]> www.git.momoyon.org Git - commonlib.git/commitdiff
[test.py] New flag '-x' Stop on error.
authorahmedsamyh <ahmedsamyh10@gmail.com>
Tue, 25 Feb 2025 10:33:59 +0000 (15:33 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Tue, 25 Feb 2025 10:33:59 +0000 (15:33 +0500)
test.py

diff --git a/test.py b/test.py
index 98832639aba1a4ce38f727a4d56b2c514cbb4d6c..1f9eb5d3cb7a3579f81ba220d4b84a203c910f68 100644 (file)
--- a/test.py
+++ b/test.py
@@ -60,6 +60,7 @@ def hhelp():
     Flags:
         -h      - Same as the help subcommand.
         -v      - Verbose output.
+        -x      - Stop on first error.
           ''')
 
 def vlog(verbose_output, msg):
@@ -80,6 +81,7 @@ def main():
 
     # FLAG_VALUES
     verbose_output = False
+    stop_on_error  = False
 
     subcmds = []
 
@@ -99,6 +101,8 @@ def main():
             exit(0)
         elif flag == 'v':
             verbose_output = True
+        elif flag == 'x':
+            stop_on_error = True
         else:
             print(f"[ERROR] Invalid flag '{flag}'", file=sys.stderr)
             exit(1)
@@ -147,7 +151,8 @@ def main():
                         print(f"{res.stderr}")
                     else:
                         print('')
-                    continue
+                    if stop_on_error: exit(1)
+                    else: continue
                 else:
                     passing_tests_count += 1
                     print("[PASS] ", end='')
@@ -175,7 +180,8 @@ def main():
                     res = subprocess.run(cmd, capture_output = True, text = True)
                 except Exception as e:
                     print(f"[ERROR] Failed to run ./{test_name}: {e}")
-                    continue
+                    if stop_on_error: exit(1)
+                    else: continue
 
                 if test.expected_returncode == -1:
                     print(f"[WARNING] Test doesn't have any expected returncode!")
@@ -185,7 +191,8 @@ def main():
                     print('[FAILED]', file=sys.stderr)
                     print(f"Expected: >>>{test.expected_stdout}>>>")
                     print(f"But Got: >>>{res.stdout}>>>")
-                    continue
+                    if stop_on_error: exit(1)
+                    else: continue
                 passing_tests_count += 1
                 print('[PASS]')