run_tests supports --reverse arg

This commit is contained in:
Andrew Kelley 2015-12-04 23:04:49 -07:00
parent c7615c1a80
commit f49e857b9b

View File

@ -548,12 +548,21 @@ static void run_test(TestCase *test_case) {
} }
} }
static void run_all_tests(void) { static void run_all_tests(bool reverse) {
for (int i = 0; i < test_cases.length; i += 1) { if (reverse) {
TestCase *test_case = test_cases.at(i); for (int i = test_cases.length - 1; i >= 0; i -= 1) {
printf("Test %d/%d %s...", i + 1, test_cases.length, test_case->case_name); TestCase *test_case = test_cases.at(i);
run_test(test_case); printf("Test %d/%d %s...", i + 1, test_cases.length, test_case->case_name);
printf("OK\n"); run_test(test_case);
printf("OK\n");
}
} else {
for (int i = 0; i < test_cases.length; i += 1) {
TestCase *test_case = test_cases.at(i);
printf("Test %d/%d %s...", i + 1, test_cases.length, test_case->case_name);
run_test(test_case);
printf("OK\n");
}
} }
printf("%d tests passed.\n", test_cases.length); printf("%d tests passed.\n", test_cases.length);
} }
@ -563,9 +572,22 @@ static void cleanup(void) {
remove(tmp_exe_path); remove(tmp_exe_path);
} }
static int usage(const char *arg0) {
fprintf(stderr, "Usage: %s [--reverse]\n", arg0);
return 1;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
bool reverse = false;
for (int i = 1; i < argc; i += 1) {
if (strcmp(argv[i], "--reverse") == 0) {
reverse = true;
} else {
return usage(argv[0]);
}
}
add_compiling_test_cases(); add_compiling_test_cases();
add_compile_failure_test_cases(); add_compile_failure_test_cases();
run_all_tests(); run_all_tests(reverse);
cleanup(); cleanup();
} }