From 1f28c3c733ea3ae4234bff91e1c55e61b1ee3e96 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 31 Jul 2019 01:25:05 +0200 Subject: Starting on asm, implementing extern function call so progress is visible --- tests/main.c | 84 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 27 deletions(-) (limited to 'tests/main.c') diff --git a/tests/main.c b/tests/main.c index 1394860..5b8bad0 100644 --- a/tests/main.c +++ b/tests/main.c @@ -20,14 +20,14 @@ static int num_tests_run = 0; }while(0) static CHECK_RESULT int test_hash_map() { - ScopedAllocator scoped_allocator; + ArenaAllocator arena_allocator; HashMap hash_map; int value; bool has_key; unsigned char i; - return_if_error(scoped_allocator_init(&scoped_allocator)); - cleanup_if_error(hash_map_init(&hash_map, &scoped_allocator, sizeof(int), hash_map_compare_string, amal_hash_string)); + return_if_error(arena_allocator_init(&arena_allocator)); + cleanup_if_error(hash_map_init(&hash_map, &arena_allocator, sizeof(int), hash_map_compare_string, amal_hash_string)); value = 34; return_if_error(hash_map_insert(&hash_map, create_buffer_view("hello", 5), &value)); @@ -43,7 +43,7 @@ static CHECK_RESULT int test_hash_map() { REQUIRE_EQ_INT(34, value); cleanup: - scoped_allocator_deinit(&scoped_allocator); + arena_allocator_deinit(&arena_allocator); return 0; } @@ -200,6 +200,55 @@ static void test_load_error(const char *filepath, const char *expected_error) { free(expected_data.expected_error); } +static void run_all_tests() { + test_load("tests/main.amal"); + test_load("tests/utf8bom.amal"); + test_load("tests/bytecode.amal"); + + test_load_error("tests/errors/duplicate_declaration.amal", + "2:7: error: Variable with the name main was declared twice in the same scope\n" + "const main = fn {}\n" + " ^\n"); + test_load_error("tests/errors/pub_in_closure.amal", + "2:5: error: Only declarations in global structs can be public\n" + " pub const num = 45;\n" + " ^\n"); + test_load_error("tests/errors/closure_no_lhs.amal", + "1:1: error: Expected string, variable, closure, struct, function call or import\n" + "fn {}\n" + "^\n"); + test_load_error("tests/errors/const_assign.amal", + "3:5: error: Can't assign to a const value\n" + " value = 34;\n" + " ^\n"); + test_load_error("tests/errors/arithmetic_incompatible_types.amal", + "4:28: error: Can't cast type \"str\" to type \"i64\"\n" + " const value3 = value + value2;\n" + " ^\n" + "4:20: error: Left-hand side is of type i64\n" + " const value3 = value + value2;\n" + " ^\n" + "4:28: error: Right-hand side is of type str\n" + " const value3 = value + value2;\n" + " ^\n"); + test_load_error("tests/errors/non_arithmetic_type_arithmetic.amal", + "3:20: error: Arithmetic operation can only be performed with the types i8, u8, i16, u16, i32, u32, i64, u64, isize and usize\n" + " const value2 = value + value;\n" + " ^\n"); + test_load_error("tests/errors/empty_body_regular_func.amal", + "1:15: error: Expected function declaration. Only extern functions can have empty declarations.\n" + " const func: fn;\n" + " ^\n"); + test_load_error("tests/errors/declaration_no_type.amal", + "1:8: error: A variable can't be declared without a type or assignment\n" + " const a;\n" + " ^\n"); + test_load_error("tests/errors/declaration_no_type_extern.amal", + "1:15: error: A variable can't be declared without a type or assignment\n" + " extern const a;\n" + " ^\n"); +} + /* TODO: Restrict variables in global scope to const */ int main(int argc, char **argv) { int result; @@ -212,34 +261,14 @@ int main(int argc, char **argv) { exit(1); } + /* Sanity check */ return_if_error(test_hash_map()); /* Run all tests */ if(argc == 1) { - test_load("tests/main.amal"); - test_load("tests/utf8bom.amal"); - test_load("tests/bytecode.amal"); - - test_load_error("tests/errors/duplicate_declaration.amal", - "2:7: error: Variable with the name main was declared twice in the same scope\n" - "const main = fn {}\n" - " ^\n"); - test_load_error("tests/errors/pub_in_closure.amal", - "2:5: error: Only declarations in global structs can be public\n" - " pub const num = 45;\n" - " ^\n"); - test_load_error("tests/errors/closure_no_lhs.amal", - "1:1: error: Expected string, variable, closure, struct, function call or import\n" - "fn {}\n" - "^\n"); - test_load_error("tests/errors/const_assign.amal", - "3:5: error: Can't assign to a const value\n" - " value = 34;\n" - " ^\n"); - fprintf(stderr, "##### %d/%d tests succeeded #####\n", num_successful_tests, num_tests_run); + run_all_tests(); } else if(argc == 2) { test_load(argv[1]); - fprintf(stderr, "##### %d/%d tests succeeded #####\n", num_successful_tests, num_tests_run); } else { fprintf(stderr, "usage: test [test-file-path]\n"); fprintf(stderr, "If you run test without any files then all tests will run.\n"); @@ -249,5 +278,6 @@ int main(int argc, char **argv) { exit(1); } + fprintf(stderr, "##### %d/%d tests succeeded #####\n", num_successful_tests, num_tests_run); return 0; -} \ No newline at end of file +} -- cgit v1.2.3