]> www.git.momoyon.org Git - lang.git/commitdiff
[testing] Now can pass input for tests.
authorahmedsamyh <ahmedsamyh10@gmail.com>
Tue, 4 Mar 2025 18:23:49 +0000 (23:23 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Tue, 4 Mar 2025 18:23:49 +0000 (23:23 +0500)
test.py
tests/.identifiers.build.in.expected [new file with mode: 0644]
tests/.identifiers.in.expected [new file with mode: 0644]
tests/.keywords.build.in.expected [new file with mode: 0644]
tests/.keywords.in.expected [new file with mode: 0644]
tests/.operators.build.in.expected [new file with mode: 0644]
tests/.operators.in.expected [new file with mode: 0644]
tests/.strings.build.in.expected [new file with mode: 0644]
tests/.strings.in.expected [new file with mode: 0644]

diff --git a/test.py b/test.py
index e7f4250bd4e13724de8b6e6703ef2fd24143241a..a778892740a1312e72899b76c2ff3ccc970700c2 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -12,10 +12,12 @@ SUFFIX=".momo"
 # TODO: Use Colored logging
 
 class Test:
+    stdin = ''
     expected_stdout = ''
     expected_stderr = ''
     expected_returncode = -1
 
+    build_stdin = ''
     build_expected_stdout = ''
     build_expected_stderr = ''
     build_expected_returncode = -1
@@ -33,6 +35,7 @@ class Test:
                 with open(f, "r") as file:
                      return file.read()
 
+        self.stdin = read_or_create_expected_file("in")
         self.expected_stdout = read_or_create_expected_file("out")
         self.expected_stderr = read_or_create_expected_file("err")
         self.expected_returncode = read_or_create_expected_file("code")
@@ -41,6 +44,7 @@ class Test:
         else:
             self.expected_returncode = int(self.expected_returncode)
 
+        self.build_stdin = read_or_create_expected_file("build.in")
         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")
@@ -57,20 +61,28 @@ class Test:
             with open(f, "w") as file:
                 file.write(content)
 
+        write_expected("in", self.stdin)
         write_expected("out", self.expected_stdout)
         write_expected("err", self.expected_stderr)
         write_expected("code", str(self.expected_returncode))
 
+        write_expected("build.in", self.build_stdin)
         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 get_expected_filename(self, name):
-        if name not in [ "out", "err", "code", "build.out", "build.err", "build.code" ]:
+        if name not in [ "in", "out", "err", "code", "build.in", "build.out", "build.err", "build.code" ]:
             raise Exception("Please pass a valid name")
             
         return f".{self.name}.{name}.expected"
 
+    def get_build_stdin_list(self):
+            build_input_array = self.build_stdin.split(sep=' ')
+            for i in range(len(build_input_array)-1, -1, -1):
+                if len(build_input_array[i]) <= 0:
+                    build_input_array.pop(i)
+            return build_input_array
 
 def usage(program: str):
     print(f"Usage: {program} <subcmd> [flags]")
@@ -170,9 +182,12 @@ def main():
                     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]...")
+                    if stop_on_error: exit(1)
                     continue
 
                 cmd = [COMPILER, f"{test_name}{SUFFIX}"]
+                build_stdin_list = test.get_build_stdin_list()
+                if len(build_stdin_list) > 0: cmd.extend(build_stdin_list)
                 vlog(verbose_output, f"[CMD] {cmd}")
                 res = subprocess.run(cmd, capture_output = True, text = True)
                 if res.returncode != 0:
@@ -268,7 +283,18 @@ def main():
                 print(f"+ Recording expected build behaviour for '{test_name}'...")
                 test = tests[test_name]
 
+                if len(test.build_stdin) > 0:
+                    print(f"[INFO] Test already has build_input '{test.build_stdin}'...")
+                    ans = input("Do you want to change the build_input? [y/N]")
+                    if ans.lower() == 'y':
+                        test.build_stdin = input("What is the input passed? ")
+                else:
+                    test.build_stdin = input("What is the input passed? ")
+
+
                 cmd = [COMPILER, f"{test_name}{SUFFIX}"]
+                build_stdin_list = test.get_build_stdin_list()
+                if len(build_stdin_list) > 0: cmd.extend(build_stdin_list)
                 vlog(verbose_output, f"[CMD] {cmd}")
                 res = subprocess.run(cmd, capture_output = True, text = True)
 
diff --git a/tests/.identifiers.build.in.expected b/tests/.identifiers.build.in.expected
new file mode 100644 (file)
index 0000000..e062164
--- /dev/null
@@ -0,0 +1 @@
+-d
\ No newline at end of file
diff --git a/tests/.identifiers.in.expected b/tests/.identifiers.in.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/.keywords.build.in.expected b/tests/.keywords.build.in.expected
new file mode 100644 (file)
index 0000000..e062164
--- /dev/null
@@ -0,0 +1 @@
+-d
\ No newline at end of file
diff --git a/tests/.keywords.in.expected b/tests/.keywords.in.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/.operators.build.in.expected b/tests/.operators.build.in.expected
new file mode 100644 (file)
index 0000000..e062164
--- /dev/null
@@ -0,0 +1 @@
+-d
\ No newline at end of file
diff --git a/tests/.operators.in.expected b/tests/.operators.in.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/.strings.build.in.expected b/tests/.strings.build.in.expected
new file mode 100644 (file)
index 0000000..e062164
--- /dev/null
@@ -0,0 +1 @@
+-d
\ No newline at end of file
diff --git a/tests/.strings.in.expected b/tests/.strings.in.expected
new file mode 100644 (file)
index 0000000..e69de29