mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
#16306: report only the first unknown option and add more tests. Patch by Serhiy Storchaka.
This commit is contained in:
parent
3c76aa6b23
commit
a0dd22e5e8
3 changed files with 17 additions and 4 deletions
|
@ -376,12 +376,24 @@ class CmdLineTest(unittest.TestCase):
|
|||
print("del sys.modules['__main__']", file=script)
|
||||
assert_python_ok(filename)
|
||||
|
||||
|
||||
def test_unknown_options(self):
|
||||
rc, out, err = assert_python_failure('-z', __cleanenv=True)
|
||||
self.assertIn(b'Unknown option', err)
|
||||
rc, out, err = assert_python_failure('-E', '-z')
|
||||
self.assertIn(b'Unknown option: -z', err)
|
||||
self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1)
|
||||
self.assertEqual(b'', out)
|
||||
# Add "without='-E'" to prevent _assert_python to append -E
|
||||
# to env_vars and change the output of stderr
|
||||
rc, out, err = assert_python_failure('-z', without='-E')
|
||||
self.assertIn(b'Unknown option: -z', err)
|
||||
self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1)
|
||||
self.assertEqual(b'', out)
|
||||
rc, out, err = assert_python_failure('-a', '-z', without='-E')
|
||||
self.assertIn(b'Unknown option: -a', err)
|
||||
# only the first unknown option is reported
|
||||
self.assertNotIn(b'Unknown option: -z', err)
|
||||
self.assertEqual(err.splitlines().count(b'Unknown option: -a'), 1)
|
||||
self.assertEqual(b'', out)
|
||||
|
||||
|
||||
def test_main():
|
||||
test.support.run_unittest(CmdLineTest)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue