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
;
223 DG__status
.xpass
= 0;
224 DG__status
.xfail
= 0;
225 DG__status
.untested
= 0;
226 DG__status
.unresolved
= 0;
227 DG__status
.unsupported
= 0;
229 /* C++ object destruction will substitute for atexit(). */
230 DG__status
.endmsg_registered
= 1;
231 DG__status
.TestState_count
++;
236 DG__status
.TestState_count
--;
238 if (DG__status
.TestState_count
> 0) return;
240 /* The last TestState object is being destroyed. */
242 std::cout
<< "\tEND: done" << std::endl
;
245 void testrun (bool b
, std::string s
)
253 void pass (std::string s
)
258 std::cout
<< DG__outstate_list
[PASSED
] << s
<< std::endl
;
261 void xpass (std::string s
)
266 std::cout
<< DG__outstate_list
[XPASSED
] << s
<< std::endl
;
269 void fail (std::string s
)
274 std::cout
<< DG__outstate_list
[FAILED
] << s
<< std::endl
;
277 void xfail (std::string s
)
282 std::cout
<< DG__outstate_list
[XFAILED
] << s
<< std::endl
;
285 void untested (std::string s
)
287 DG__status
.untested
++;
288 laststate
= UNTESTED
;
290 std::cout
<< DG__outstate_list
[UNTESTED
] << s
<< std::endl
;
293 void unresolved (std::string s
)
295 DG__status
.unresolved
++;
296 laststate
= UNRESOLVED
;
298 std::cout
<< DG__outstate_list
[UNRESOLVED
] << s
<< std::endl
;
301 void unsupported (std::string s
)
303 DG__status
.unsupported
++;
304 laststate
= UNSUPPORTED
;
306 std::cout
<< DG__outstate_list
[UNSUPPORTED
] << s
<< std::endl
;
309 void note (std::string s
)
311 std::cout
<< "\t" << "NOTE: " << s
<< std::endl
;
316 std::cout
<< std::endl
<< "Totals:" << std::endl
;
318 std::cout
<< "\t#passed:\t\t"
319 << DG__status
.pass
<< std::endl
;
320 std::cout
<< "\t#real failed:\t\t"
321 << DG__status
.fail
<< std::endl
;
323 if (DG__status
.xfail
)
324 std::cout
<< "\t#expected failures:\t\t"
325 << DG__status
.xfail
<< std::endl
;
326 if (DG__status
.xpass
)
327 std::cout
<< "\t#unexpected passes:\t\t"
328 << DG__status
.xpass
<< std::endl
;
329 if (DG__status
.untested
)
330 std::cout
<< "\t#untested:\t\t"
331 << DG__status
.untested
<< std::endl
;
332 if (DG__status
.unresolved
)
333 std::cout
<< "\t#unresolved:\t\t"
334 << DG__status
.unresolved
<< std::endl
;
335 if (DG__status
.unsupported
)
336 std::cout
<< "\t#unsupported:\t\t"
337 << DG__status
.unsupported
<< std::endl
;
340 // This is so this class can be printed in an ostream.
341 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
343 return os
<< DG__outstate_list
[t
.laststate
] << t
.lastmsg
;
346 int GetState (void) { return laststate
; }
347 std::string
GetMsg (void) { return lastmsg
; }
350 #endif /* __cplusplus */
351 #endif /* _DEJAGNU_H_ */