]> granicus.if.org Git - llvm/commitdiff
[lit] Add argument check: --timeout must be non-negative integer
authorJulian Lettner <jlettner@apple.com>
Mon, 14 Oct 2019 23:43:18 +0000 (23:43 +0000)
committerJulian Lettner <jlettner@apple.com>
Mon, 14 Oct 2019 23:43:18 +0000 (23:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374847 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/cl_arguments.py

index bf44a31513da57bd838b96124bfbd561c77e04c4..8d4bf06939fe7b9cfd1f31ab6e2f4122f49682ec 100644 (file)
@@ -121,7 +121,7 @@ def parse_args():
             dest="maxIndividualTestTime",
             help="Maximum time to spend running a single test (in seconds). "
                  "0 means no time limit. [Default: 0]",
-            type=int,
+            type=_non_negative_int,
             default=None)
     execution_group.add_argument("--max-failures",
             dest="maxFailures",
@@ -202,14 +202,20 @@ def parse_args():
     return opts
 
 def _positive_int(arg):
-    desc = "requires positive integer, but found '{}'"
+    return _int(arg, 'positive', lambda i: i > 0)
+
+def _non_negative_int(arg):
+    return _int(arg, 'non-negative', lambda i: i >= 0)
+
+def _int(arg, kind, pred):
+    desc = "requires {} integer, but found '{}'"
     try:
-        n = int(arg)
+        i = int(arg)
     except ValueError:
-        raise _error(desc, arg)
-    if n <= 0:
-        raise _error(desc, arg)
-    return n
+        raise _error(desc, kind, arg)
+    if not pred(i):
+        raise _error(desc, kind, arg)
+    return i
 
 def _case_insensitive_regex(arg):
     import re