diff --git a/v0/test.c b/v0/test.c index b8cd999..00f91b4 100644 --- a/v0/test.c +++ b/v0/test.c @@ -74,6 +74,7 @@ TokenStream* test_get_tokenstream(void) { if (s_testSource) free(s_testSource); s_testSource = read_file_content(filepath); if (!s_testSource) { + puts(filepath); fail("could not read test source file"); free(filepath); return NULL; @@ -184,38 +185,37 @@ typedef struct { static int s_totalTests; static int s_greenTests; +#define TEST(name) {#name, name}, + static TestCase s_tests[] = { - {"tokenstream_open_fail", test_tokenstream_open_fail}, - {"tokenstream_simple_keyword", test_tokenstream_simple_keyword}, - {"tokenstream_keywords_and_symbols", test_tokenstream_keywords_and_symbols}, - {"tokenstream_parentheses_and_brackets", test_tokenstream_parentheses_and_brackets}, - {"tokenstream_comma", test_tokenstream_comma}, - {"tokenstream_whitespace_ignored", test_tokenstream_whitespace_ignored}, - {"tokenstream_void_function_signature", test_tokenstream_void_function_signature}, - {"tokenstream_unknown_token", test_tokenstream_unknown_token}, - {"tokenstream_info", test_tokenstream_info}, - {"parser_module_name", test_parser_module_name}, - {"parser_bad_module_name", test_parser_bad_module_name}, - {"parser_missing_semicolon_module", test_parser_missing_semicolon_module}, - {"parser_missing_semicolon_import", test_parser_missing_semicolon_import}, - {"parser_bad_import_name", test_parser_bad_import_name}, - {"parser_imports", test_parser_imports}, - {"parser_public_imports", test_parser_public_imports}, - {"parser_alias_simple", test_parser_alias_simple}, - {"parser_alias_array", test_parser_alias_array}, - {"log_error", test_log_error}, - {"log_on_line", test_log_on_line}, - {"log_on_line_variadic", test_log_on_line_variadic}, - {"parser_alias_and_import_mix", test_parser_alias_and_import_mix}, + TEST(test_log_error) + TEST(test_log_on_line_variadic) + TEST(test_log_on_line) + TEST(test_parser_alias_and_import_mix) + TEST(test_parser_alias_array) + TEST(test_parser_alias_simple) + TEST(test_parser_bad_import_name) + TEST(test_parser_bad_module_name) + TEST(test_parser_imports) + TEST(test_parser_missing_semicolon_import) + TEST(test_parser_missing_semicolon_module) + TEST(test_parser_module_name) + TEST(test_parser_public_imports) + TEST(test_tokenstream_comma) + TEST(test_tokenstream_info) + TEST(test_tokenstream_keywords_and_symbols) + TEST(test_tokenstream_open_fail) + TEST(test_tokenstream_parentheses_and_brackets) + TEST(test_tokenstream_simple_keyword) + TEST(test_tokenstream_unknown_token) + TEST(test_tokenstream_void_function_signature) + TEST(test_tokenstream_whitespace_ignored) }; int main(int argc, char** argv) { - /* Declarations first for C89 */ const char** failedTests; int failedCount; - int i; - int j; (void)argc; (void)argv; @@ -223,12 +223,13 @@ int main(int argc, char** argv) { s_totalTests = sizeof(s_tests) / sizeof(s_tests[0]); s_greenTests = 0; - /* Allocate failed tests array dynamically to avoid VLAs */ + // Allocate failed tests array dynamically to avoid VLAs failedTests = (const char**)malloc((s_totalTests + 1) * sizeof(const char*)); failedCount = 0; - for (i = 0; i < s_totalTests; i++) { - s_currentTestName = s_tests[i].name; + for (int i = 0; i < s_totalTests; i++) { + // Add 5 to strip the 'test_' prefix. + s_currentTestName = s_tests[i].name + 5; log_set_output(log_append); printf("%s...", s_tests[i].name); fflush(stdout); @@ -264,7 +265,7 @@ int main(int argc, char** argv) { if (failedCount > 0) { printf("\nFailed tests:\n"); - for (j = 0; j < failedCount; j++) { + for (int j = 0; j < failedCount; j++) { printf(" - %s\n", failedTests[j]); } }