1 /* DejaGnu unit testing header.
2 Copyright (C) 2000-2016, 2022 Free Software Foundation, Inc.
4 This file is part of DejaGnu.
6 DejaGnu is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 DejaGnu is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DejaGnu; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
28 /* If you have problems with DejaGnu dropping failed, untested, or
29 * unresolved messages generated by a unit testcase, then see the section
30 * "Priority of Expect Patterns" in *note (dejagnu)Writing a test case. or
31 * use the DejaGnu built-in unit testing support in your testsuite, which
32 * has been improved to resolve this issue in DejaGnu 1.6.3. */
43 int endmsg_registered
;
44 int TestState_count
; /* number of live TestState objects in C++ */
49 { puts ("\tEND: done"); }
54 if (DG__status
.endmsg_registered
) return;
56 if (atexit (DG__endmsg
) == 0)
57 DG__status
.endmsg_registered
= 1;
61 pass (const char* fmt
, ...)
69 fputs ("\tPASSED: ", stdout
);
70 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
76 xpass (const char* fmt
, ...)
84 fputs ("\tXPASSED: ", stdout
);
85 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
91 fail (const char* fmt
, ...)
99 fputs ("\tFAILED: ", stdout
);
100 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
101 fputc ('\n', stdout
);
102 funlockfile (stdout
);
106 xfail (const char* fmt
, ...)
114 fputs ("\tXFAILED: ", stdout
);
115 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
116 fputc ('\n', stdout
);
117 funlockfile (stdout
);
121 untested (const char* fmt
, ...)
125 DG__status
.untested
++;
129 fputs ("\tUNTESTED: ", stdout
);
130 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
131 fputc ('\n', stdout
);
132 funlockfile (stdout
);
136 unresolved (const char* fmt
, ...)
140 DG__status
.unresolved
++;
144 fputs ("\tUNRESOLVED: ", stdout
);
145 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
146 fputc ('\n', stdout
);
147 funlockfile (stdout
);
151 unsupported (const char* fmt
, ...)
155 DG__status
.unsupported
++;
159 fputs ("\tUNSUPPORTED: ", stdout
);
160 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
161 fputc ('\n', stdout
);
162 funlockfile (stdout
);
166 note (const char* fmt
, ...)
173 fputs ("\tNOTE: ", stdout
);
174 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
175 fputc ('\n', stdout
);
176 funlockfile (stdout
);
180 DG_error (const char* fmt
, ...)
187 fputs ("\tERROR: ", stdout
);
188 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
189 fputc ('\n', stdout
);
190 funlockfile (stdout
);
194 DG_warning (const char* fmt
, ...)
201 fputs ("\tWARNING: ", stdout
);
202 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
203 fputc ('\n', stdout
);
204 funlockfile (stdout
);
210 printf ("\nTotals:\n");
211 printf ("\t#passed:\t\t%d\n", DG__status
.pass
);
212 printf ("\t#failed:\t\t%d\n", DG__status
.fail
);
213 if (DG__status
.xfail
)
214 printf ("\t#expected failures:\t\t%d\n", DG__status
.xfail
);
215 if (DG__status
.xpass
)
216 printf ("\t#unexpected passes:\t\t%d\n", DG__status
.xpass
);
217 if (DG__status
.untested
)
218 printf ("\t#untested:\t\t%d\n", DG__status
.untested
);
219 if (DG__status
.unresolved
)
220 printf ("\t#unresolved:\t\t%d\n", DG__status
.unresolved
);
221 if (DG__status
.unsupported
)
222 printf ("\t#unsupported:\t\t%d\n", DG__status
.unsupported
);
232 const char * DG__outstate_list
[] = {
233 "\tFAILED: ", "\tPASSED: ",
234 "\tUNTESTED: ", "\tUNRESOLVED: ", "\tUNSUPPORTED: ",
235 "\tXFAILED: ", "\tXPASSED: "
238 enum DG_teststate
{ FAILED
, PASSED
,
239 UNTESTED
, UNRESOLVED
, UNSUPPORTED
,
244 DG_teststate laststate
;
249 DG__status
.TestState_count
++;
251 if (DG__status
.TestState_count
> 1)
252 return; /* Do not clear the counters if additional TestState
253 objects are constructed. */
257 DG__status
.xpass
= 0;
258 DG__status
.xfail
= 0;
259 DG__status
.untested
= 0;
260 DG__status
.unresolved
= 0;
261 DG__status
.unsupported
= 0;
263 /* C++ object destruction will substitute for atexit(). */
264 DG__status
.endmsg_registered
= 1;
269 DG__status
.TestState_count
--;
271 if (DG__status
.TestState_count
> 0) return;
273 /* The last TestState object is being destroyed. */
275 std::cout
<< "\tEND: done" << std::endl
;
278 void testrun (bool b
, std::string s
)
286 void pass (std::string s
)
291 std::cout
<< DG__outstate_list
[PASSED
] << s
<< std::endl
;
294 void xpass (std::string s
)
299 std::cout
<< DG__outstate_list
[XPASSED
] << s
<< std::endl
;
302 void fail (std::string s
)
307 std::cout
<< DG__outstate_list
[FAILED
] << s
<< std::endl
;
310 void xfail (std::string s
)
315 std::cout
<< DG__outstate_list
[XFAILED
] << s
<< std::endl
;
318 void untested (std::string s
)
320 DG__status
.untested
++;
321 laststate
= UNTESTED
;
323 std::cout
<< DG__outstate_list
[UNTESTED
] << s
<< std::endl
;
326 void unresolved (std::string s
)
328 DG__status
.unresolved
++;
329 laststate
= UNRESOLVED
;
331 std::cout
<< DG__outstate_list
[UNRESOLVED
] << s
<< std::endl
;
334 void unsupported (std::string s
)
336 DG__status
.unsupported
++;
337 laststate
= UNSUPPORTED
;
339 std::cout
<< DG__outstate_list
[UNSUPPORTED
] << s
<< std::endl
;
342 void note (std::string s
)
344 std::cout
<< "\t" << "NOTE: " << s
<< std::endl
;
347 void error (std::string s
)
349 std::cout
<< "\t" << "ERROR: " << s
<< std::endl
;
352 void warning (std::string s
)
354 std::cout
<< "\t" << "WARNING: " << s
<< std::endl
;
359 std::cout
<< std::endl
<< "Totals:" << std::endl
;
361 std::cout
<< "\t#passed:\t\t"
362 << DG__status
.pass
<< std::endl
;
363 std::cout
<< "\t#failed:\t\t"
364 << DG__status
.fail
<< std::endl
;
366 if (DG__status
.xfail
)
367 std::cout
<< "\t#expected failures:\t\t"
368 << DG__status
.xfail
<< std::endl
;
369 if (DG__status
.xpass
)
370 std::cout
<< "\t#unexpected passes:\t\t"
371 << DG__status
.xpass
<< std::endl
;
372 if (DG__status
.untested
)
373 std::cout
<< "\t#untested:\t\t"
374 << DG__status
.untested
<< std::endl
;
375 if (DG__status
.unresolved
)
376 std::cout
<< "\t#unresolved:\t\t"
377 << DG__status
.unresolved
<< std::endl
;
378 if (DG__status
.unsupported
)
379 std::cout
<< "\t#unsupported:\t\t"
380 << DG__status
.unsupported
<< std::endl
;
383 // This is so this class can be printed in an ostream.
384 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
386 return os
<< DG__outstate_list
[t
.laststate
] << t
.lastmsg
;
389 int GetState (void) { return laststate
; }
390 std::string
GetMsg (void) { return lastmsg
; }
395 #endif /* __cplusplus */
396 #endif /* _DEJAGNU_H_ */