diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-10-17 16:11:03 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-10-17 16:11:03 (GMT) |
commit | 1f6b69b74996164be5f13dea34242edc14bd87a1 (patch) | |
tree | b1b50209870de40fc64e71aacc84b8a9785c3266 /Lib/test | |
parent | 5493e4723a922b9905cf6916363e72109a531cfd (diff) | |
download | cpython-1f6b69b74996164be5f13dea34242edc14bd87a1.zip cpython-1f6b69b74996164be5f13dea34242edc14bd87a1.tar.gz cpython-1f6b69b74996164be5f13dea34242edc14bd87a1.tar.bz2 |
Issue #28409: regrtest: fix the parser of command line arguments.
Diffstat (limited to 'Lib/test')
-rwxr-xr-x | Lib/test/regrtest.py | 11 | ||||
-rw-r--r-- | Lib/test/test_regrtest.py | 10 |
2 files changed, 17 insertions, 4 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index f1892ac..f870854 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -325,9 +325,6 @@ def _create_parser(): group.add_argument('-P', '--pgo', dest='pgo', action='store_true', help='enable Profile Guided Optimization training') - parser.add_argument('args', nargs='*', - help=argparse.SUPPRESS) - return parser def relative_filename(string): @@ -373,7 +370,13 @@ def _parse_args(args, **kwargs): ns.use_resources = [] parser = _create_parser() - parser.parse_args(args=args, namespace=ns) + # Issue #14191: argparse doesn't support "intermixed" positional and + # optional arguments. Use parse_known_args() as workaround. + ns.args = parser.parse_known_args(args=args, namespace=ns)[1] + for arg in ns.args: + if arg.startswith('-'): + parser.error("unrecognized arguments: %s" % arg) + sys.exit(1) if ns.single and ns.fromfile: parser.error("-s and -f don't go together!") diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py index a398a4f..ae18327 100644 --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -270,6 +270,16 @@ class ParseArgsTestCase(unittest.TestCase): self.assertEqual(ns.verbose, 0) self.assertEqual(ns.args, ['foo']) + def test_arg_option_arg(self): + ns = regrtest._parse_args(['test_unaryop', '-v', 'test_binop']) + self.assertEqual(ns.verbose, 1) + self.assertEqual(ns.args, ['test_unaryop', 'test_binop']) + + def test_unknown_option(self): + self.checkError(['--unknown-option'], + 'unrecognized arguments: --unknown-option') + + if __name__ == '__main__': unittest.main() |