From: Julian Lettner Date: Wed, 30 Oct 2019 06:06:00 +0000 (-0700) Subject: [lit] Refine adoption of argparse --version action X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a3fab31acd6b99dd70334df7fbfae22b914e3214;p=platform%2Fupstream%2Fllvm.git [lit] Refine adoption of argparse --version action The real work for this was already done by serge-sans-paille [1]. Thanks for this! [1] 1d4849379f71a0f5d73202a291c0b709f7cafbc5 --- diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py index 402fadb..53ef761 100644 --- a/llvm/utils/lit/lit/cl_arguments.py +++ b/llvm/utils/lit/lit/cl_arguments.py @@ -5,18 +5,17 @@ import sys import lit.util + def parse_args(): - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser(prog='lit') parser.add_argument('test_paths', nargs='+', metavar="TEST_PATH", help='File or path to include in the test suite') - parser.add_argument("--version", - dest="show_version", - help="Show version and exit", - version="lit " + lit.__version__, - action="version") + parser.add_argument('--version', + action='version', + version='%(prog)s ' + lit.__version__) parser.add_argument("-j", "--threads", "--workers", dest="workers", @@ -189,12 +188,15 @@ def parse_args(): return opts + def _positive_int(arg): 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: @@ -205,6 +207,7 @@ def _int(arg, kind, pred): raise _error(desc, kind, arg) return i + def _case_insensitive_regex(arg): import re try: @@ -212,6 +215,7 @@ def _case_insensitive_regex(arg): except re.error as reason: raise _error("invalid regular expression: '{}', {}", arg, reason) + def _error(desc, *args): msg = desc.format(*args) return argparse.ArgumentTypeError(msg) diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py index 4b61c8f..8c675c0 100755 --- a/llvm/utils/lit/lit/main.py +++ b/llvm/utils/lit/lit/main.py @@ -20,7 +20,6 @@ import lit.util def main(builtin_params={}): opts = lit.cl_arguments.parse_args() - params = create_params(builtin_params, opts.user_params) is_windows = platform.system() == 'Windows' diff --git a/llvm/utils/lit/tests/usage.py b/llvm/utils/lit/tests/usage.py index d168c5e..77b3573 100644 --- a/llvm/utils/lit/tests/usage.py +++ b/llvm/utils/lit/tests/usage.py @@ -1,6 +1,7 @@ -# Basic sanity check that usage works. +# Basic sanity check for `--help` and `--version` options. # -# RUN: %{lit} --help > %t.out -# RUN: FileCheck < %t.out %s +# RUN: %{lit} --help | FileCheck %s --check-prefix=HELP +# RUN: %{lit} --version 2>&1 | FileCheck %s --check-prefix=VERSION # -# CHECK: usage: lit.py [-h] +# HELP: usage: lit [-h] +# VERSION: lit {{[0-9]+\.[0-9]+\.[0-9]+[a-zA-Z0-9]*}} diff --git a/llvm/utils/lit/tests/version.py b/llvm/utils/lit/tests/version.py deleted file mode 100644 index 1d5e152..0000000 --- a/llvm/utils/lit/tests/version.py +++ /dev/null @@ -1,5 +0,0 @@ -# Basic sanity check that --version works. -# -# RUN: %{lit} --version 2>&1 | FileCheck %s -# -# CHECK: lit {{[0-9]+\.[0-9]+\.[0-9]+[a-zA-Z0-9]*}}