aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/main.c23
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);