53MAIN(
int argc,
const char* argv[]) {
54 if (!(argc == 2 || argc == 3)) {
55 fail(1,
"use as: %s TESTFILE [TESTFOLDER]\n", argv[0]);
57 const char* folder =
".";
62 FILE* handle = fopen(argv[1],
"r");
65 fail(1,
"Failed to open file for reading\n");
71 char filename[PATH_MAX];
75 while (!feof(handle) && (cur =
fpeekc(handle)) != EOF) {
85 if (!feof(handle) &&
fpeekc(handle) ==
'!') {
90 if (!feof(handle) &&
fpeekc(handle) ==
' ') {
95 while (!feof(handle) && cur !=
'\n') {
101 while (!feof(handle) && cur !=
'\n') {
107 }
else if (cur ==
'\n') {
114 "Expected comment or test directive on line %zu, "
115 "received character '%c' instead\n",
121 if (fscanf(handle,
"%d %127s\n", &exit_code, filename) != 2) {
123 fail(1,
"Failed to parse line %zu\n", line);
127 if (
run_test(exit_code, filename, folder) != 0) {
131 if (fclose(handle) != 0) {
133 fail(1,
"Failed to close file\n");
138 printf(
"\nSummary:\n");
139 if (errors == tests) {
140 printf(
" - \033[31;1mNone of the %d test(s) passed\033[m\n", tests);
142 }
else if (errors > tests / 2) {
144 " - \033[31;1mLess than half of the tests (%d/%d) passed\033[m\n",
145 tests - errors, tests);
147 }
else if (errors > 0) {
148 printf(
" ~ \033[33;1mMost of the tests (%d/%d) passed\033[m\n",
149 tests - errors, tests);
152 printf(
" + \033[32;1mAll %d test(s) passed!\033[m\n", tests);
Enables programs to be located in the project directory.
#define MAIN
Defines a main function that should not be treated as a main function unless explicitly desired by th...