Skip to content

Commit

Permalink
Merge pull request #33 from birth-software/integral-tests
Browse files Browse the repository at this point in the history
Divide tests between standalone and integral
  • Loading branch information
david4r4 authored Dec 17, 2023
2 parents 3d271de + dda1ab3 commit 4dc6bea
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 6 deletions.
56 changes: 50 additions & 6 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 standalone_test_case in $standalone_test_directory_files
do
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/$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 dir in $test_directory
for integral_test_case in $integral_test_directory_files
do
MY_TESTNAME=${dir##*/}
zig build run -Duse_llvm=$nativity_use_llvm -- $dir/main.nat
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/$MY_TESTNAME
nat/src

if [[ "$?" == "0" ]]; then
passed_test_count=$(($passed_test_count + 1))
Expand All @@ -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"
Expand Down
27 changes: 27 additions & 0 deletions test/integral/first/build.nat
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 3 additions & 0 deletions test/integral/first/src/main.nat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const main = fn () s32 {
return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4dc6bea

Please sign in to comment.