]> git.proxmox.com Git - libgit2.git/blob - tests/clar/print.h
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / clar / print.h
1 /* clap: clar protocol, the traditional clar output format */
2
3 static void clar_print_clap_init(int test_count, int suite_count, const char *suite_names)
4 {
5 (void)test_count;
6 printf("Loaded %d suites: %s\n", (int)suite_count, suite_names);
7 printf("Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')\n");
8 }
9
10 static void clar_print_clap_shutdown(int test_count, int suite_count, int error_count)
11 {
12 (void)test_count;
13 (void)suite_count;
14 (void)error_count;
15
16 printf("\n\n");
17 clar_report_all();
18 }
19
20 static void clar_print_clap_error(int num, const struct clar_report *report, const struct clar_error *error)
21 {
22 printf(" %d) Failure:\n", num);
23
24 printf("%s::%s [%s:%"PRIuZ"]\n",
25 report->suite,
26 report->test,
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
39 static void clar_print_clap_ontest(const char *test_name, int test_number, enum cl_test_status status)
40 {
41 (void)test_name;
42 (void)test_number;
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;
48 case CL_TEST_NOTRUN: printf("N"); break;
49 }
50
51 fflush(stdout);
52 }
53
54 static void clar_print_clap_onsuite(const char *suite_name, int suite_index)
55 {
56 if (_clar.report_suite_names)
57 printf("\n%s", suite_name);
58
59 (void)suite_index;
60 }
61
62 static 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
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'\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
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
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
169 static 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
174 static 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
179 static 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
184 static 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
189 static void clar_print_onsuite(const char *suite_name, int suite_index)
190 {
191 PRINT(onsuite, suite_name, suite_index);
192 }
193
194 static void clar_print_onabort(const char *msg, ...)
195 {
196 va_list argp;
197 va_start(argp, msg);
198 PRINT(onabort, msg, argp);
199 va_end(argp);
200 }