From ea97370f973374f863e4296c2bb872be8b5235a3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 12 Aug 2019 09:48:55 +0200 Subject: Before interpreter. Cleanup build script. Begin writing code analyzer tool to find common mistakes --- tests/main.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'tests/main.c') diff --git a/tests/main.c b/tests/main.c index 5b8bad0..63f72d5 100644 --- a/tests/main.c +++ b/tests/main.c @@ -21,7 +21,7 @@ static int num_tests_run = 0; static CHECK_RESULT int test_hash_map() { ArenaAllocator arena_allocator; - HashMap hash_map; + HashMapType(BufferView, int) hash_map; int value; bool has_key; unsigned char i; @@ -175,8 +175,10 @@ static void test_load_error(const char *filepath, const char *expected_error) { options.error_callback = error_callback_assert; expected_data.filepath = get_full_path(filepath); - expected_data.expected_error = join_str(expected_data.filepath, expected_error, ':'); - expected_data.got_expected_error = bool_false; + if(expected_error) { + expected_data.expected_error = join_str(expected_data.filepath, expected_error, ':'); + expected_data.got_expected_error = bool_false; + } options.error_callback_userdata = &expected_data; if(amal_program_init(&program) != 0) { @@ -184,12 +186,12 @@ static void test_load_error(const char *filepath, const char *expected_error) { FAIL_TEST(expected_data.filepath); } if(amal_compiler_load_file(&options, &program, filepath) == AMAL_COMPILER_OK) { - fprintf(stderr, "Expected to fail loading file\n"); + fprintf(stderr, "Successfully loaded file when it was expected to fail\n"); FAIL_TEST(expected_data.filepath); } amal_program_deinit(&program); - if(!expected_data.got_expected_error) { + if(expected_error && !expected_data.got_expected_error) { fprintf(stderr, "Didn't get expected error message:\n%s\n", expected_error); FAIL_TEST(expected_data.filepath); } @@ -197,7 +199,8 @@ static void test_load_error(const char *filepath, const char *expected_error) { fprintf(stderr, "Test failed as expected: %s\n", expected_data.filepath); ++num_successful_tests; free(expected_data.filepath); - free(expected_data.expected_error); + if(expected_error) + free(expected_data.expected_error); } static void run_all_tests() { @@ -247,6 +250,7 @@ static void run_all_tests() { "1:15: error: A variable can't be declared without a type or assignment\n" " extern const a;\n" " ^\n"); + test_load_error("tests/errors/no_main_func.amal", NULL); } /* TODO: Restrict variables in global scope to const */ -- cgit v1.2.3