1 /* A self-testing framework, for use by -fself-test.
2 Copyright (C) 2015-2016 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 int selftest::num_passes
;
29 /* Record the successful outcome of some aspect of a test. */
32 selftest::pass (const location
&/*loc*/, const char */
*msg*/
)
37 /* Report the failed outcome of some aspect of a test and abort. */
40 selftest::fail (const location
&loc
, const char *msg
)
42 fprintf (stderr
,"%s:%i: %s: FAIL: %s\n", loc
.m_file
, loc
.m_line
,
47 /* As "fail", but using printf-style formatted output. */
50 selftest::fail_formatted (const location
&loc
, const char *fmt
, ...)
54 fprintf (stderr
, "%s:%i: %s: FAIL: ", loc
.m_file
, loc
.m_line
,
57 vfprintf (stderr
, fmt
, ap
);
59 fprintf (stderr
, "\n");
63 /* Implementation detail of ASSERT_STREQ. */
66 selftest::assert_streq (const location
&loc
,
67 const char *desc_expected
, const char *desc_actual
,
68 const char *val_expected
, const char *val_actual
)
70 if (0 == strcmp (val_expected
, val_actual
))
71 ::selftest::pass (loc
, "ASSERT_STREQ");
73 ::selftest::fail_formatted
74 (loc
, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=\"%s\"",
75 desc_expected
, desc_actual
, val_expected
, val_actual
);
79 #endif /* #if CHECKING_P */