]>
git.proxmox.com Git - libgit2.git/blob - tests/clar/print.h
1 /* clap: clar protocol, the traditional clar output format */
3 static void clar_print_clap_init(int test_count
, int suite_count
, const char *suite_names
)
6 printf("Loaded %d suites: %s\n", (int)suite_count
, suite_names
);
7 printf("Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')\n");
10 static void clar_print_clap_shutdown(int test_count
, int suite_count
, int error_count
)
20 static void clar_print_clap_error(int num
, const struct clar_report
*report
, const struct clar_error
*error
)
22 printf(" %d) Failure:\n", num
);
24 printf("%s::%s [%s:%"PRIuZ
"]\n",
30 printf(" %s\n", error
->error_msg
);
32 if (error
->description
!= NULL
)
33 printf(" %s\n", error
->description
);
39 static void clar_print_clap_ontest(const char *test_name
, int test_number
, enum cl_test_status 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;
54 static void clar_print_clap_onsuite(const char *suite_name
, int suite_index
)
56 if (_clar
.report_suite_names
)
57 printf("\n%s", suite_name
);
62 static void clar_print_clap_onabort(const char *fmt
, va_list arg
)
64 vfprintf(stderr
, fmt
, arg
);
67 /* tap: test anywhere protocol format */
69 static void clar_print_tap_init(int test_count
, int suite_count
, const char *suite_names
)
74 printf("TAP version 13\n");
77 static void clar_print_tap_shutdown(int test_count
, int suite_count
, int error_count
)
82 printf("1..%d\n", test_count
);
85 static void clar_print_tap_error(int num
, const struct clar_report
*report
, const struct clar_error
*error
)
92 static void print_escaped(const char *str
)
96 while ((c
= strchr(str
, '\'')) != NULL
) {
97 printf("%.*s", (int)(c
- str
), str
);
105 static void clar_print_tap_ontest(const char *test_name
, int test_number
, enum cl_test_status status
)
107 const struct clar_error
*error
= _clar
.last_report
->errors
;
114 printf("ok %d - %s::%s\n", test_number
, _clar
.active_suite
, test_name
);
116 case CL_TEST_FAILURE
:
117 printf("not ok %d - %s::%s\n", test_number
, _clar
.active_suite
, test_name
);
120 printf(" reason: |\n");
121 printf(" %s\n", error
->error_msg
);
123 if (error
->description
)
124 printf(" %s\n", error
->description
);
127 printf(" file: '"); print_escaped(error
->file
); printf("'\n");
128 printf(" line: %" PRIuZ
"\n", error
->line_number
);
129 printf(" function: '%s'\n", error
->function
);
135 printf("ok %d - # SKIP %s::%s\n", test_number
, _clar
.active_suite
, test_name
);
142 static void clar_print_tap_onsuite(const char *suite_name
, int suite_index
)
144 printf("# start of suite %d: %s\n", suite_index
, suite_name
);
147 static void clar_print_tap_onabort(const char *fmt
, va_list arg
)
149 printf("Bail out! ");
154 /* indirection between protocol output selection */
156 #define PRINT(FN, ...) do { \
157 switch (_clar.output_format) { \
158 case CL_OUTPUT_CLAP: \
159 clar_print_clap_##FN (__VA_ARGS__); \
161 case CL_OUTPUT_TAP: \
162 clar_print_tap_##FN (__VA_ARGS__); \
169 static void clar_print_init(int test_count
, int suite_count
, const char *suite_names
)
171 PRINT(init
, test_count
, suite_count
, suite_names
);
174 static void clar_print_shutdown(int test_count
, int suite_count
, int error_count
)
176 PRINT(shutdown
, test_count
, suite_count
, error_count
);
179 static void clar_print_error(int num
, const struct clar_report
*report
, const struct clar_error
*error
)
181 PRINT(error
, num
, report
, error
);
184 static void clar_print_ontest(const char *test_name
, int test_number
, enum cl_test_status status
)
186 PRINT(ontest
, test_name
, test_number
, status
);
189 static void clar_print_onsuite(const char *suite_name
, int suite_index
)
191 PRINT(onsuite
, suite_name
, suite_index
);
194 static void clar_print_onabort(const char *msg
, ...)
198 PRINT(onabort
, msg
, argp
);