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
);
182 printf ("\nTotals:\n");
183 printf ("\t#passed:\t\t%d\n", DG__status
.pass
);
184 printf ("\t#real failed:\t\t%d\n", DG__status
.fail
);
185 if (DG__status
.xfail
)
186 printf ("\t#expected failures:\t\t%d\n", DG__status
.xfail
);
187 if (DG__status
.xpass
)
188 printf ("\t#unexpected passes:\t\t%d\n", DG__status
.xpass
);
189 if (DG__status
.untested
)
190 printf ("\t#untested:\t\t%d\n", DG__status
.untested
);
191 if (DG__status
.unresolved
)
192 printf ("\t#unresolved:\t\t%d\n", DG__status
.unresolved
);
193 if (DG__status
.unsupported
)
194 printf ("\t#unsupported:\t\t%d\n", DG__status
.unsupported
);
204 const char * DG__outstate_list
[] = {
205 "\tFAILED: ", "\tPASSED: ",
206 "\tUNTESTED: ", "\tUNRESOLVED: ", "\tUNSUPPORTED: ",
207 "\tXFAILED: ", "\tXPASSED: "
210 enum DG_teststate
{ FAILED
, PASSED
,
211 UNTESTED
, UNRESOLVED
, UNSUPPORTED
,
216 DG_teststate laststate
;
221 DG__status
.TestState_count
++;
223 if (DG__status
.TestState_count
> 1)
224 return; /* Do not clear the counters if additional TestState
225 objects are constructed. */
229 DG__status
.xpass
= 0;
230 DG__status
.xfail
= 0;
231 DG__status
.untested
= 0;
232 DG__status
.unresolved
= 0;
233 DG__status
.unsupported
= 0;
235 /* C++ object destruction will substitute for atexit(). */
236 DG__status
.endmsg_registered
= 1;
241 DG__status
.TestState_count
--;
243 if (DG__status
.TestState_count
> 0) return;
245 /* The last TestState object is being destroyed. */
247 std::cout
<< "\tEND: done" << std::endl
;
250 void testrun (bool b
, std::string s
)
258 void pass (std::string s
)
263 std::cout
<< DG__outstate_list
[PASSED
] << s
<< std::endl
;
266 void xpass (std::string s
)
271 std::cout
<< DG__outstate_list
[XPASSED
] << s
<< std::endl
;
274 void fail (std::string s
)
279 std::cout
<< DG__outstate_list
[FAILED
] << s
<< std::endl
;
282 void xfail (std::string s
)
287 std::cout
<< DG__outstate_list
[XFAILED
] << s
<< std::endl
;
290 void untested (std::string s
)
292 DG__status
.untested
++;
293 laststate
= UNTESTED
;
295 std::cout
<< DG__outstate_list
[UNTESTED
] << s
<< std::endl
;
298 void unresolved (std::string s
)
300 DG__status
.unresolved
++;
301 laststate
= UNRESOLVED
;
303 std::cout
<< DG__outstate_list
[UNRESOLVED
] << s
<< std::endl
;
306 void unsupported (std::string s
)
308 DG__status
.unsupported
++;
309 laststate
= UNSUPPORTED
;
311 std::cout
<< DG__outstate_list
[UNSUPPORTED
] << s
<< std::endl
;
314 void note (std::string s
)
316 std::cout
<< "\t" << "NOTE: " << s
<< std::endl
;
321 std::cout
<< std::endl
<< "Totals:" << std::endl
;
323 std::cout
<< "\t#passed:\t\t"
324 << DG__status
.pass
<< std::endl
;
325 std::cout
<< "\t#real failed:\t\t"
326 << DG__status
.fail
<< std::endl
;
328 if (DG__status
.xfail
)
329 std::cout
<< "\t#expected failures:\t\t"
330 << DG__status
.xfail
<< std::endl
;
331 if (DG__status
.xpass
)
332 std::cout
<< "\t#unexpected passes:\t\t"
333 << DG__status
.xpass
<< std::endl
;
334 if (DG__status
.untested
)
335 std::cout
<< "\t#untested:\t\t"
336 << DG__status
.untested
<< std::endl
;
337 if (DG__status
.unresolved
)
338 std::cout
<< "\t#unresolved:\t\t"
339 << DG__status
.unresolved
<< std::endl
;
340 if (DG__status
.unsupported
)
341 std::cout
<< "\t#unsupported:\t\t"
342 << DG__status
.unsupported
<< std::endl
;
345 // This is so this class can be printed in an ostream.
346 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
348 return os
<< DG__outstate_list
[t
.laststate
] << t
.lastmsg
;
351 int GetState (void) { return laststate
; }
352 std::string
GetMsg (void) { return lastmsg
; }
357 #endif /* __cplusplus */
358 #endif /* _DEJAGNU_H_ */