File src/stic.c changed (mode: 100644) (index ccfd5e4..da4b355) |
... |
... |
static int sea_tests_failed = 0; |
75 |
75 |
static int stic_display_only = 0; |
static int stic_display_only = 0; |
76 |
76 |
static int stic_verbose = 0; |
static int stic_verbose = 0; |
77 |
77 |
static int stic_random_failures = 0; |
static int stic_random_failures = 0; |
|
78 |
|
static int stic_silent = 0; |
78 |
79 |
static int stic_machine_readable = 0; |
static int stic_machine_readable = 0; |
79 |
80 |
static const char *stic_current_fixture; |
static const char *stic_current_fixture; |
80 |
81 |
static const char *stic_current_fixture_path; |
static const char *stic_current_fixture_path; |
|
... |
... |
int stic_is_display_only() |
104 |
105 |
return stic_display_only; |
return stic_display_only; |
105 |
106 |
} |
} |
106 |
107 |
|
|
|
108 |
|
static void stic_header_printer(const char s[], int length, char f) |
|
109 |
|
{ |
|
110 |
|
int l = strlen(s); |
|
111 |
|
int d = (length- (l + 2)) / 2; |
|
112 |
|
int i; |
|
113 |
|
if(stic_is_display_only() || stic_machine_readable) return; |
|
114 |
|
for(i = 0; i<d; i++) printf("%c",f); |
|
115 |
|
if(l==0) printf("%c%c", f, f); |
|
116 |
|
else printf(" %s ", s); |
|
117 |
|
for(i = (d+l+2); i<length; i++) printf("%c",f); |
|
118 |
|
printf("\n"); |
|
119 |
|
} |
|
120 |
|
|
107 |
121 |
void stic_suite_setup( void ) |
void stic_suite_setup( void ) |
108 |
122 |
{ |
{ |
109 |
123 |
if(stic_suite_setup_func != 0) stic_suite_setup_func(); |
if(stic_suite_setup_func != 0) stic_suite_setup_func(); |
|
... |
... |
static const char * test_file_name(const char path[]) |
156 |
170 |
|
|
157 |
171 |
static int stic_fixture_tests_run; |
static int stic_fixture_tests_run; |
158 |
172 |
static int stic_fixture_tests_failed; |
static int stic_fixture_tests_failed; |
|
173 |
|
static int stic_fixture_tests_passed; |
|
174 |
|
|
|
175 |
|
static int test_had_output(void) |
|
176 |
|
{ |
|
177 |
|
const int nfailed = sea_tests_failed - stic_fixture_tests_failed; |
|
178 |
|
const int npassed = sea_tests_passed - stic_fixture_tests_passed; |
|
179 |
|
return (nfailed != 0 || (npassed != 0 && stic_verbose)); |
|
180 |
|
} |
159 |
181 |
|
|
160 |
182 |
void stic_simple_test_result_log(int passed, char* reason, const char* function, const char file[], unsigned int line) |
void stic_simple_test_result_log(int passed, char* reason, const char* function, const char file[], unsigned int line) |
161 |
183 |
{ |
{ |
|
... |
... |
void stic_simple_test_result_log(int passed, char* reason, const char* function, |
173 |
195 |
passed = !passed; |
passed = !passed; |
174 |
196 |
} |
} |
175 |
197 |
|
|
|
198 |
|
if (stic_silent && !test_had_output() && (!passed || stic_verbose)) |
|
199 |
|
{ |
|
200 |
|
stic_header_printer(stic_current_fixture, stic_screen_width, '-'); |
|
201 |
|
} |
|
202 |
|
|
176 |
203 |
if (!passed) |
if (!passed) |
177 |
204 |
{ |
{ |
178 |
205 |
if(stic_machine_readable) |
if(stic_machine_readable) |
|
... |
... |
void stic_run_test(const char fixture[], const char test[]) |
378 |
405 |
sea_tests_run++; |
sea_tests_run++; |
379 |
406 |
} |
} |
380 |
407 |
|
|
381 |
|
static void stic_header_printer(const char s[], int length, char f) |
|
382 |
|
{ |
|
383 |
|
int l = strlen(s); |
|
384 |
|
int d = (length- (l + 2)) / 2; |
|
385 |
|
int i; |
|
386 |
|
if(stic_is_display_only() || stic_machine_readable) return; |
|
387 |
|
for(i = 0; i<d; i++) printf("%c",f); |
|
388 |
|
if(l==0) printf("%c%c", f, f); |
|
389 |
|
else printf(" %s ", s); |
|
390 |
|
for(i = (d+l+2); i<length; i++) printf("%c",f); |
|
391 |
|
printf("\n"); |
|
392 |
|
} |
|
393 |
|
|
|
394 |
408 |
void stic_test_fixture_start(const char filepath[]) |
void stic_test_fixture_start(const char filepath[]) |
395 |
409 |
{ |
{ |
396 |
410 |
stic_current_fixture_path = filepath; |
stic_current_fixture_path = filepath; |
397 |
411 |
stic_current_fixture = test_file_name(filepath); |
stic_current_fixture = test_file_name(filepath); |
398 |
|
stic_header_printer(stic_current_fixture, stic_screen_width, '-'); |
|
399 |
412 |
stic_fixture_tests_failed = sea_tests_failed; |
stic_fixture_tests_failed = sea_tests_failed; |
|
413 |
|
stic_fixture_tests_passed = sea_tests_passed; |
400 |
414 |
stic_fixture_tests_run = sea_tests_run; |
stic_fixture_tests_run = sea_tests_run; |
401 |
415 |
stic_fixture_teardown = 0; |
stic_fixture_teardown = 0; |
402 |
416 |
stic_fixture_setup = 0; |
stic_fixture_setup = 0; |
|
417 |
|
|
|
418 |
|
if (!stic_silent) |
|
419 |
|
{ |
|
420 |
|
stic_header_printer(stic_current_fixture, stic_screen_width, '-'); |
|
421 |
|
} |
403 |
422 |
} |
} |
404 |
423 |
|
|
405 |
424 |
void stic_test_fixture_end() |
void stic_test_fixture_end() |
406 |
425 |
{ |
{ |
|
426 |
|
char s[STIC_PRINT_BUFFER_SIZE]; |
407 |
427 |
const int nrun = sea_tests_run - stic_fixture_tests_run; |
const int nrun = sea_tests_run - stic_fixture_tests_run; |
408 |
428 |
const int nfailed = sea_tests_failed - stic_fixture_tests_failed; |
const int nfailed = sea_tests_failed - stic_fixture_tests_failed; |
409 |
|
char s[STIC_PRINT_BUFFER_SIZE]; |
|
410 |
|
|
|
411 |
|
sprintf(s, "%d run %d failed", nrun, nfailed); |
|
412 |
429 |
|
|
413 |
|
if(nrun != 0 && (nfailed != 0 || stic_verbose)) |
|
|
430 |
|
if (stic_silent) |
414 |
431 |
{ |
{ |
|
432 |
|
if (stic_verbose) |
|
433 |
|
{ |
|
434 |
|
if(!test_had_output()) |
|
435 |
|
{ |
|
436 |
|
stic_header_printer(stic_current_fixture, stic_screen_width, '-'); |
|
437 |
|
} |
|
438 |
|
} |
|
439 |
|
else if(!test_had_output()) |
|
440 |
|
{ |
|
441 |
|
return; |
|
442 |
|
} |
415 |
443 |
printf("\n"); |
printf("\n"); |
416 |
444 |
} |
} |
|
445 |
|
else if(test_had_output()) |
|
446 |
|
{ |
|
447 |
|
printf("\n"); |
|
448 |
|
} |
|
449 |
|
|
|
450 |
|
sprintf(s, "%d run %d failed", nrun, nfailed); |
|
451 |
|
|
417 |
452 |
stic_header_printer(s, stic_screen_width, ' '); |
stic_header_printer(s, stic_screen_width, ' '); |
418 |
453 |
printf("\n"); |
printf("\n"); |
419 |
454 |
} |
} |
|
... |
... |
void stic_show_help( void ) |
523 |
558 |
printf("\t-d:\twill just display test names and fixtures without\n"); |
printf("\t-d:\twill just display test names and fixtures without\n"); |
524 |
559 |
printf("\t-d:\trunning the test\n"); |
printf("\t-d:\trunning the test\n"); |
525 |
560 |
printf("\t-r:\tproduce random failures\n"); |
printf("\t-r:\tproduce random failures\n"); |
|
561 |
|
printf("\t-s:\tdo not display fixtures unless they contain failures\n"); |
526 |
562 |
printf("\t-v:\twill print a more verbose version of the test run\n"); |
printf("\t-v:\twill print a more verbose version of the test run\n"); |
527 |
563 |
printf("\t-m:\twill print a machine readable format of the test run, ie :- \n"); |
printf("\t-m:\twill print a machine readable format of the test run, ie :- \n"); |
528 |
564 |
printf("\t \t<textfixture>,<testname>,<linenumber>,<testresult><EOL>\n"); |
printf("\t \t<textfixture>,<testname>,<linenumber>,<testresult><EOL>\n"); |
|
... |
... |
void stic_interpret_commandline(stic_testrunner_t* runner) |
566 |
602 |
} |
} |
567 |
603 |
if(stic_is_string_equal_i(runner->argv[arg], "-d")) runner->action = STIC_DISPLAY_TESTS; |
if(stic_is_string_equal_i(runner->argv[arg], "-d")) runner->action = STIC_DISPLAY_TESTS; |
568 |
604 |
if(stic_is_string_equal_i(runner->argv[arg], "-r")) stic_random_failures = 1; |
if(stic_is_string_equal_i(runner->argv[arg], "-r")) stic_random_failures = 1; |
|
605 |
|
if(stic_is_string_equal_i(runner->argv[arg], "-s")) stic_silent = 1; |
569 |
606 |
if(stic_is_string_equal_i(runner->argv[arg], "-v")) stic_verbose = 1; |
if(stic_is_string_equal_i(runner->argv[arg], "-v")) stic_verbose = 1; |
570 |
607 |
if(stic_is_string_equal_i(runner->argv[arg], "-m")) stic_machine_readable = 1; |
if(stic_is_string_equal_i(runner->argv[arg], "-m")) stic_machine_readable = 1; |
571 |
608 |
if(stic_parse_commandline_option_with_value(runner,arg,"-t", test_filter)) arg++; |
if(stic_parse_commandline_option_with_value(runner,arg,"-t", test_filter)) arg++; |