diff --git a/README.md b/README.md index e21a586..02c8b4a 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ # CI Playground -This is where is play around with [Drone](https://ci.pbrinkmeier.de). +This is where I play around with [Drone](https://ci.pbrinkmeier.de). diff --git a/algo2/pairingheap/tests.h b/algo2/pairingheap/tests.h index ba98dfd..2856a48 100644 --- a/algo2/pairingheap/tests.h +++ b/algo2/pairingheap/tests.h @@ -6,9 +6,14 @@ #include // globals. -int tests_passed = 0; -char *current_label; -int current_num; +struct tests_state { + int passed_tests; + int run_tests; + int total_tests; + char *current_label; +}; + +struct tests_state tests_state = { 0, 0, 0, NULL }; /* Basic idea: @@ -30,23 +35,28 @@ DONE */ #define TEST(LABEL, BLOCK) \ -current_label = LABEL; \ -current_num = __COUNTER__ + 1; \ +tests_state.current_label = LABEL; \ +tests_state.run_tests++; \ +tests_state.total_tests = __COUNTER__; \ BLOCK; \ -fprintf(stderr, "[%3d] \x1b[32m%s ✓\x1b[0m\n", current_num, current_label); \ -tests_passed++; +fprintf(stderr, "[%3d] \x1b[32m%s ✓\x1b[0m\n", tests_state.run_tests, tests_state.current_label); \ +tests_state.passed_tests++; #define ASSERT(EXPR) \ if (!(EXPR)) { \ - fprintf(stderr, "[%3d] \x1b[31m%s ❌\x1b[0m\n", current_num, current_label); \ + fprintf(stderr, "[%3d] \x1b[31m%s ❌\x1b[0m\n", tests_state.run_tests, tests_state.current_label); \ fprintf(stderr, " Assertion failed in %s:%d:\n", __FILE__, __LINE__); \ fprintf(stderr, " " #EXPR "\n"); \ - goto after_tests; \ + goto tests_bail; \ } #define DONE \ -after_tests: { \ - int tests_total = __COUNTER__; \ - fprintf(stderr, "[\x1b[%dm***\x1b[0m] %d/%d tests passed.\n", tests_passed == tests_total ? 32 : 31, tests_passed, tests_total); \ - if (tests_passed != tests_total) exit(1); \ +tests_bail: { \ + tests_state.total_tests = __COUNTER__; \ + fprintf(stderr, "[\x1b[%dm***\x1b[0m] %d/%d tests passed", tests_state.passed_tests == tests_state.total_tests ? 32 : 31, tests_state.passed_tests, tests_state.total_tests); \ + if (tests_state.total_tests > tests_state.run_tests) { \ + fprintf(stderr, ", %d skipped", tests_state.total_tests - tests_state.run_tests); \ + } \ + fprintf(stderr, ".\n"); \ + if (tests_state.passed_tests != tests_state.total_tests) exit(1); \ }