]> www.git.momoyon.org Git - lang.git/commitdiff
Implement testing system.
authorahmedsamyh <ahmedsamyh10@gmail.com>
Fri, 15 Nov 2024 16:11:42 +0000 (21:11 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Fri, 15 Nov 2024 16:11:42 +0000 (21:11 +0500)
test.sh [new file with mode: 0755]
tests/01-unterminated-string.momo [new file with mode: 0644]
tests/01-unterminated-string.momo.test [new file with mode: 0644]

diff --git a/test.sh b/test.sh
new file mode 100755 (executable)
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 (file)
index 0000000..362fd01
--- /dev/null
@@ -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 (file)
index 0000000..4259fc6
--- /dev/null
@@ -0,0 +1 @@
+'[ERROR] tests/01-unterminated-string.momo:1:21: Unterminated string!'