b8181c84cdff59a8c3061fb5fca623c07f1a7e49
2 * Copyright (c) 2013 Andreas Sandberg
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Andreas Sandberg
31 #include "test_helper.h"
37 unsigned test_current
= 0;
38 unsigned test_count
= 0;
39 unsigned test_fail_count
= 0;
42 test_init(unsigned no_tests
)
44 assert(test_count
== 0 && test_current
== 0);
46 test_count
= no_tests
;
50 printf("1..%u\n", no_tests
);
63 test_bail(const char *fmt
, ...)
78 test_diag(const char *fmt
, ...)
91 test_vstatus(const char *status
, const char *test
,
92 const char *directive
,
93 const char *fmt_why
, va_list ap
)
95 printf("%s %i", status
, test_current
);
97 if (test
&& test
[0] != '\0')
98 printf(" - %s", test
);
100 if (directive
&& directive
[0] != '\0') {
101 printf(" # %s ", directive
);
102 if (fmt_why
&& fmt_why
[0] != '\0')
103 vprintf(fmt_why
, ap
);
110 static void __attribute__((format (printf
, 4, 5)))
111 test_status(const char *status
, const char *test
,
112 const char *directive
,
113 const char *fmt_why
, ...)
116 va_start(ap
, fmt_why
);
118 test_vstatus(status
, test
, directive
, fmt_why
, ap
);
124 test_ok(const char *test
)
126 test_status("ok", test
, NULL
, NULL
);
130 test_fail(const char *test
)
132 test_status("not ok", test
, NULL
, NULL
);
137 test_skip(const char *test
, const char *fmt_why
, ...)
140 va_start(ap
, fmt_why
);
142 test_vstatus("ok", test
, "SKIP", fmt_why
, ap
);
148 test_todo(const char *test
, const char *fmt_why
, ...)
151 va_start(ap
, fmt_why
);
153 test_vstatus("not ok", test
, "TODO", fmt_why
, ap
);