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, see <http://www.gnu.org/licenses/>. */
27 /* If you have problems with DejaGnu dropping failed, untested, or
28 * unresolved messages generated by a unit testcase, then see the section
29 * "Priority of Expect Patterns" in *note (dejagnu)Writing a test case. or
30 * use the DejaGnu built-in unit testing support in your testsuite, which
31 * has been improved to resolve this issue in DejaGnu 1.6.3. */
42 int endmsg_registered
;
43 int TestState_count
; /* number of live TestState objects in C++ */
48 { puts ("\tEND: done"); }
53 if (DG__status
.endmsg_registered
) return;
55 if (atexit (DG__endmsg
) == 0)
56 DG__status
.endmsg_registered
= 1;
60 pass (const char* fmt
, ...)
68 fputs ("\tPASSED: ", stdout
);
69 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
75 xpass (const char* fmt
, ...)
83 fputs ("\tXPASSED: ", stdout
);
84 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
90 fail (const char* fmt
, ...)
98 fputs ("\tFAILED: ", stdout
);
99 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
100 fputc ('\n', stdout
);
101 funlockfile (stdout
);
105 xfail (const char* fmt
, ...)
113 fputs ("\tXFAILED: ", stdout
);
114 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
115 fputc ('\n', stdout
);
116 funlockfile (stdout
);
120 untested (const char* fmt
, ...)
124 DG__status
.untested
++;
128 fputs ("\tUNTESTED: ", stdout
);
129 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
130 fputc ('\n', stdout
);
131 funlockfile (stdout
);
135 unresolved (const char* fmt
, ...)
139 DG__status
.unresolved
++;
143 fputs ("\tUNRESOLVED: ", stdout
);
144 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
145 fputc ('\n', stdout
);
146 funlockfile (stdout
);
150 unsupported (const char* fmt
, ...)
154 DG__status
.unsupported
++;
158 fputs ("\tUNSUPPORTED: ", stdout
);
159 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
160 fputc ('\n', stdout
);
161 funlockfile (stdout
);
165 note (const char* fmt
, ...)
172 fputs ("\tNOTE: ", stdout
);
173 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
174 fputc ('\n', stdout
);
175 funlockfile (stdout
);
179 DG_error (const char* fmt
, ...)
186 fputs ("\tERROR: ", stdout
);
187 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
188 fputc ('\n', stdout
);
189 funlockfile (stdout
);
193 DG_warning (const char* fmt
, ...)
200 fputs ("\tWARNING: ", stdout
);
201 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
202 fputc ('\n', stdout
);
203 funlockfile (stdout
);
209 printf ("\nTotals:\n");
210 printf ("\t#passed:\t\t%d\n", DG__status
.pass
);
211 printf ("\t#failed:\t\t%d\n", DG__status
.fail
);
212 if (DG__status
.xfail
)
213 printf ("\t#expected failures:\t\t%d\n", DG__status
.xfail
);
214 if (DG__status
.xpass
)
215 printf ("\t#unexpected passes:\t\t%d\n", DG__status
.xpass
);
216 if (DG__status
.untested
)
217 printf ("\t#untested:\t\t%d\n", DG__status
.untested
);
218 if (DG__status
.unresolved
)
219 printf ("\t#unresolved:\t\t%d\n", DG__status
.unresolved
);
220 if (DG__status
.unsupported
)
221 printf ("\t#unsupported:\t\t%d\n", DG__status
.unsupported
);
231 const char * DG__outstate_list
[] = {
232 "\tFAILED: ", "\tPASSED: ",
233 "\tUNTESTED: ", "\tUNRESOLVED: ", "\tUNSUPPORTED: ",
234 "\tXFAILED: ", "\tXPASSED: "
237 enum DG_teststate
{ FAILED
, PASSED
,
238 UNTESTED
, UNRESOLVED
, UNSUPPORTED
,
243 DG_teststate laststate
;
248 DG__status
.TestState_count
++;
250 if (DG__status
.TestState_count
> 1)
251 return; /* Do not clear the counters if additional TestState
252 objects are constructed. */
256 DG__status
.xpass
= 0;
257 DG__status
.xfail
= 0;
258 DG__status
.untested
= 0;
259 DG__status
.unresolved
= 0;
260 DG__status
.unsupported
= 0;
262 /* C++ object destruction will substitute for atexit(). */
263 DG__status
.endmsg_registered
= 1;
268 DG__status
.TestState_count
--;
270 if (DG__status
.TestState_count
> 0) return;
272 /* The last TestState object is being destroyed. */
274 std::cout
<< "\tEND: done" << std::endl
;
277 void testrun (bool b
, std::string s
)
285 void pass (std::string s
)
290 std::cout
<< DG__outstate_list
[PASSED
] << s
<< std::endl
;
293 void xpass (std::string s
)
298 std::cout
<< DG__outstate_list
[XPASSED
] << s
<< std::endl
;
301 void fail (std::string s
)
306 std::cout
<< DG__outstate_list
[FAILED
] << s
<< std::endl
;
309 void xfail (std::string s
)
314 std::cout
<< DG__outstate_list
[XFAILED
] << s
<< std::endl
;
317 void untested (std::string s
)
319 DG__status
.untested
++;
320 laststate
= UNTESTED
;
322 std::cout
<< DG__outstate_list
[UNTESTED
] << s
<< std::endl
;
325 void unresolved (std::string s
)
327 DG__status
.unresolved
++;
328 laststate
= UNRESOLVED
;
330 std::cout
<< DG__outstate_list
[UNRESOLVED
] << s
<< std::endl
;
333 void unsupported (std::string s
)
335 DG__status
.unsupported
++;
336 laststate
= UNSUPPORTED
;
338 std::cout
<< DG__outstate_list
[UNSUPPORTED
] << s
<< std::endl
;
341 void note (std::string s
)
343 std::cout
<< "\t" << "NOTE: " << s
<< std::endl
;
346 void error (std::string s
)
348 std::cout
<< "\t" << "ERROR: " << s
<< std::endl
;
351 void warning (std::string s
)
353 std::cout
<< "\t" << "WARNING: " << s
<< std::endl
;
358 std::cout
<< std::endl
<< "Totals:" << std::endl
;
360 std::cout
<< "\t#passed:\t\t"
361 << DG__status
.pass
<< std::endl
;
362 std::cout
<< "\t#failed:\t\t"
363 << DG__status
.fail
<< std::endl
;
365 if (DG__status
.xfail
)
366 std::cout
<< "\t#expected failures:\t\t"
367 << DG__status
.xfail
<< std::endl
;
368 if (DG__status
.xpass
)
369 std::cout
<< "\t#unexpected passes:\t\t"
370 << DG__status
.xpass
<< std::endl
;
371 if (DG__status
.untested
)
372 std::cout
<< "\t#untested:\t\t"
373 << DG__status
.untested
<< std::endl
;
374 if (DG__status
.unresolved
)
375 std::cout
<< "\t#unresolved:\t\t"
376 << DG__status
.unresolved
<< std::endl
;
377 if (DG__status
.unsupported
)
378 std::cout
<< "\t#unsupported:\t\t"
379 << DG__status
.unsupported
<< std::endl
;
382 // This is so this class can be printed in an ostream.
383 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
385 return os
<< DG__outstate_list
[t
.laststate
] << t
.lastmsg
;
388 int GetState (void) { return laststate
; }
389 std::string
GetMsg (void) { return lastmsg
; }
394 #endif /* __cplusplus */
395 #endif /* _DEJAGNU_H_ */