1 /* DejaGnu unit testing header.
2 Copyright (C) 2000-2023 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. */
20 /* Imported from 1.6.2 with modifications
21 * to avoid and unused symbol in C compilations
22 * avoid wait () clashing with system-provided routines
23 * provide a deterministic last line of output after the totals. */
32 /* If you have problems with DejaGnu dropping failed, untested, or
33 * unresolved messages generated by a unit testcase, then: */
35 /* #define _DEJAGNU_WAIT_ */
39 #include <sys/types.h>
52 static char buffer
[512];
65 select (0, &rfds
, NULL
, NULL
, &tv
);
70 pass (const char* fmt
, ...)
76 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
78 printf ("\tPASSED: %s\n", buffer
);
85 xpass (const char* fmt
, ...)
91 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
93 printf ("\tXPASSED: %s\n", buffer
);
100 fail (const char* fmt
, ...)
106 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
108 printf ("\tFAILED: %s\n", buffer
);
109 #ifdef _DEJAGNU_WAIT_
115 xfail (const char* fmt
, ...)
121 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
123 printf ("\tXFAILED: %s\n", buffer
);
124 #ifdef _DEJAGNU_WAIT_
130 untested (const char* fmt
, ...)
136 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
138 printf ("\tUNTESTED: %s\n", buffer
);
139 #ifdef _DEJAGNU_WAIT_
145 unresolved (const char* fmt
, ...)
151 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
153 printf ("\tUNRESOLVED: %s\n", buffer
);
154 #ifdef _DEJAGNU_WAIT_
160 note (const char* fmt
, ...)
165 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
167 printf ("\tNOTE: %s\n", buffer
);
168 #ifdef _DEJAGNU_WAIT_
176 printf ("\nTotals:\n");
177 printf ("\t#passed:\t\t%d\n", passed
);
178 printf ("\t#real failed:\t\t%d\n", failed
);
180 printf ("\t#expected failures:\t\t%d\n", xfailed
);
182 printf ("\t#untested:\t\t%d\n", untest
);
184 printf ("\t#unresolved:\t\t%d\n", unresolve
);
185 printf ("\njit-dg-harness-complete\n");
195 const char *outstate_list
[] = {
196 "FAILED: ", "PASSED: ", "UNTESTED: ", "UNRESOLVED: ", "XFAILED: ", "XPASSED: "
199 const char ** outstate
= outstate_list
;
201 enum teststate
{ FAILED
, PASSED
, UNTESTED
, UNRESOLVED
, XFAILED
, XPASSED
} laststate
;
218 ~TestState (void) { totals(); }
220 void testrun (bool b
, std::string s
)
228 void pass (std::string s
)
233 std::cout
<< "\t" << outstate
[PASSED
] << s
<< std::endl
;
236 void pass (const char *c
)
242 void xpass (std::string s
)
247 std::cout
<< "\t" << outstate
[XPASSED
] << s
<< std::endl
;
250 void xpass (const char *c
)
256 void fail (std::string s
)
261 std::cout
<< "\t" << outstate
[FAILED
] << s
<< std::endl
;
264 void fail (const char *c
)
270 void xfail (std::string s
)
275 std::cout
<< "\t" << outstate
[XFAILED
] << s
<< std::endl
;
278 void xfail (const char *c
)
284 void untested (std::string s
)
287 laststate
= UNTESTED
;
289 std::cout
<< "\t" << outstate
[UNTESTED
] << s
<< std::endl
;
292 void untested (const char *c
)
298 void unresolved (std::string s
)
301 laststate
= UNRESOLVED
;
303 std::cout
<< "\t" << outstate
[UNRESOLVED
] << s
<< std::endl
;
306 void unresolved (const char *c
)
314 std::cout
<< "\t#passed:\t\t" << passed
<< std::endl
;
315 std::cout
<< "\t#real failed:\t\t" << failed
<< std::endl
;
317 std::cout
<< "\t#expected failures:\t\t" << xfailed
<< std::endl
;
319 std::cout
<< "\t#unexpected passes:\t\t" << xpassed
<< std::endl
;
321 std::cout
<< "\t#untested:\t\t" << untest
<< std::endl
;
323 std::cout
<< "\t#unresolved:\t\t" << unresolve
<< std::endl
;
324 std::cout
<< "\njit-dg-harness-complete" << std::endl
;
327 // This is so this class can be printed in an ostream.
328 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
330 return os
<< "\t" << outstate
[t
.laststate
] << t
.lastmsg
;
333 int GetState (void) { return laststate
; }
334 std::string
GetMsg (void) { return lastmsg
; }
337 #endif /* __cplusplus */
338 #endif /* _DEJAGNU_H_ */