From 98aa3c1de985ad42e999bae0264979d293274a91 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 llvm-svn: 374847 --- llvm/utils/lit/lit/cl_arguments.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py index bf44a31..8d4bf06 100644 --- a/llvm/utils/lit/lit/cl_arguments.py +++ b/llvm/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.7.4