diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-18 06:37:58 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | d4d33a89586b5210d1f0bc81d95fa2b640da659b (patch) | |
tree | 1502737b7a9e34493665ce88b66c2e0d80d31118 /tests | |
parent | 04b7ba96dbabea540f96ba7f72a220f067e9aaf8 (diff) |
Cleanup on test failure
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/tests/main.c b/tests/main.c index 05725f7..3573f9c 100644 --- a/tests/main.c +++ b/tests/main.c @@ -48,6 +48,7 @@ static CHECK_RESULT int test_hash_map() { } #define FAIL_TEST(name) do { fprintf(stderr, "Test failed: %s\n", (name)); return; } while(0) +#define FAIL_TEST_CLEANUP(name) do { fprintf(stderr, "Test failed: %s\n", (name)); goto cleanup; } while(0) typedef struct { char *filepath; @@ -159,28 +160,30 @@ static void test_load(const char *filepath) { if(amal_program_add_extern_func(&program, create_buffer_view("print_extern", 12), print_extern, 0) != 0) { fprintf(stderr, "Unexpected error (alloc failure)\n"); - FAIL_TEST(full_path); + FAIL_TEST_CLEANUP(full_path); } if(amal_program_add_extern_func(&program, create_buffer_view("print_extern_num", 16), print_extern_num, sizeof(i64)) != 0) { fprintf(stderr, "Unexpected error (alloc failure)\n"); - FAIL_TEST(full_path); + FAIL_TEST_CLEANUP(full_path); } result = amal_compiler_load_file(&options, &program, filepath); if(result != AMAL_COMPILER_OK) { fprintf(stderr, "Failed to load file %s, result: %d\n", full_path, result); - FAIL_TEST(full_path); + FAIL_TEST_CLEANUP(full_path); } result = amal_program_run(&program); if(result != 0) { fprintf(stderr, "Failed to run the program %s, result: %d\n", full_path, result); - FAIL_TEST(full_path); + FAIL_TEST_CLEANUP(full_path); } - amal_program_deinit(&program); fprintf(stderr, "Test succeeded as expected: %s\n", full_path); ++num_successful_tests; + + cleanup: + amal_program_deinit(&program); free(full_path); } @@ -203,21 +206,23 @@ static void test_load_error(const char *filepath, const char *expected_error) { if(amal_program_init(&program) != 0) { fprintf(stderr, "Failed to initialize amal program\n"); - FAIL_TEST(expected_data.filepath); + FAIL_TEST_CLEANUP(expected_data.filepath); } if(amal_compiler_load_file(&options, &program, filepath) == AMAL_COMPILER_OK) { fprintf(stderr, "Successfully loaded file when it was expected to fail\n"); - FAIL_TEST(expected_data.filepath); + FAIL_TEST_CLEANUP(expected_data.filepath); } - amal_program_deinit(&program); 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); + FAIL_TEST_CLEANUP(expected_data.filepath); } fprintf(stderr, "Test failed as expected: %s\n", expected_data.filepath); ++num_successful_tests; + + cleanup: + amal_program_deinit(&program); free(expected_data.filepath); if(expected_error) free(expected_data.expected_error); |