@@ -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