| ... | ... | @@ -548,12 +548,21 @@ static void run_test(TestCase *test_case) { |
| 548 | 548 | } |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | | static void run_all_tests(void) { |
| 552 | | for (int i = 0; i < test_cases.length; i += 1) { |
| 553 | | TestCase *test_case = test_cases.at(i); |
| 554 | | printf("Test %d/%d %s...", i + 1, test_cases.length, test_case->case_name); |
| 555 | | run_test(test_case); |
| 556 | | printf("OK\n"); |
| 551 | static void run_all_tests(bool reverse) { |
| 552 | if (reverse) { |
| 553 | for (int i = test_cases.length - 1; i >= 0; i -= 1) { |
| 554 | TestCase *test_case = test_cases.at(i); |
| 555 | printf("Test %d/%d %s...", i + 1, test_cases.length, test_case->case_name); |
| 556 | run_test(test_case); |
| 557 | printf("OK\n"); |
| 558 | } |
| 559 | } else { |
| 560 | for (int i = 0; i < test_cases.length; i += 1) { |
| 561 | TestCase *test_case = test_cases.at(i); |
| 562 | printf("Test %d/%d %s...", i + 1, test_cases.length, test_case->case_name); |
| 563 | run_test(test_case); |
| 564 | printf("OK\n"); |
| 565 | } |
| 557 | 566 | } |
| 558 | 567 | printf("%d tests passed.\n", test_cases.length); |
| 559 | 568 | } |
| ... | ... | @@ -563,9 +572,22 @@ static void cleanup(void) { |
| 563 | 572 | remove(tmp_exe_path); |
| 564 | 573 | } |
| 565 | 574 | |
| 575 | static int usage(const char *arg0) { |
| 576 | fprintf(stderr, "Usage: %s [--reverse]\n", arg0); |
| 577 | return 1; |
| 578 | } |
| 579 | |
| 566 | 580 | int main(int argc, char **argv) { |
| 581 | bool reverse = false; |
| 582 | for (int i = 1; i < argc; i += 1) { |
| 583 | if (strcmp(argv[i], "--reverse") == 0) { |
| 584 | reverse = true; |
| 585 | } else { |
| 586 | return usage(argv[0]); |
| 587 | } |
| 588 | } |
| 567 | 589 | add_compiling_test_cases(); |
| 568 | 590 | add_compile_failure_test_cases(); |
| 569 | | run_all_tests(); |
| 591 | run_all_tests(reverse); |
| 570 | 592 | cleanup(); |
| 571 | 593 | } |