From 121b389a30648f5a92293c74a182615c7b2abc4e Mon Sep 17 00:00:00 2001 From: ahmedsamyh Date: Fri, 15 Nov 2024 21:11:42 +0500 Subject: [PATCH] Implement testing system. --- test.sh | 41 ++++++++++++++++++++++++++ tests/01-unterminated-string.momo | 1 + tests/01-unterminated-string.momo.test | 1 + 3 files changed, 43 insertions(+) create mode 100755 test.sh create mode 100644 tests/01-unterminated-string.momo create mode 100644 tests/01-unterminated-string.momo.test diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..afdde63 --- /dev/null +++ b/test.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +TESTS_DIR=./tests/ + +test_file_exists() { + filename=$1 + testfilename=$filename.test + + # TODO: Maybe create the test file with the current output + if [ ! -f "$testfilename" ]; then + echo "ERROR: test file \"$testfilename\" doesn't exist!" + exit 1 + fi +} + +test_source_file() { + filename=$1 + + if [ ! -f "$filename" ]; then + echo "ERROR: File \"$filename\" doesn't exist!" + exit 1 + fi + + test_file_exists $filename + + printf "INFO: Testing file \"$filename\"... " + + output=$(python3 main.py $filename) + expected_output=$(cat $filename.test) + if [ "$output" != "$expected_output" ]; then + echo "Failed!" + echo "Expected: \`$expected_output\`" + echo "Got: \`$output\`" + else + echo "Success!" + fi +} + +# set -xe + +test_source_file tests/01-unterminated-string.momo diff --git a/tests/01-unterminated-string.momo b/tests/01-unterminated-string.momo new file mode 100644 index 0000000..362fd01 --- /dev/null +++ b/tests/01-unterminated-string.momo @@ -0,0 +1 @@ +"Unterminated string diff --git a/tests/01-unterminated-string.momo.test b/tests/01-unterminated-string.momo.test new file mode 100644 index 0000000..4259fc6 --- /dev/null +++ b/tests/01-unterminated-string.momo.test @@ -0,0 +1 @@ +'[ERROR] tests/01-unterminated-string.momo:1:21: Unterminated string!' -- 2.39.5