xaizek / stic (License: MIT) (since 2018-12-07)
Simple Tests In C with optional automatic test registration in C.
Commit a2d0e6b4738a7bf559781369319e819690a1575d

Change "sea_" prefix to "stic_" in stic

Strange that it went unnoticed before.

Also removed a bunch of TODO entries.

Author: xaizek
Author date (UTC): 2017-09-03 14:45
Committer: xaizek
Commit date (UTC): 2017-09-03 17:16
Tree: 5c5b024978927bb8ca0a1f804d0fe86342827155
Parents: 65736d3e07cfcc986d91007aa26e2a71ac3a3273
Signing key: 99DC5E4DB05F6BE2
File Lines added Lines deleted
src/stic.c 29 29

File src/stic.c changed (mode: 100644) (index 3a4e61e..d9a4238)
... ... int stic_is_string_equal_i(const char* s1, const char* s2)
50 50 #endif #endif
51 51
52 52 #ifdef STIC_INTERNAL_TESTS #ifdef STIC_INTERNAL_TESTS
53 static int sea_test_last_passed = 0;
53 static int stic_test_last_passed = 0;
54 54 #endif #endif
55 55
56 56 typedef enum typedef enum
 
... ... typedef struct
69 69 } stic_testrunner_t; } stic_testrunner_t;
70 70
71 71 static int stic_screen_width = 70; static int stic_screen_width = 70;
72 static int sea_tests_run = 0;
73 static int sea_tests_skipped = 0;
74 static int sea_tests_failed = 0;
75 static int sea_checks_passed = 0;
76 static int sea_checks_failed = 0;
72 static int stic_tests_run = 0;
73 static int stic_tests_skipped = 0;
74 static int stic_tests_failed = 0;
75 static int stic_checks_passed = 0;
76 static int stic_checks_failed = 0;
77 77 static int stic_display_only = 0; static int stic_display_only = 0;
78 78 static int stic_verbose = 0; static int stic_verbose = 0;
79 79 static int stic_random_failures = 0; static int stic_random_failures = 0;
 
... ... void stic_suite_setup( void )
128 128
129 129 void stic_skip_test(const char fixture[], const char test[]) void stic_skip_test(const char fixture[], const char test[])
130 130 { {
131 sea_tests_skipped++;
131 stic_tests_skipped++;
132 132 } }
133 133
134 134 int stic_positive_predicate( void ) int stic_positive_predicate( void )
 
... ... static int stic_fixture_checks_passed;
184 184
185 185 static int test_had_output(void) static int test_had_output(void)
186 186 { {
187 const int nfailed = sea_checks_failed - stic_fixture_checks_failed;
188 const int npassed = sea_checks_passed - stic_fixture_checks_passed;
187 const int nfailed = stic_checks_failed - stic_fixture_checks_failed;
188 const int npassed = stic_checks_passed - stic_fixture_checks_passed;
189 189 return (nfailed != 0 || (npassed != 0 && stic_verbose)); return (nfailed != 0 || (npassed != 0 && stic_verbose));
190 190 } }
191 191
 
... ... void stic_simple_test_result_log(int passed, char* reason, const char* function,
229 229 " %s\n", " %s\n",
230 230 file, line, function, reason ); file, line, function, reason );
231 231 } }
232 sea_checks_failed++;
232 stic_checks_failed++;
233 233
234 234 if (last_failed_test != stic_current_test) if (last_failed_test != stic_current_test)
235 235 { {
236 ++sea_tests_failed;
236 ++stic_tests_failed;
237 237 } }
238 238 last_failed_test = stic_current_test; last_failed_test = stic_current_test;
239 239
 
... ... void stic_simple_test_result_log(int passed, char* reason, const char* function,
259 259 } }
260 260 last_test = stic_current_test; last_test = stic_current_test;
261 261 } }
262 sea_checks_passed++;
262 stic_checks_passed++;
263 263 } }
264 264 } }
265 265
 
