~ubuntu-branches/ubuntu/warty/dejagnu/warty

« back to all changes in this revision

Viewing changes to doc/html/x1522.html

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2004-02-09 15:07:58 UTC
  • Revision ID: james.westby@ubuntu.com-20040209150758-oaj7r5zrop60v8sb
Tags: upstream-1.4.4
ImportĀ upstreamĀ versionĀ 1.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>Hints On Writing A Test Case</TITLE
 
6
><META
 
7
NAME="GENERATOR"
 
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
 
9
"><LINK
 
10
REL="HOME"
 
11
TITLE="DejaGnu"
 
12
HREF="book1.html"><LINK
 
13
REL="UP"
 
14
TITLE="Extending DejaGnu"
 
15
HREF="c1099.html"><LINK
 
16
REL="PREVIOUS"
 
17
TITLE="Adding A Test Case To A Testsuite."
 
18
HREF="x1493.html"><LINK
 
19
REL="NEXT"
 
20
TITLE="Special variables used by test cases."
 
21
HREF="x1551.html"></HEAD
 
22
><BODY
 
23
CLASS="SECT1"
 
24
BGCOLOR="#FFFFFF"
 
25
TEXT="#000000"
 
26
LINK="#0000FF"
 
27
VLINK="#840084"
 
28
ALINK="#0000FF"
 
29
><DIV
 
30
CLASS="NAVHEADER"
 
31
><TABLE
 
32
SUMMARY="Header navigation table"
 
33
WIDTH="100%"
 
34
BORDER="0"
 
35
CELLPADDING="0"
 
36
CELLSPACING="0"
 
37
><TR
 
38
><TH
 
39
COLSPAN="3"
 
40
ALIGN="center"
 
41
>DejaGnu: The GNU Testing Framework</TH
 
42
></TR
 
43
><TR
 
44
><TD
 
45
WIDTH="10%"
 
46
ALIGN="left"
 
47
VALIGN="bottom"
 
48
><A
 
49
HREF="x1493.html"
 
50
ACCESSKEY="P"
 
51
>&#60;&#60;&#60; Previous</A
 
52
></TD
 
53
><TD
 
54
WIDTH="80%"
 
55
ALIGN="center"
 
56
VALIGN="bottom"
 
57
>Extending DejaGnu</TD
 
58
><TD
 
59
WIDTH="10%"
 
60
ALIGN="right"
 
61
VALIGN="bottom"
 
62
><A
 
63
HREF="x1551.html"
 
64
ACCESSKEY="N"
 
65
>Next &#62;&#62;&#62;</A
 
66
></TD
 
67
></TR
 
68
></TABLE
 
69
><HR
 
70
ALIGN="LEFT"
 
71
WIDTH="100%"></DIV
 
72
><DIV
 
73
CLASS="SECT1"
 
74
><H1
 
75
CLASS="SECT1"
 
76
><A
 
77
NAME="HINTS"
 
78
></A
 
79
>Hints On Writing A Test Case</H1
 
80
><P
 
81
>It is safest to write patterns that match all the output
 
82
      generated by the tested program; this is called closure.
 
83
      If a pattern does not match the entire output, any output that
 
84
      remains will be examined by the next <B
 
85
CLASS="COMMAND"
 
86
>expect</B
 
87
>
 
88
      command. In this situation, the precise boundary that determines
 
89
      which <B
 
90
CLASS="COMMAND"
 
91
>expect</B
 
92
> command sees what is very
 
93
      sensitive to timing between the Expect task and the task running
 
94
      the tested tool.  As a result, the test may sometimes appear to
 
95
      work, but is likely to have unpredictable results. (This problem
 
96
      is particularly likely for interactive tools, but can also
 
97
      affect batch tools---especially for tests that take a long time
 
98
      to finish.) The best way to ensure closure is to use the
 
99
      <TT
 
100
CLASS="OPTION"
 
101
>-re</TT
 
102
> option for the <B
 
103
CLASS="COMMAND"
 
104
>expect</B
 
105
>
 
106
      command to write the pattern as a full regular expressions; then
 
107
      you can match the end of output using a <I
 
108
CLASS="EMPHASIS"
 
109
>$</I
 
110
>.
 
111
      It is also a good idea to write patterns that match all
 
112
      available output by using <I
 
113
CLASS="EMPHASIS"
 
114
>.*\</I
 
115
> after the
 
116
      text of interest; this will also match any intervening blank
 
117
      lines.  Sometimes an alternative is to match end of line using
 
118
      <I
 
119
CLASS="EMPHASIS"
 
120
>\r</I
 
121
> or <I
 
122
CLASS="EMPHASIS"
 
123
>\n</I
 
124
>, but this is
 
125
      usually too dependent on terminal settings.</P
 
126
><P
 
127
>Always escape punctuation, such as <I
 
128
CLASS="EMPHASIS"
 
