[llvm] r374847 - [lit] Add argument check: --timeout must be non-negative integer
Julian Lettner via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 14 16:43:18 PDT 2019
Author: yln
Date: Mon Oct 14 16:43:18 2019
New Revision: 374847
URL: http://llvm.org/viewvc/llvm-project?rev=374847&view=rev
Log:
[lit] Add argument check: --timeout must be non-negative integer
Modified:
llvm/trunk/utils/lit/lit/cl_arguments.py
Modified: llvm/trunk/utils/lit/lit/cl_arguments.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/cl_arguments.py?rev=374847&r1=374846&r2=374847&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/cl_arguments.py (original)
+++ llvm/trunk/utils/lit/lit/cl_arguments.py Mon Oct 14 16:43:18 2019
@@ -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
More information about the llvm-commits
mailing list