]> www.git.momoyon.org Git - lang.git/commitdiff
[testing] Make testing functional...
authorahmedsamyh <ahmedsamyh10@gmail.com>
Mon, 3 Mar 2025 12:37:11 +0000 (17:37 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Mon, 3 Mar 2025 12:37:11 +0000 (17:37 +0500)
- Can record compilation behaviour.

38 files changed:
test.py [changed mode: 0644->0755]
tests/01-unterminated-string.momo [deleted file]
tests/01-unterminated-string.momo.test [deleted file]
tests/02-string.momo [deleted file]
tests/02-string.momo.test [deleted file]
tests/03-whitespaced-string.momo [deleted file]
tests/03-whitespaced-string.momo.test [deleted file]
tests/04-identifier.momo [deleted file]
tests/04-identifier.momo.test [deleted file]
tests/05-multiple-identifiers.momo [deleted file]
tests/05-multiple-identifiers.momo.test [deleted file]
tests/06-symbols.momo [deleted file]
tests/06-symbols.momo.test [deleted file]
tests/07-numbers.momo [deleted file]
tests/07-numbers.momo.test [deleted file]
tests/08-floating-point-numbers.momo [deleted file]
tests/08-floating-point-numbers.momo.test [deleted file]
tests/identifiers.build.code.expected [new file with mode: 0644]
tests/identifiers.build.err.expected [new file with mode: 0644]
tests/identifiers.build.out.expected [new file with mode: 0644]
tests/identifiers.code.expected [new file with mode: 0644]
tests/identifiers.err.expected [new file with mode: 0644]
tests/identifiers.momo [new file with mode: 0644]
tests/identifiers.out.expected [new file with mode: 0644]
tests/operators.build.code.expected [new file with mode: 0644]
tests/operators.build.err.expected [new file with mode: 0644]
tests/operators.build.out.expected [new file with mode: 0644]
tests/operators.code.expected [new file with mode: 0644]
tests/operators.err.expected [new file with mode: 0644]
tests/operators.momo [new file with mode: 0644]
tests/operators.out.expected [new file with mode: 0644]
tests/strings.build.code.expected [new file with mode: 0644]
tests/strings.build.err.expected [new file with mode: 0644]
tests/strings.build.out.expected [new file with mode: 0644]
tests/strings.code.expected [new file with mode: 0644]
tests/strings.err.expected [new file with mode: 0644]
tests/strings.momo [new file with mode: 0644]
tests/strings.out.expected [new file with mode: 0644]

diff --git a/test.py b/test.py
old mode 100644 (file)
new mode 100755 (executable)
index 1c59608..87642fd
--- a/test.py
+++ b/test.py
@@ -13,6 +13,10 @@ class Test:
     expected_stderr = ''
     expected_returncode = -1
 
+    build_expected_stdout = ''
+    build_expected_stderr = ''
+    build_expected_returncode = -1
+
     def __init__(self, name):
         self.name = name
 
@@ -34,6 +38,14 @@ class Test:
         else:
             self.expected_returncode = int(self.expected_returncode)
 
+        self.build_expected_stdout = read_or_create_expected_file("build.out")
+        self.build_expected_stderr = read_or_create_expected_file("build.err")
+        self.build_expected_returncode = read_or_create_expected_file("build.code")
+        if self.build_expected_returncode == '':
+            self.build_expected_returncode = -1
+        else:
+            self.build_expected_returncode = int(self.build_expected_returncode)
+
         # if self.expected_stdout: print(f"{self.name}.out.expected: {self.expected_stdout}")
         # if self.expected_stderr: print(f"{self.name}.err.expected: {self.expected_stderr}")
     def save_expected(self):
@@ -46,6 +58,10 @@ class Test:
         write_expected("err", self.expected_stderr)
         write_expected("code", str(self.expected_returncode))
 
+        write_expected("build.out", self.build_expected_stdout)
+        write_expected("build.err", self.build_expected_stderr)
+        write_expected("build.code", str(self.build_expected_returncode))
+
 
 def usage(program: str):
     print(f"Usage: {program} <subcmd> [flags]")
@@ -54,10 +70,11 @@ def usage(program: str):
 def hhelp():
     print('''
     Subcommands:
-        help    - Prints this help message.
-        build   - Builds all the tests.
-        run     - Runs all the tests.
-        record  - Records the expected behaviour of all the tests.
+        help            - Prints this help message.
+        build           - Builds all the tests.
+        run             - Runs all the tests.
+        record          - Records the expected behaviour of all the tests.
+        record_build    - Records the expected build behaviour of all the tests.
 
     Flags:
         -h      - Same as the help subcommand.
@@ -140,11 +157,15 @@ def main():
                 current_test_id += 1
                 test = tests[test_name]
 
+                if test.build_expected_returncode == -1:
+                    print(f"[WARNING] Test doesn't have any expected build returncode!")
+                    print(f"[WARNING] Please record the expected build behaviour of the test using the 'record_build' subcommand!")
+                    print(f"[SKIPPING]...")
+                    continue
+
                 cmd = [COMPILER, f"{test_name}{SUFFIX}"]
                 vlog(verbose_output, f"[CMD] {cmd}")
-                res = subprocess.run(cmd,
-                                     capture_output = True,
-                                     text = True)
+                res = subprocess.run(cmd, capture_output = True, text = True)
                 if res.returncode != 0:
                     print("[FAILED] ", end='')
                     if res.stderr:
@@ -203,13 +224,16 @@ def main():
                 print(f"+ Recording expected behaviour for '{test_name}'...")
                 test = tests[test_name]
 
+                res = subprocess.run([f"./{test_name}"], capture_output = True, text = True)
+
+                print(f"stdout: {res.stdout}")
+                print(f"stderr: {res.stderr}")
+                print(f"returncode: {res.returncode}")
+
                 prompt_msg = "Record current behaviour as the expected one? [y/N]"
                 ans = input(prompt_msg)
 
                 if ans.lower() == "y":
-                    res = subprocess.run([f"./{test_name}"],
-                                         capture_output = True,
-                                         text = True)
                     tests[test_name].expected_stdout = res.stdout
                     tests[test_name].expected_stderr = res.stderr
                     tests[test_name].expected_returncode = res.returncode
@@ -217,6 +241,32 @@ def main():
                     print('[SUCCESS] Recorded expected behaviour')
                 else:
                     print('[SKIP]')
+        elif subcmd == "record_build":
+            print(f'----- [RECORD_BUILD] -----')
+            for test_name in tests:
+                print(f"+ Recording expected build behaviour for '{test_name}'...")
+                test = tests[test_name]
+
+                cmd = [COMPILER, f"{test_name}{SUFFIX}"]
+                vlog(verbose_output, f"[CMD] {cmd}")
+                res = subprocess.run(cmd, capture_output = True, text = True)
+
+                print(f"stdout: {res.stdout}")
+                print(f"stderr: {res.stderr}")
+                print(f"returncode: {res.returncode}")
+
+                prompt_msg = "Record current build behaviour as the expected one? [y/N]"
+                ans = input(prompt_msg)
+
+                if ans.lower() == "y":
+
+                    tests[test_name].build_expected_stdout = res.stdout
+                    tests[test_name].build_expected_stderr = res.stderr
+                    tests[test_name].build_expected_returncode = res.returncode
+                    tests[test_name].save_expected()
+                    print('[SUCCESS] Recorded expected behaviour')
+                else:
+                    print('[SKIP]')
 
         else:
             print(f"[ERROR] Invalid subcommand '{subcmd}'", file=sys.stderr)
diff --git a/tests/01-unterminated-string.momo b/tests/01-unterminated-string.momo
deleted file mode 100644 (file)
index 362fd01..0000000
+++ /dev/null
@@ -1 +0,0 @@
-"Unterminated string
diff --git a/tests/01-unterminated-string.momo.test b/tests/01-unterminated-string.momo.test
deleted file mode 100644 (file)
index 8fca335..0000000
+++ /dev/null
@@ -1 +0,0 @@
-[ERROR] ./tests/01-unterminated-string.momo:1:21: Unterminated string!
diff --git a/tests/02-string.momo b/tests/02-string.momo
deleted file mode 100644 (file)
index 4cafbe0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-"This is a long ass string"
diff --git a/tests/02-string.momo.test b/tests/02-string.momo.test
deleted file mode 100644 (file)
index 80e60a7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-"Token (String, 'This is a long ass string', ./tests/02-string.momo:1:0)"
diff --git a/tests/03-whitespaced-string.momo b/tests/03-whitespaced-string.momo
deleted file mode 100644 (file)
index c168e11..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-"This is a long ass string"
diff --git a/tests/03-whitespaced-string.momo.test b/tests/03-whitespaced-string.momo.test
deleted file mode 100644 (file)
index aecc6b6..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-("Token (String, 'This is a long ass string', "
- './tests/03-whitespaced-string.momo:3:0)')
diff --git a/tests/04-identifier.momo b/tests/04-identifier.momo
deleted file mode 100644 (file)
index 17dc7cc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-   foo
diff --git a/tests/04-identifier.momo.test b/tests/04-identifier.momo.test
deleted file mode 100644 (file)
index d6c9899..0000000
+++ /dev/null
@@ -1 +0,0 @@
-"Token (Ident, 'foo', ./tests/04-identifier.momo:1:4)"
diff --git a/tests/05-multiple-identifiers.momo b/tests/05-multiple-identifiers.momo
deleted file mode 100644 (file)
index 63afdaf..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-  foo
-bar baz
diff --git a/tests/05-multiple-identifiers.momo.test b/tests/05-multiple-identifiers.momo.test
deleted file mode 100644 (file)
index 8dbb042..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-"Token (Ident, 'foo', ./tests/05-multiple-identifiers.momo:1:3)"
-"Token (Ident, 'bar', ./tests/05-multiple-identifiers.momo:2:1)"
-"Token (Ident, 'baz', ./tests/05-multiple-identifiers.momo:2:5)"
diff --git a/tests/06-symbols.momo b/tests/06-symbols.momo
deleted file mode 100644 (file)
index e3c1f3c..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-() {} [] ->
-- + / * %
-= !
->= > < <= != ==
-, : ; .
-
-& | ~
-
-&& ||
-
diff --git a/tests/06-symbols.momo.test b/tests/06-symbols.momo.test
deleted file mode 100644 (file)
index 04e9eaf..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-"Token (Left Paren, '(', ./tests/06-symbols.momo:1:0)"
-"Token (Right Paren, ')', ./tests/06-symbols.momo:1:1)"
-"Token (Left Brace, '{', ./tests/06-symbols.momo:1:3)"
-"Token (Right Brace, '}', ./tests/06-symbols.momo:1:4)"
-"Token (Left Square Brace, '[', ./tests/06-symbols.momo:1:6)"
-"Token (Right Square Brace, ']', ./tests/06-symbols.momo:1:7)"
-"Token (Returner, '->', ./tests/06-symbols.momo:1:9)"
-"Token (Minus, '-', ./tests/06-symbols.momo:2:0)"
-"Token (Plus, '+', ./tests/06-symbols.momo:2:2)"
-"Token (Divide, '/', ./tests/06-symbols.momo:2:4)"
-"Token (Multiply, '*', ./tests/06-symbols.momo:2:6)"
-"Token (Modulus, '%', ./tests/06-symbols.momo:2:8)"
-"Token (Equal, '=', ./tests/06-symbols.momo:3:0)"
-"Token (Not, '!', ./tests/06-symbols.momo:3:2)"
-"Token (Greater Than or Equal, '>=', ./tests/06-symbols.momo:4:0)"
-"Token (Greater Than, '>', ./tests/06-symbols.momo:4:3)"
-"Token (Less Than, '<', ./tests/06-symbols.momo:4:5)"
-"Token (Less Than or Equal, '<=', ./tests/06-symbols.momo:4:7)"
-"Token (Not Equal, '!=', ./tests/06-symbols.momo:4:10)"
-"Token (Equal Equal, '==', ./tests/06-symbols.momo:4:13)"
-"Token (Comma, ',', ./tests/06-symbols.momo:5:0)"
-"Token (Colon, ':', ./tests/06-symbols.momo:5:2)"
-"Token (Semicolon, ';', ./tests/06-symbols.momo:5:4)"
-"Token (Dot, '.', ./tests/06-symbols.momo:5:6)"
-"Token (Binary And, '&', ./tests/06-symbols.momo:7:0)"
-"Token (Binary Or, '|', ./tests/06-symbols.momo:7:2)"
-"Token (Binary Not, '~', ./tests/06-symbols.momo:7:4)"
-"Token (Logical And, '&&', ./tests/06-symbols.momo:9:0)"
-"Token (Logical Or, '||', ./tests/06-symbols.momo:9:3)"
diff --git a/tests/07-numbers.momo b/tests/07-numbers.momo
deleted file mode 100644 (file)
index 229bc10..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-69
-
-100
diff --git a/tests/07-numbers.momo.test b/tests/07-numbers.momo.test
deleted file mode 100644 (file)
index 9f1e6c2..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-"Token (Int, '69', ./tests/07-numbers.momo:1:1)"
-"Token (Int, '100', ./tests/07-numbers.momo:3:1)"
diff --git a/tests/08-floating-point-numbers.momo b/tests/08-floating-point-numbers.momo
deleted file mode 100644 (file)
index f1e547b..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-69.0
-100.15134324
-420.11
diff --git a/tests/08-floating-point-numbers.momo.test b/tests/08-floating-point-numbers.momo.test
deleted file mode 100644 (file)
index 908ddcf..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-"Token (Float, '69.0', ./tests/08-floating-point-numbers.momo:1:1)"
-"Token (Float, '100.15134324', ./tests/08-floating-point-numbers.momo:2:1)"
-"Token (Float, '420.11', ./tests/08-floating-point-numbers.momo:3:1)"
diff --git a/tests/identifiers.build.code.expected b/tests/identifiers.build.code.expected
new file mode 100644 (file)
index 0000000..c227083
--- /dev/null
@@ -0,0 +1 @@
+0
\ No newline at end of file
diff --git a/tests/identifiers.build.err.expected b/tests/identifiers.build.err.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/identifiers.build.out.expected b/tests/identifiers.build.out.expected
new file mode 100644 (file)
index 0000000..d8a895b
--- /dev/null
@@ -0,0 +1,11 @@
+identifiers.momo:1:0 [IDENT] 'foo'
+identifiers.momo:2:1 [IDENT] 'bar'
+identifiers.momo:2:5 [IDENT] 'baz'
+identifiers.momo:8:0 [IDENT] 'A'
+identifiers.momo:8:2 [IDENT] 'B'
+identifiers.momo:8:4 [IDENT] 'C'
+identifiers.momo:10:0 [IDENT] '_D'
+identifiers.momo:10:3 [IDENT] 'eE'
+identifiers.momo:10:6 [IDENT] '_F'
+identifiers.momo:10:9 [IDENT] '_G'
+[INFO] OK
diff --git a/tests/identifiers.code.expected b/tests/identifiers.code.expected
new file mode 100644 (file)
index 0000000..d7d17fc
--- /dev/null
@@ -0,0 +1 @@
+-1
\ No newline at end of file
diff --git a/tests/identifiers.err.expected b/tests/identifiers.err.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/identifiers.momo b/tests/identifiers.momo
new file mode 100644 (file)
index 0000000..8f3067b
--- /dev/null
@@ -0,0 +1,10 @@
+foo
+ bar baz
+
+
+
+
+
+A B C
+
+_D eE _F _G
diff --git a/tests/identifiers.out.expected b/tests/identifiers.out.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/operators.build.code.expected b/tests/operators.build.code.expected
new file mode 100644 (file)
index 0000000..c227083
--- /dev/null
@@ -0,0 +1 @@
+0
\ No newline at end of file
diff --git a/tests/operators.build.err.expected b/tests/operators.build.err.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/operators.build.out.expected b/tests/operators.build.out.expected
new file mode 100644 (file)
index 0000000..37c4a50
--- /dev/null
@@ -0,0 +1,27 @@
+operators.momo:1:7 [MINUS] '-'
+operators.momo:2:0 [MINUS_MINUS] '--'
+operators.momo:3:0 [RETURNER] '->'
+operators.momo:4:0 [PLUS] '+'
+operators.momo:5:0 [PLUS_PLUS] '++'
+operators.momo:6:0 [PLUS_EQUAL] '+='
+operators.momo:7:0 [DIVIDE] '/'
+operators.momo:8:0 [DIVIDE_EQUAL] '/='
+operators.momo:9:0 [MULTIPLY] '*'
+operators.momo:10:0 [POWER] '**'
+operators.momo:11:0 [MULTIPLY_EQUAL] '*='
+operators.momo:12:0 [MODULUS] '%'
+operators.momo:13:0 [MODULUS_EQUAL] '%='
+operators.momo:15:0 [BITWISE_AND] '&'
+operators.momo:16:0 [BITWISE_AND_EQUAL] '&='
+operators.momo:17:0 [BITWISE_XOR] '^'
+operators.momo:18:0 [BITWISE_XOR_EQUAL] '^='
+operators.momo:19:0 [BITWISE_NOT] '~'
+operators.momo:20:0 [BITWISE_OR] '|'
+operators.momo:21:0 [BITWISE_OR_EQUAL] '|='
+operators.momo:23:0 [NOT] '!'
+operators.momo:24:0 [NOT_EQUAL] '!='
+operators.momo:25:0 [LOGICAL_AND] '&&'
+operators.momo:26:0 [LOGICAL_OR] '||'
+operators.momo:28:0 [EQUAL] '='
+operators.momo:29:0 [EQUAL_EQUAL] '=='
+[INFO] OK
diff --git a/tests/operators.code.expected b/tests/operators.code.expected
new file mode 100644 (file)
index 0000000..d7d17fc
--- /dev/null
@@ -0,0 +1 @@
+-1
\ No newline at end of file
diff --git a/tests/operators.err.expected b/tests/operators.err.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/operators.momo b/tests/operators.momo
new file mode 100644 (file)
index 0000000..1d999f9
--- /dev/null
@@ -0,0 +1,29 @@
+       -
+--
+->
++
+++
++=
+/
+/=
+*
+**
+*=
+%
+%=
+
+&
+&=
+^
+^=
+~
+|
+|=
+
+!
+!=
+&&
+||
+
+=
+==
diff --git a/tests/operators.out.expected b/tests/operators.out.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/strings.build.code.expected b/tests/strings.build.code.expected
new file mode 100644 (file)
index 0000000..c227083
--- /dev/null
@@ -0,0 +1 @@
+0
\ No newline at end of file
diff --git a/tests/strings.build.err.expected b/tests/strings.build.err.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/strings.build.out.expected b/tests/strings.build.out.expected
new file mode 100644 (file)
index 0000000..214376d
--- /dev/null
@@ -0,0 +1,3 @@
+strings.momo:1:1 [STRING] 'This is a string!'
+strings.momo:4:9 [STRING] 'This too is a string!'
+[INFO] OK
diff --git a/tests/strings.code.expected b/tests/strings.code.expected
new file mode 100644 (file)
index 0000000..d7d17fc
--- /dev/null
@@ -0,0 +1 @@
+-1
\ No newline at end of file
diff --git a/tests/strings.err.expected b/tests/strings.err.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/strings.momo b/tests/strings.momo
new file mode 100644 (file)
index 0000000..f31ccf3
--- /dev/null
@@ -0,0 +1,4 @@
+"This is a string!"
+
+
+        "This too is a string!"
diff --git a/tests/strings.out.expected b/tests/strings.out.expected
new file mode 100644 (file)
index 0000000..e69de29