From f529a806363fdbb354267cc6ccf44e75a8bbf85c Mon Sep 17 00:00:00 2001 From: joshuawills Date: Thu, 4 Jan 2024 13:03:21 +1100 Subject: [PATCH 1/3] adding testing script and environment --- out | Bin 0 -> 4664 bytes out.asm | 12 +++++ out.o | Bin 0 -> 576 bytes run-tests.sh | 121 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_one.hy | 17 +++++++ tests/test_three.hy | 13 +++++ tests/test_two.hy | 2 + 7 files changed, 165 insertions(+) create mode 100755 out create mode 100644 out.asm create mode 100644 out.o create mode 100755 run-tests.sh create mode 100644 tests/test_one.hy create mode 100644 tests/test_three.hy create mode 100644 tests/test_two.hy diff --git a/out b/out new file mode 100755 index 0000000000000000000000000000000000000000..e403f8d614df143c9615470113cb8ee2e8e61238 GIT binary patch literal 4664 zcmeI0KTg9i6vn@V1i?bXfP{ddTp%+8LRrehzzr-%jl@!rY9qnK6*x-AY@DG->BdI= zocBtJQmJBo9{lO*&maK`!q=)BgGwJR8%q5&A@jd9YBQ}q+!mH#op|<6jtKs zbip-I@IG`#PBqz=&jafP`$RW=oL5l-NJfjWMqH=Mg}_u1P><4z~F#jLfH-stPD&@qU13_c7ZS(n)U{$Bc#y81K(7s$UUJ4k`>66$G-d`QidpVFFYo3y=oc!vW<>Kxs*+IFt*g44{UhyBFR5 z9Uy^#9X3ERo}U#=?*|#e&k7=eK(8dVqJ%-OIHS0vs3b87$g0eR&=5XE6+seY4GY7^ h|JW2VV~KH2ph5vG;tctvC3=a)xeW2eC5c5P3;=Hw98v%P literal 0 HcmV?d00001 diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..7c4c8d1 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +help() { + echo "How to use test suite:" + echo "\tCreate a file with the format test_[a-z]+.hy in the tests directory" + echo "\tMake the first line a comment with the expected exit code: E.g. // exit 1" + echo "\tIf there's any stdout you want to test, create a file with the same name but with .txt instead of .hy" + echo "\tThe script will then do a diff compare to make sure it's the same" + echo "\tNo need to provide the .txt file if there's no output to test" + echo +} + + +## Variables +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RESET='\033[0m' +PASS=0 +FAIL=0 +TOTAL=0 + +# Helpful details for shell script +if [ "$#" -ne "0" ] +then + if [ "$1" = "--help" ] || [ "$1" = "-h" ] + then + help + fi +fi + + +for file in tests/* +do + file=$(basename $file) + + # Ignoring any other random files that aren't .txt or .hy + if ! (echo $file | grep -Eq "test_[a-z]+\.(hy|txt)$") + then + echo "Skipping over ${YELLOW}${file}${RESET}: invalid filename" + continue + fi + + # If it's not a .hy file, ignore + if ! echo $file | grep -Eq "\.hy$" + then + continue + fi + + + EXIT_CODE=$(head -n1 tests/"$file" | grep -Eo "[0-9]+$") + if [ "$EXIT_CODE" = "" ] + then + echo "Skipping over ${YELLOW}${file}${RESET}: please provide exit code in first line" + continue + fi + + # Attempt to build the executable + ./build/hydro tests/"$file" >> /dev/null >&2 + + # Build failed + if [ "$?" -ne "0" ] + then + echo "${RED}Build error${RESET} for ${YELLOW}${file}${RESET}, counting as fail" + FAIL=$((FAIL + 1)) + TOTAL=$((TOTAL + 1)) + continue + fi + + # Now execute commands and compare to the test_one.txt file + rootName=$(echo "$file" | grep -Eo "^test_[a-z]+") + if [ -f "tests/${rootName}.txt" ] + then + # Also need to compare stdout + ./out > "tests/current_output" + if [ "$EXIT_CODE" -ne "$?" ] + then + echo "${RED}Fail${RESET} for ${YELLOW}${file}${RESET}, differing exit codes" + FAIL=$((FAIL + 1)) + else + + if diff "tests/current_output" "tests/${rootName}.txt" > /dev/null + then + # They are identical + echo "${GREEN}Pass${RESET} for ${YELLOW}${file}${RESET}, same exit code and stdout" + PASS=$((PASS + 1)) + else + # They aren't identical + echo "${RED}Fail${RESET} for ${YELLOW}${file}${RESET}, differing stdout, same exit code" + FAIL=$((FAIL + 1)) + fi + TOTAL=$((TOTAL + 1)) + fi + + else + # Don't bother comparing stdout + ./out + if [ "$EXIT_CODE" -eq "$?" ] + then + echo "${GREEN}Pass${RESET} for ${YELLOW}${file}${RESET}, same exit code" + PASS=$((PASS + 1)) + else + echo "${RED}Fail${RESET} for ${YELLOW}${file}${RESET}, differing exit codes" + FAIL=$((FAIL + 1)) + fi + TOTAL=$((TOTAL + 1)) + fi + +done + +if [ -f "tests/current_output" ] +then + rm tests/current_output +fi + +echo +echo "Test suite completed: " +echo "\t${GREEN}${PASS} passed${RESET}" +echo "\t${RED}${FAIL} failed${RESET}" +echo "\t${TOTAL} total" + diff --git a/tests/test_one.hy b/tests/test_one.hy new file mode 100644 index 0000000..f32bd05 --- /dev/null +++ b/tests/test_one.hy @@ -0,0 +1,17 @@ +// expected exit: 5 +let y = (10 - 2 * 3); +let x = 7; // first +// first +if (0) { + x = 1; +} elif (0) { + x = 2; +} else { + x = 5; +} + +exit(x); + +/* +exit(4); +*/ diff --git a/tests/test_three.hy b/tests/test_three.hy new file mode 100644 index 0000000..4883989 --- /dev/null +++ b/tests/test_three.hy @@ -0,0 +1,13 @@ +// 0 + +let y = 5; +let x = 0; + +if (x) { + x = x + 1; +} else { + y = 0; +} + + +exit(y); \ No newline at end of file diff --git a/tests/test_two.hy b/tests/test_two.hy new file mode 100644 index 0000000..5523576 --- /dev/null +++ b/tests/test_two.hy @@ -0,0 +1,2 @@ +// 1 +exit(1); \ No newline at end of file From 5f616bfff170524517a2b23567ce453950acf493 Mon Sep 17 00:00:00 2001 From: joshuawills Date: Fri, 5 Jan 2024 00:14:02 +1100 Subject: [PATCH 2/3] removing unnecessary files --- out | Bin 4664 -> 0 bytes out.asm | 12 ------------ out.o | Bin 576 -> 0 bytes 3 files changed, 12 deletions(-) delete mode 100755 out delete mode 100644 out.asm delete mode 100644 out.o diff --git a/out b/out deleted file mode 100755 index e403f8d614df143c9615470113cb8ee2e8e61238..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4664 zcmeI0KTg9i6vn@V1i?bXfP{ddTp%+8LRrehzzr-%jl@!rY9qnK6*x-AY@DG->BdI= zocBtJQmJBo9{lO*&maK`!q=)BgGwJR8%q5&A@jd9YBQ}q+!mH#op|<6jtKs zbip-I@IG`#PBqz=&jafP`$RW=oL5l-NJfjWMqH=Mg}_u1P><4z~F#jLfH-stPD&@qU13_c7ZS(n)U{$Bc#y81K(7s$UUJ4k`>66$G-d`QidpVFFYo3y=oc!vW<>Kxs*+IFt*g44{UhyBFR5 z9Uy^#9X3ERo}U#=?*|#e&k7=eK(8dVqJ%-OIHS0vs3b87$g0eR&=5XE6+seY4GY7^ h|JW2VV~KH2ph5vG;tctvC3=a)xeW2eC5c5P3;=Hw98v%P From b70cd9a4357d549f3e53d61befbc8d7ec65dc2e5 Mon Sep 17 00:00:00 2001 From: joshuawills Date: Fri, 5 Jan 2024 00:16:50 +1100 Subject: [PATCH 3/3] adding rms at the end --- run-tests.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index 7c4c8d1..d677621 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -113,6 +113,21 @@ then rm tests/current_output fi +if [ -f "out" ] +then + rm out +fi + +if [ -f "out.asm" ] +then + rm "out.asm" +fi + +if [ -f "out.o" ] +then + rm "out.o" +fi + echo echo "Test suite completed: " echo "\t${GREEN}${PASS} passed${RESET}"