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. */
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. */
44 pass (const char* fmt
, ...)
51 fputs ("\tPASSED: ", stdout
);
52 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
58 xpass (const char* fmt
, ...)
65 fputs ("\tXPASSED: ", stdout
);
66 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
72 fail (const char* fmt
, ...)
79 fputs ("\tFAILED: ", stdout
);
80 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
86 xfail (const char* fmt
, ...)
93 fputs ("\tXFAILED: ", stdout
);
94 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
100 untested (const char* fmt
, ...)
104 DG__status
.untested
++;
107 fputs ("\tUNTESTED: ", stdout
);
108 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
109 fputc ('\n', stdout
);
110 funlockfile (stdout
);
114 unresolved (const char* fmt
, ...)
118 DG__status
.unresolved
++;
121 fputs ("\tUNRESOLVED: ", stdout
);
122 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
123 fputc ('\n', stdout
);
124 funlockfile (stdout
);
128 unsupported (const char* fmt
, ...)
132 DG__status
.unsupported
++;
135 fputs ("\tUNSUPPORTED: ", stdout
);
136 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
137 fputc ('\n', stdout
);
138 funlockfile (stdout
);
142 note (const char* fmt
, ...)
147 fputs ("\tNOTE: ", stdout
);
148 va_start (ap
, fmt
); vfprintf (stdout
, fmt
, ap
); va_end (ap
);
149 fputc ('\n', stdout
);
150 funlockfile (stdout
);
156 printf ("\nTotals:\n");
157 printf ("\t#passed:\t\t%d\n", DG__status
.pass
);
158 printf ("\t#real failed:\t\t%d\n", DG__status
.fail
);
159 if (DG__status
.xfail
)
160 printf ("\t#expected failures:\t\t%d\n", DG__status
.xfail
);
161 if (DG__status
.xpass
)
162 printf ("\t#unexpected passes:\t\t%d\n", DG__status
.xpass
);
163 if (DG__status
.untested
)
164 printf ("\t#untested:\t\t%d\n", DG__status
.untested
);
165 if (DG__status
.unresolved
)
166 printf ("\t#unresolved:\t\t%d\n", DG__status
.unresolved
);
167 if (DG__status
.unsupported
)
168 printf ("\t#unsupported:\t\t%d\n", DG__status
.unsupported
);
169 printf ("\tEND: done\n");
179 const char * DG__outstate_list
[] = {
180 "\tFAILED: ", "\tPASSED: ",
181 "\tUNTESTED: ", "\tUNRESOLVED: ", "\tUNSUPPORTED: ",
182 "\tXFAILED: ", "\tXPASSED: "
185 enum DG_teststate
{ FAILED
, PASSED
,
186 UNTESTED
, UNRESOLVED
, UNSUPPORTED
,
191 DG_teststate laststate
;
198 DG__status
.xpass
= 0;
199 DG__status
.xfail
= 0;
200 DG__status
.untested
= 0;
201 DG__status
.unresolved
= 0;
202 DG__status
.unsupported
= 0;
205 ~TestState (void) { totals(); }
207 void testrun (bool b
, std::string s
)
215 void pass (std::string s
)
220 std::cout
<< DG__outstate_list
[PASSED
] << s
<< std::endl
;
223 void xpass (std::string s
)
228 std::cout
<< DG__outstate_list
[XPASSED
] << s
<< std::endl
;
231 void fail (std::string s
)
236 std::cout
<< DG__outstate_list
[FAILED
] << s
<< std::endl
;
239 void xfail (std::string s
)
244 std::cout
<< DG__outstate_list
[XFAILED
] << s
<< std::endl
;
247 void untested (std::string s
)
249 DG__status
.untested
++;
250 laststate
= UNTESTED
;
252 std::cout
<< DG__outstate_list
[UNTESTED
] << s
<< std::endl
;
255 void unresolved (std::string s
)
257 DG__status
.unresolved
++;
258 laststate
= UNRESOLVED
;
260 std::cout
<< DG__outstate_list
[UNRESOLVED
] << s
<< std::endl
;
263 void unsupported (std::string s
)
265 DG__status
.unsupported
++;
266 laststate
= UNSUPPORTED
;
268 std::cout
<< DG__outstate_list
[UNSUPPORTED
] << s
<< std::endl
;
271 void note (std::string s
)
273 std::cout
<< "\t" << "NOTE: " << s
<< std::endl
;
278 std::cout
<< std::endl
<< "Totals:" << std::endl
;
280 std::cout
<< "\t#passed:\t\t"
281 << DG__status
.pass
<< std::endl
;
282 std::cout
<< "\t#real failed:\t\t"
283 << DG__status
.fail
<< std::endl
;
285 if (DG__status
.xfail
)
286 std::cout
<< "\t#expected failures:\t\t"
287 << DG__status
.xfail
<< std::endl
;
288 if (DG__status
.xpass
)
289 std::cout
<< "\t#unexpected passes:\t\t"
290 << DG__status
.xpass
<< std::endl
;
291 if (DG__status
.untested
)
292 std::cout
<< "\t#untested:\t\t"
293 << DG__status
.untested
<< std::endl
;
294 if (DG__status
.unresolved
)
295 std::cout
<< "\t#unresolved:\t\t"
296 << DG__status
.unresolved
<< std::endl
;
297 if (DG__status
.unsupported
)
298 std::cout
<< "\t#unsupported:\t\t"
299 << DG__status
.unsupported
<< std::endl
;
301 std::cout
<< "\tEND: done" << std::endl
;
304 // This is so this class can be printed in an ostream.
305 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
307 return os
<< DG__outstate_list
[t
.laststate
] << t
.lastmsg
;
310 int GetState (void) { return laststate
; }
311 std::string
GetMsg (void) { return lastmsg
; }
314 #endif /* __cplusplus */
315 #endif /* _DEJAGNU_H_ */