]> www.git.momoyon.org Git - lang.git/commitdiff
[Testing] test.py go over every .momo file in ./tests.
authorahmedsamyh <ahmedsamyh10@gmail.com>
Sat, 16 Nov 2024 12:29:00 +0000 (17:29 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Sat, 16 Nov 2024 12:29:00 +0000 (17:29 +0500)
- [New test] 02-string.momo

main.momo
test.py
tests/02-string.momo [new file with mode: 0644]
tests/02-string.momo.test [new file with mode: 0644]

index c31fe036451f7d9da5b0bba248f6bd16a54e5f12..4cafbe06fca943f2d0be1239a60c5110ad16605d 100644 (file)
--- a/main.momo
+++ b/main.momo
@@ -1,5 +1 @@
-
-
-
-
 "This is a long ass string"
diff --git a/test.py b/test.py
index ef8d0ba4fcd664e0af6eff487c0fe84bc5c88d8e..b5c67f883f74e40ee591f7834f0e768207902171 100644 (file)
--- a/test.py
+++ b/test.py
@@ -2,7 +2,8 @@ import os
 import sys
 import subprocess
 
-TEST_DIR = "./tests/"
+MOMO_FILE_SUFFIX = ".momo"
+TESTS_DIR = "./tests/"
 TEST_FILE_SUFFIX = ".test"
 
 def error(msg: str):
@@ -30,7 +31,7 @@ def test_source_file(filename: str):
 
     testfilename: str = filename + TEST_FILE_SUFFIX
     if not os.path.exists(testfilename):
-        error("Test file {testfilename} doesn't exist!")
+        error(f"Test file {testfilename} doesn't exist!")
         ans = input("Create test file with current output? [y/N]")
         if ans.lower() == "y" or ans.lower() == "yes":
             output = cmd(["python", "./main.py", filename]).stdout
@@ -47,10 +48,11 @@ def test_source_file(filename: str):
     expected_output = f.read()
     f.close()
 
+    print(f"INFO: Testing file '{filename}'...", end='')
     if output != expected_output:
         print("Failed!")
-        print(f"Expected: `{expected_output}`")
-        print(f"Got:      `{output}`")
+        print(f"Expected: `{repr(expected_output)}`")
+        print(f"Got:      `{repr(output)}`")
         ans = input("\nUpdate output? [y/N]")
         if ans.lower() == "y" or ans.lower() == "yes":
             info(f"Updating test file {testfilename}")
@@ -60,8 +62,11 @@ def test_source_file(filename: str):
         print("Success!")
 
 def main():
-    test_source_file("./tests/01-unterminated-string.momo")
 
+    for (dirpath, dirs, files) in os.walk(TESTS_DIR):
+        for f in files:
+            if f.endswith(MOMO_FILE_SUFFIX):
+                test_source_file(TESTS_DIR + f)
 
 if __name__ == '__main__':
     main()
diff --git a/tests/02-string.momo b/tests/02-string.momo
new file mode 100644 (file)
index 0000000..4cafbe0
--- /dev/null
@@ -0,0 +1 @@
+"This is a long ass string"
diff --git a/tests/02-string.momo.test b/tests/02-string.momo.test
new file mode 100644 (file)
index 0000000..1bfd269
--- /dev/null
@@ -0,0 +1 @@
+Token (2, 'This is a long ass string', ./tests/02-string.momo:1:0)