From dc141ad7cdb43488eab23fa869c6873afeab5715 Mon Sep 17 00:00:00 2001 From: Julian Lettner Date: Mon, 14 Oct 2019 23:43:18 +0000 Subject: [PATCH] [lit] Add argument check: --timeout must be non-negative integer git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374847 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/lit/lit/cl_arguments.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/utils/lit/lit/cl_arguments.py b/utils/lit/lit/cl_arguments.py index bf44a31513d..8d4bf06939f 100644 --- a/utils/lit/lit/cl_arguments.py +++ b/utils/lit/lit/cl_arguments.py @@ -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 -- 2.11.4.GIT