From: ahmedsamyh Date: Sat, 16 Nov 2024 12:29:00 +0000 (+0500) Subject: [Testing] test.py go over every .momo file in ./tests. X-Git-Url: https://www.git.momoyon.org/?a=commitdiff_plain;h=c4ee459a7a3d8fae1bcea22367af758801ce1717;p=lang.git [Testing] test.py go over every .momo file in ./tests. - [New test] 02-string.momo --- diff --git a/main.momo b/main.momo index c31fe03..4cafbe0 100644 --- a/main.momo +++ b/main.momo @@ -1,5 +1 @@ - - - - "This is a long ass string" diff --git a/test.py b/test.py index ef8d0ba..b5c67f8 100644 --- 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 index 0000000..4cafbe0 --- /dev/null +++ b/tests/02-string.momo @@ -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 index 0000000..1bfd269 --- /dev/null +++ b/tests/02-string.momo.test @@ -0,0 +1 @@ +Token (2, 'This is a long ass string', ./tests/02-string.momo:1:0)