summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-11-23 16:48:32 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2012-11-23 16:48:32 (GMT)
commita0dd22e5e824195e322cb417ebb34c66475e952d (patch)
treee956848fbcae719625590663cbef64c6401d124e /Lib/test
parent3c76aa6b234fb1496b35488f30cca2fece467354 (diff)
downloadcpython-a0dd22e5e824195e322cb417ebb34c66475e952d.zip
cpython-a0dd22e5e824195e322cb417ebb34c66475e952d.tar.gz
cpython-a0dd22e5e824195e322cb417ebb34c66475e952d.tar.bz2
#16306: report only the first unknown option and add more tests. Patch by Serhiy Storchaka.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_cmd_line.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index d8f2443..e12f305 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -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)