129
>(</I
 
130
>
 
131
      or <I
 
132
CLASS="EMPHASIS"
 
133
>"</I
 
134
>, in your patterns; for example, write
 
135
      <I
 
136
CLASS="EMPHASIS"
 
137
>\(</I
 
138
>.  If you forget to escape punctuation,
 
139
      you will usually see an error message like <TABLE
 
140
BORDER="0"
 
141
BGCOLOR="#E0E0E0"
 
142
WIDTH="100%"
 
143
><TR
 
144
><TD
 
145
><PRE
 
146
CLASS="PROGRAMLISTING"
 
147
>extra
 
148
      characters after close-quote.</PRE
 
149
></TD
 
150
></TR
 
151
></TABLE
 
152
></P
 
153
><P
 
154
>If you have trouble understanding why a pattern does not
 
155
      match the program output, try using the <TT
 
156
CLASS="OPTION"
 
157
>--debug</TT
 
158
>
 
159
      option to <B
 
160
CLASS="COMMAND"
 
161
>runtest</B
 
162
>, and examine the debug log
 
163
      carefully.</P
 
164
><P
 
165
>Be careful not to neglect output generated by setup rather
 
166
      than by the interesting parts of a test case.  For example,
 
167
      while testing GDB, I issue a send <I
 
168
CLASS="EMPHASIS"
 
169
>set height
 
170
      0\n</I
 
171
> command.  The purpose is simply to make sure GDB
 
172
      never calls a paging program.  The <I
 
173
CLASS="EMPHASIS"
 
174
>set
 
175
      height</I
 
176
> command in GDB does not generate any
 
177
      output; but running any command makes GDB issue a new
 
178
      <I
 
179
CLASS="EMPHASIS"
 
180
>(gdb) </I
 
181
> prompt.  If there were no
 
182
      <B
 
183
CLASS="COMMAND"
 
184
>expect</B
 
185
> command to match this prompt, the
 
186
      output <I
 
187
CLASS="EMPHASIS"
 
188
>(gdb) </I
 
189
> begins the text seen by the
 
190
      next <B
 
191
CLASS="COMMAND"
 
192
>expect</B
 
193
> command---which might make that
 
194
      pattern fail to match.</P
 
195
><P
 
196
>To preserve basic sanity, I also recommended that no test
 
197
      ever pass if there was any kind of problem in the test case.  To
 
198
      take an extreme case, tests that pass even when the tool will
 
199
      not spawn are misleading. Ideally, a test in this sort of
 
200
      situation should not fail either. Instead, print an error
 
201
      message by calling one of the DejaGnu procedures
 
202
      <B
 
203
CLASS="COMMAND"
 
204
>error</B
 
205
> or <B
 
206
CLASS="COMMAND"
 
207
>warning</B
 
208
>.</P
 
209
></DIV
 
210
><DIV
 
211
CLASS="NAVFOOTER"
 
212
><HR
 
213
ALIGN="LEFT"
 
214
WIDTH="100%"><TABLE
 
215
SUMMARY="Footer navigation table"
 
216
WIDTH="100%"
 
217
BORDER="0"
 
218
CELLPADDING="0"
 
219
CELLSPACING="0"
 
220
><TR
 
221
><TD
 
222
WIDTH="33%"
 
223
ALIGN="left"
 
224
VALIGN="top"
 
225
><A
 
226
HREF="x1493.html"
 
227
ACCESSKEY="P"
 
228
>&#60;&#60;&#60; Previous</A
 
229
></TD
 
230
><TD
 
231
WIDTH="34%"
 
232
ALIGN="center"
 
233
VALIGN="top"
 
234
><A
 
235
HREF="book1.html"
 
236
ACCESSKEY="H"
 
237
>Home</A
 
238
></TD
 
239
><TD
 
240
WIDTH="33%"
 
241
ALIGN="right"
 
242
VALIGN="top"
 
243
><A
 
244
HREF="x1551.html"
 
245
ACCESSKEY="N"
 
246
>Next &#62;&#62;&#62;</A
 
247
></TD
 
248
></TR
 
249
><TR
 
250
><TD
 
251
WIDTH="33%"
 
252
ALIGN="left"
 
253
VALIGN="top"
 
254
>Adding A Test Case To A Testsuite.</TD
 
255
><TD
 
256
WIDTH="34%"
 
257
ALIGN="center"
 
258
VALIGN="top"
 
259
><A
 
260
HREF="c1099.html"
 
261
ACCESSKEY="U"
 
262
>Up</A
 
263
></TD
 
264
><TD
 
265
WIDTH="33%"
 
266
ALIGN="right"
 
267
VALIGN="top"
 
268
>Special variables used by test cases.</TD
 
269
></TR
 
270
></TABLE
 
271
></DIV
 
272
></BODY
 
273
></HTML
 
274
>
 
 
b'\\ No newline at end of file'