... ... void stic_assert_string_doesnt_contain(const char* expected, const char* actual,
425 425
426 426 void stic_run_test(const char fixture[], const char test[]) void stic_run_test(const char fixture[], const char test[])
427 427 { {
428 sea_tests_run++;
428 stic_tests_run++;
429 429 } }
430 430
431 431 void stic_test_fixture_start(const char filepath[]) void stic_test_fixture_start(const char filepath[])
432 432 { {
433 433 stic_current_fixture_path = filepath; stic_current_fixture_path = filepath;
434 434 stic_current_fixture = test_file_name(filepath); stic_current_fixture = test_file_name(filepath);
435 stic_fixture_checks_failed = sea_checks_failed;
436 stic_fixture_checks_passed = sea_checks_passed;
437 stic_fixture_tests_run = sea_tests_run;
435 stic_fixture_checks_failed = stic_checks_failed;
436 stic_fixture_checks_passed = stic_checks_passed;
437 stic_fixture_tests_run = stic_tests_run;
438 438 stic_fixture_teardown = 0; stic_fixture_teardown = 0;
439 439 stic_fixture_setup = 0; stic_fixture_setup = 0;
440 440
 
... ... void stic_test_fixture_start(const char filepath[])
447 447 void stic_test_fixture_end() void stic_test_fixture_end()
448 448 { {
449 449 char s[STIC_PRINT_BUFFER_SIZE]; char s[STIC_PRINT_BUFFER_SIZE];
450 const int nrun = sea_tests_run - stic_fixture_tests_run;
451 const int nfailed = sea_checks_failed - stic_fixture_checks_failed;
450 const int nrun = stic_tests_run - stic_fixture_tests_run;
451 const int nfailed = stic_checks_failed - stic_fixture_checks_failed;
452 452
453 453 if (stic_silent) if (stic_silent)
454 454 { {
 
... ... int run_tests(stic_void_void tests)
542 542 printf("\n"); printf("\n");
543 543 stic_header_printer(version, stic_screen_width, '='); stic_header_printer(version, stic_screen_width, '=');
544 544 printf("\n"); printf("\n");
545 if (sea_checks_failed > 0) {
545 if (stic_checks_failed > 0) {
546 546 snprintf(s, sizeof(s), "%d CHECK%s IN %d TEST%s FAILED", snprintf(s, sizeof(s), "%d CHECK%s IN %d TEST%s FAILED",
547 sea_checks_failed, sea_checks_failed == 1 ? "" : "S",
548 sea_tests_failed, sea_tests_failed == 1 ? "" : "S");
547 stic_checks_failed, stic_checks_failed == 1 ? "" : "S",
548 stic_tests_failed, stic_tests_failed == 1 ? "" : "S");
549 549 stic_header_printer(s, stic_screen_width, ' '); stic_header_printer(s, stic_screen_width, ' ');
550 550 } }
551 551 else else
 
... ... int run_tests(stic_void_void tests)
567 567 } }
568 568
569 569 sprintf(s,"%d check%s :: %d run test%s :: %d skipped test%s :: %s", sprintf(s,"%d check%s :: %d run test%s :: %d skipped test%s :: %s",
570 sea_checks_passed + sea_checks_failed,
571 sea_checks_passed + sea_checks_failed == 1 ? "" : "s",
572 sea_tests_run, sea_tests_run == 1 ? "" : "s",
573 sea_tests_skipped, sea_tests_skipped == 1 ? "" : "s",
570 stic_checks_passed + stic_checks_failed,
571 stic_checks_passed + stic_checks_failed == 1 ? "" : "s",
572 stic_tests_run, stic_tests_run == 1 ? "" : "s",
573 stic_tests_skipped, stic_tests_skipped == 1 ? "" : "s",
574 574 time); time);
575 575 stic_header_printer(s, stic_screen_width, ' '); stic_header_printer(s, stic_screen_width, ' ');
576 576
577 577 printf("\n"); printf("\n");
578 578 stic_header_printer("", stic_screen_width, '='); stic_header_printer("", stic_screen_width, '=');
579 579
580 return sea_checks_failed == 0;
580 return stic_checks_failed == 0;
581 581 } }
582 582
583 583 void stic_show_help( void ) void stic_show_help( void )
 
... ... int stic_testrunner(int argc, char** argv, stic_void_void tests, stic_void_void
683 683
684 684 void stic_simple_test_result_nolog(int passed, char* reason, const char* function, const char file[], unsigned int line) void stic_simple_test_result_nolog(int passed, char* reason, const char* function, const char file[], unsigned int line)
685 685 { {
686 sea_test_last_passed = passed;
686 stic_test_last_passed = passed;
687 687 } }
688 688
689 689 void stic_assert_last_passed() void stic_assert_last_passed()
690 690 { {
691 assert_int_equal(1, sea_test_last_passed);
691 assert_int_equal(1, stic_test_last_passed);
692 692 } }
693 693
694 694 void stic_assert_last_failed() void stic_assert_last_failed()
695 695 { {
696 assert_int_equal(0, sea_test_last_passed);
696 assert_int_equal(0, stic_test_last_passed);
697 697 } }
698 698
699 699 void stic_disable_logging() void stic_disable_logging()
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/stic

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/stic

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master