]> git.proxmox.com Git - libgit2.git/blame - tests/clar/clar/print.h
Merge https://salsa.debian.org/debian/libgit2 into proxmox/bullseye
[libgit2.git] / tests / clar / clar / print.h
CommitLineData
22a2d3d5 1/* clap: clar protocol, the traditional clar output format */
2e6f06a8 2
22a2d3d5 3static void clar_print_clap_init(int test_count, int suite_count, const char *suite_names)
2e6f06a8
VM
4{
5 (void)test_count;
6 printf("Loaded %d suites: %s\n", (int)suite_count, suite_names);
eae0bfdc 7 printf("Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')\n");
2e6f06a8
VM
8}
9
22a2d3d5 10static void clar_print_clap_shutdown(int test_count, int suite_count, int error_count)
2e6f06a8
VM
11{
12 (void)test_count;
13 (void)suite_count;
14 (void)error_count;
15
16 printf("\n\n");
6c7cee42 17 clar_report_all();
2e6f06a8
VM
18}
19
22a2d3d5 20static void clar_print_clap_error(int num, const struct clar_report *report, const struct clar_error *error)
2e6f06a8
VM
21{
22 printf(" %d) Failure:\n", num);
23
22a2d3d5 24 printf("%s::%s [%s:%"PRIuZ"]\n",
6c7cee42
RD
25 report->suite,
26 report->test,
2e6f06a8
VM
27 error->file,
28 error->line_number);
29
30 printf(" %s\n", error->error_msg);
31
32 if (error->description != NULL)
33 printf(" %s\n", error->description);
34
35 printf("\n");
36 fflush(stdout);
37}
38
22a2d3d5 39static void clar_print_clap_ontest(const char *test_name, int test_number, enum cl_test_status status)
2e6f06a8
VM
40{
41 (void)test_name;
42 (void)test_number;
0f65733b
VM
43
44 switch(status) {
45 case CL_TEST_OK: printf("."); break;
46 case CL_TEST_FAILURE: printf("F"); break;
47 case CL_TEST_SKIP: printf("S"); break;
6c7cee42 48 case CL_TEST_NOTRUN: printf("N"); break;
0f65733b
VM
49 }
50
2e6f06a8
VM
51 fflush(stdout);
52}
53
22a2d3d5 54static void clar_print_clap_onsuite(const char *suite_name, int suite_index)
2e6f06a8 55{
e8a92fe1
RB
56 if (_clar.report_suite_names)
57 printf("\n%s", suite_name);
58
2e6f06a8 59 (void)suite_index;
2e6f06a8
VM
60}
61
22a2d3d5
UG
62static void clar_print_clap_onabort(const char *fmt, va_list arg)
63{
64 vfprintf(stderr, fmt, arg);
65}
66
67/* tap: test anywhere protocol format */
68
69static 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
77static 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
85static 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
92static 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
105static 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'\n", error->function);
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
142static 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
147static 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
154/* indirection between protocol output selection */
155
156#define PRINT(FN, ...) do { \
157 switch (_clar.output_format) { \
158 case CL_OUTPUT_CLAP: \
159 clar_print_clap_##FN (__VA_ARGS__); \
160 break; \
161 case CL_OUTPUT_TAP: \
162 clar_print_tap_##FN (__VA_ARGS__); \
163 break; \
164 default: \
165 abort(); \
166 } \
167 } while (0)
168
169static void clar_print_init(int test_count, int suite_count, const char *suite_names)
170{
171 PRINT(init, test_count, suite_count, suite_names);
172}
173
174static void clar_print_shutdown(int test_count, int suite_count, int error_count)
175{
176 PRINT(shutdown, test_count, suite_count, error_count);
177}
178
179static void clar_print_error(int num, const struct clar_report *report, const struct clar_error *error)
180{
181 PRINT(error, num, report, error);
182}
183
184static void clar_print_ontest(const char *test_name, int test_number, enum cl_test_status status)
185{
186 PRINT(ontest, test_name, test_number, status);
187}
188
189static void clar_print_onsuite(const char *suite_name, int suite_index)
190{
191 PRINT(onsuite, suite_name, suite_index);
192}
193
2e6f06a8
VM
194static void clar_print_onabort(const char *msg, ...)
195{
196 va_list argp;
197 va_start(argp, msg);
22a2d3d5 198 PRINT(onabort, msg, argp);
2e6f06a8
VM
199 va_end(argp);
200}