Skip to content

Commit f7250cc

Browse files
committed
clar: add tap output
1 parent 691315e commit f7250cc

File tree

3 files changed

+99
-3
lines changed

3 files changed

+99
-3
lines changed

tests/clar.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ clar_usage(const char *arg)
363363
printf(" -v Increase verbosity (show suite names)\n");
364364
printf(" -q Only report tests that had an error\n");
365365
printf(" -Q Quit as soon as a test fails\n");
366+
printf(" -t Display results in tap format\n");
366367
printf(" -l Print suite names\n");
367368
printf(" -r[filename] Write summary file (to the optional filename)\n");
368369
exit(-1);
@@ -378,7 +379,7 @@ clar_parse_args(int argc, char **argv)
378379
char *argument = argv[i];
379380

380381
if (argument[0] != '-' || argument[1] == '\0'
381-
|| strchr("sixvqQlr", argument[1]) == NULL) {
382+
|| strchr("sixvqQtlr", argument[1]) == NULL) {
382383
clar_usage(argv[0]);
383384
}
384385
}
@@ -461,6 +462,10 @@ clar_parse_args(int argc, char **argv)
461462
_clar.exit_on_error = 1;
462463
break;
463464

465+
case 't':
466+
_clar.output_format = CL_OUTPUT_TAP;
467+
break;
468+
464469
case 'l': {
465470
size_t j;
466471
printf("Test suites (use -s<name> to run just one):\n");

tests/clar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum cl_test_status {
1818

1919
enum cl_output_format {
2020
CL_OUTPUT_CLAP,
21+
CL_OUTPUT_TAP,
2122
};
2223

2324
/** Setup clar environment */

tests/clar/print.h

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,102 @@ static void clar_print_clap_onabort(const char *fmt, va_list arg)
6464
vfprintf(stderr, fmt, arg);
6565
}
6666

67+
/* tap: test anywhere protocol format */
68+
69+
static void clar_print_tap_init(int test_count, int suite_count, const char *suite_names)
70+
{
71+
(void)test_count;
72+
(void)suite_count;
73+
(void)suite_names;
74+
printf("TAP version 13\n");
75+
}
76+
77+
static void clar_print_tap_shutdown(int test_count, int suite_count, int error_count)
78+
{
79+
(void)suite_count;
80+
(void)error_count;
81+
82+
printf("1..%d\n", test_count);
83+
}
84+
85+
static void clar_print_tap_error(int num, const struct clar_report *report, const struct clar_error *error)
86+
{
87+
(void)num;
88+
(void)report;
89+
(void)error;
90+
}
91+
92+
static void print_escaped(const char *str)
93+
{
94+
char *c;
95+
96+
while ((c = strchr(str, '\'')) != NULL) {
97+
printf("%.*s", (int)(c - str), str);
98+
printf("''");
99+
str = c + 1;
100+
}
101+
102+
printf("%s", str);
103+
}
104+
105+
static void clar_print_tap_ontest(const char *test_name, int test_number, enum cl_test_status status)
106+
{
107+
const struct clar_error *error = _clar.last_report->errors;
108+
109+
(void)test_name;
110+
(void)test_number;
111+
112+
switch(status) {
113+
case CL_TEST_OK:
114+
printf("ok %d - %s::%s\n", test_number, _clar.active_suite, test_name);
115+
break;
116+
case CL_TEST_FAILURE:
117+
printf("not ok %d - %s::%s\n", test_number, _clar.active_suite, test_name);
118+
119+
printf(" ---\n");
120+
printf(" reason: |\n");
121+
printf(" %s\n", error->error_msg);
122+
123+
if (error->description)
124+
printf(" %s\n", error->description);
125+
126+
printf(" at:\n");
127+
printf(" file: '"); print_escaped(error->file); printf("'\n");
128+
printf(" line: %" PRIuZ "\n", error->line_number);
129+
printf(" function: '%s::%s'\n", _clar.active_suite, test_name);
130+
printf(" ---\n");
131+
132+
break;
133+
case CL_TEST_SKIP:
134+
case CL_TEST_NOTRUN:
135+
printf("ok %d - # SKIP %s::%s\n", test_number, _clar.active_suite, test_name);
136+
break;
137+
}
138+
139+
fflush(stdout);
140+
}
141+
142+
static void clar_print_tap_onsuite(const char *suite_name, int suite_index)
143+
{
144+
printf("# start of suite %d: %s\n", suite_index, suite_name);
145+
}
146+
147+
static void clar_print_tap_onabort(const char *fmt, va_list arg)
148+
{
149+
printf("Bail out! ");
150+
vprintf(fmt, arg);
151+
fflush(stdout);
152+
}
153+
67154
/* indirection between protocol output selection */
68155

69-
#define PRINT(FN, args...) do { \
156+
#define PRINT(FN, ...) do { \
70157
switch (_clar.output_format) { \
71158
case CL_OUTPUT_CLAP: \
72-
clar_print_clap_##FN (args); \
159+
clar_print_clap_##FN (__VA_ARGS__); \
160+
break; \
161+
case CL_OUTPUT_TAP: \
162+
clar_print_tap_##FN (__VA_ARGS__); \
73163
break; \
74164
default: \
75165
abort(); \

0 commit comments

Comments
 (0)