| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3c76aa6 commit a0dd22e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -376,12 +376,24 @@ def test_del___main__(self): | |||
| 376 | 376 | print("del sys.modules['__main__']", file=script) | |
| 377 | 377 | assert_python_ok(filename) | |
| 378 | 378 | ||
| 379 | - | ||
| 380 | 379 | def test_unknown_options(self): | |
| 381 | - rc, out, err = assert_python_failure('-z', __cleanenv=True) | ||
| 382 | - self.assertIn(b'Unknown option', err) | ||
| 380 | + rc, out, err = assert_python_failure('-E', '-z') | ||
| 381 | + self.assertIn(b'Unknown option: -z', err) | ||
| 382 | + self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1) | ||
| 383 | + self.assertEqual(b'', out) | ||
| 384 | + # Add "without='-E'" to prevent _assert_python to append -E | ||
| 385 | + # to env_vars and change the output of stderr | ||
| 386 | + rc, out, err = assert_python_failure('-z', without='-E') | ||
| 387 | + self.assertIn(b'Unknown option: -z', err) | ||
| 383 | 388 | self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1) | |
| 384 | 389 | self.assertEqual(b'', out) | |
| 390 | + rc, out, err = assert_python_failure('-a', '-z', without='-E') | ||
| 391 | + self.assertIn(b'Unknown option: -a', err) | ||
| 392 | + # only the first unknown option is reported | ||
| 393 | + self.assertNotIn(b'Unknown option: -z', err) | ||
| 394 | + self.assertEqual(err.splitlines().count(b'Unknown option: -a'), 1) | ||
| 395 | + self.assertEqual(b'', out) | ||
| 396 | + | ||
| 385 | 397 | ||
| 386 | 398 | def test_main(): | |
| 387 | 399 | test.support.run_unittest(CmdLineTest) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -339,6 +339,7 @@ Py_Main(int argc, wchar_t **argv) | |||
| 339 | 339 | ||
| 340 | 340 | /* Hash randomization needed early for all string operations | |
| 341 | 341 | (including -W and -X options). */ | |
| 342 | + _PyOS_opterr = 0; /* prevent printing the error in 1st pass */ | ||
| 342 | 343 | while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) { | |
| 343 | 344 | if (c == 'm' || c == 'c') { | |
| 344 | 345 | /* -c / -m is the last option: following arguments are | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,7 +45,7 @@ static wchar_t *opt_ptr = L""; | |||
| 45 | 45 | ||
| 46 | 46 | void _PyOS_ResetGetOpt(void) | |
| 47 | 47 | { | |
| 48 | - _PyOS_opterr = 0; /* prevent printing the error in 2nd loop in main.c */ | ||
| 48 | + _PyOS_opterr = 1; | ||
| 49 | 49 | _PyOS_optind = 1; | |
| 50 | 50 | _PyOS_optarg = NULL; | |
| 51 | 51 | opt_ptr = L""; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments