From dda1ab3a56ae4521c7b5f287e0d15556b408d5cd Mon Sep 17 00:00:00 2001 From: David Gonzalez Martin Date: Sun, 17 Dec 2023 19:42:18 +0100 Subject: [PATCH] Divide tests between standalone and integral --- ci.sh | 56 +++++++++++++++++-- test/integral/first/build.nat | 27 +++++++++ test/integral/first/src/main.nat | 3 + test/{ => standalone}/add_sub/main.nat | 0 test/{ => standalone}/and/main.nat | 0 test/{ => standalone}/div/main.nat | 0 test/{ => standalone}/first/main.nat | 0 test/{ => standalone}/foreach/main.nat | 0 test/{ => standalone}/fork/main.nat | 0 test/{ => standalone}/fork_exec/main.nat | 0 test/{ => standalone}/hello_world/main.nat | 0 test/{ => standalone}/imul/main.nat | 0 test/{ => standalone}/loop_break/main.nat | 0 test/{ => standalone}/or/main.nat | 0 test/{ => standalone}/self_exe_path/main.nat | 0 test/{ => standalone}/shifts/main.nat | 0 test/{ => standalone}/simple_bool/main.nat | 0 test/{ => standalone}/stack/main.nat | 0 test/{ => standalone}/virtual_memory/main.nat | 0 test/{ => standalone}/xor/main.nat | 0 20 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 test/integral/first/build.nat create mode 100644 test/integral/first/src/main.nat rename test/{ => standalone}/add_sub/main.nat (100%) rename test/{ => standalone}/and/main.nat (100%) rename test/{ => standalone}/div/main.nat (100%) rename test/{ => standalone}/first/main.nat (100%) rename test/{ => standalone}/foreach/main.nat (100%) rename test/{ => standalone}/fork/main.nat (100%) rename test/{ => standalone}/fork_exec/main.nat (100%) rename test/{ => standalone}/hello_world/main.nat (100%) rename test/{ => standalone}/imul/main.nat (100%) rename test/{ => standalone}/loop_break/main.nat (100%) rename test/{ => standalone}/or/main.nat (100%) rename test/{ => standalone}/self_exe_path/main.nat (100%) rename test/{ => standalone}/shifts/main.nat (100%) rename test/{ => standalone}/simple_bool/main.nat (100%) rename test/{ => standalone}/stack/main.nat (100%) rename test/{ => standalone}/virtual_memory/main.nat (100%) rename test/{ => standalone}/xor/main.nat (100%) diff --git a/ci.sh b/ci.sh index 8d7f7a7..e02347f 100755 --- a/ci.sh +++ b/ci.sh @@ -6,24 +6,67 @@ zig build -Duse_llvm=$nativity_use_llvm failed_test_count=0 passed_test_count=0 test_directory_name=test -test_directory=$test_directory_name/* -total_test_count=$(ls 2>/dev/null -Ubad1 -- test/* | wc -l) +standalone_test_directory=$test_directory_name/standalone +standalone_test_directory_files=$standalone_test_directory/* +integral_test_directory=$test_directory_name/integral +integral_test_directory_files=$integral_test_directory/* +standalone_test_count=$(ls 2>/dev/null -Ubad1 -- $standalone_test_directory/* | wc -l) +integral_test_count=$(ls 2>/dev/null -Ubad1 -- $integral_test_directory/* | wc -l) +total_test_count=$(($standalone_test_count + $integral_test_count)) + ran_test_count=0 test_i=1 passed_compilation_count=0 failed_compilation_count=0 failed_compilations=() failed_tests=() +my_current_directory=$(pwd) +nat_compiler=$my_current_directory/zig-out/bin/nat -for dir in $test_directory +for standalone_test_case in $standalone_test_directory_files do - MY_TESTNAME=${dir##*/} - zig build run -Duse_llvm=$nativity_use_llvm -- $dir/main.nat + STANDALONE_TEST_NAME=${standalone_test_case##*/} + $nat_compiler $standalone_test_case/main.nat if [[ "$?" == "0" ]]; then passed_compilation_count=$(($passed_compilation_count + 1)) if [[ "$OSTYPE" == "linux-gnu"* ]]; then - nat/$MY_TESTNAME + nat/$STANDALONE_TEST_NAME + + if [[ "$?" == "0" ]]; then + passed_test_count=$(($passed_test_count + 1)) + result="\e[32mPASSED\e[0m" + else + failed_test_count=$(($failed_test_count + 1)) + result="\e[31mFAILED\e[0m" + failed_tests+=("$test_i. $STANDALONE_TEST_NAME") + fi + + ran_test_count=$(($ran_test_count + 1)) + else + result="\e[31mOS NOT SUPPORTED\e[0m" + fi + else + failed_compilation_count=$(($failed_compilation_count + 1)) + result="\e[31mCOMPILATION FAILURE\e[0m" + failed_compilations+=("$test_i. $STANDALONE_TEST_NAME") + fi + + echo -e "[$test_i/$total_test_count] [$result] $STANDALONE_TEST_NAME" + + test_i=$(($test_i + 1)) +done + +for integral_test_case in $integral_test_directory_files +do + MY_TESTNAME=${integral_test_case##*/} + cd test/integral/$MY_TESTNAME + $nat_compiler + + if [[ "$?" == "0" ]]; then + passed_compilation_count=$(($passed_compilation_count + 1)) + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + nat/src if [[ "$?" == "0" ]]; then passed_test_count=$(($passed_test_count + 1)) @@ -47,6 +90,7 @@ do echo -e "[$test_i/$total_test_count] [$result] $MY_TESTNAME" test_i=$(($test_i + 1)) + cd $my_current_directory done printf "\n" diff --git a/test/integral/first/build.nat b/test/integral/first/build.nat new file mode 100644 index 0000000..6b66fba --- /dev/null +++ b/test/integral/first/build.nat @@ -0,0 +1,27 @@ +const std = #import("std"); +const assert = std.assert; +const Executable = std.build.Executable; + +const main = fn () s32 { + const argument_count = std.start.argument_count; + const argument_values = std.start.argument_values; + assert(ok = argument_count == 3); + + const executable = Executable{ + .target = .{ + .cpu = .x86_64, + .os = .linux, + .abi = .gnu, + }, + .main_source_path = "src/main.nat", + }; + + const compiler_path = argument_values[2]; + + if (executable.compile(compiler_path)) { + return 0; + } else { + std.print(bytes = "Executable failed to compile!\n"); + return 1; + } +} diff --git a/test/integral/first/src/main.nat b/test/integral/first/src/main.nat new file mode 100644 index 0000000..48de37a --- /dev/null +++ b/test/integral/first/src/main.nat @@ -0,0 +1,3 @@ +const main = fn () s32 { + return 0; +} diff --git a/test/add_sub/main.nat b/test/standalone/add_sub/main.nat similarity index 100% rename from test/add_sub/main.nat rename to test/standalone/add_sub/main.nat diff --git a/test/and/main.nat b/test/standalone/and/main.nat similarity index 100% rename from test/and/main.nat rename to test/standalone/and/main.nat diff --git a/test/div/main.nat b/test/standalone/div/main.nat similarity index 100% rename from test/div/main.nat rename to test/standalone/div/main.nat diff --git a/test/first/main.nat b/test/standalone/first/main.nat similarity index 100% rename from test/first/main.nat rename to test/standalone/first/main.nat diff --git a/test/foreach/main.nat b/test/standalone/foreach/main.nat similarity index 100% rename from test/foreach/main.nat rename to test/standalone/foreach/main.nat diff --git a/test/fork/main.nat b/test/standalone/fork/main.nat similarity index 100% rename from test/fork/main.nat rename to test/standalone/fork/main.nat diff --git a/test/fork_exec/main.nat b/test/standalone/fork_exec/main.nat similarity index 100% rename from test/fork_exec/main.nat rename to test/standalone/fork_exec/main.nat diff --git a/test/hello_world/main.nat b/test/standalone/hello_world/main.nat similarity index 100% rename from test/hello_world/main.nat rename to test/standalone/hello_world/main.nat diff --git a/test/imul/main.nat b/test/standalone/imul/main.nat similarity index 100% rename from test/imul/main.nat rename to test/standalone/imul/main.nat diff --git a/test/loop_break/main.nat b/test/standalone/loop_break/main.nat similarity index 100% rename from test/loop_break/main.nat rename to test/standalone/loop_break/main.nat diff --git a/test/or/main.nat b/test/standalone/or/main.nat similarity index 100% rename from test/or/main.nat rename to test/standalone/or/main.nat diff --git a/test/self_exe_path/main.nat b/test/standalone/self_exe_path/main.nat similarity index 100% rename from test/self_exe_path/main.nat rename to test/standalone/self_exe_path/main.nat diff --git a/test/shifts/main.nat b/test/standalone/shifts/main.nat similarity index 100% rename from test/shifts/main.nat rename to test/standalone/shifts/main.nat diff --git a/test/simple_bool/main.nat b/test/standalone/simple_bool/main.nat similarity index 100% rename from test/simple_bool/main.nat rename to test/standalone/simple_bool/main.nat diff --git a/test/stack/main.nat b/test/standalone/stack/main.nat similarity index 100% rename from test/stack/main.nat rename to test/standalone/stack/main.nat diff --git a/test/virtual_memory/main.nat b/test/standalone/virtual_memory/main.nat similarity index 100% rename from test/virtual_memory/main.nat rename to test/standalone/virtual_memory/main.nat diff --git a/test/xor/main.nat b/test/standalone/xor/main.nat similarity index 100% rename from test/xor/main.nat rename to test/standalone/xor/main.nat