Commit db5947f0 authored by Ezio Melotti's avatar Ezio Melotti

#16306: Fix multiple error messages when unknown command line parameters where...

#16306: Fix multiple error messages when unknown command line parameters where passed to the interpreter.  Patch by Hieu Nguyen.
parent 9e94972e
...@@ -6,7 +6,8 @@ import test.test_support ...@@ -6,7 +6,8 @@ import test.test_support
import sys import sys
import unittest import unittest
from test.script_helper import ( from test.script_helper import (
assert_python_ok, spawn_python, kill_python, python_exit_code assert_python_ok, assert_python_failure, spawn_python, kill_python,
python_exit_code
) )
...@@ -116,6 +117,14 @@ class CmdLineTest(unittest.TestCase): ...@@ -116,6 +117,14 @@ class CmdLineTest(unittest.TestCase):
assert_python_ok(filename) assert_python_ok(filename)
def test_unknown_options(self):
# Add "without='-E'" to prevent _assert_python append env_vars -E
# which changes the output of stderr
rc, out, err = assert_python_failure('-z', without='-E')
self.assertIn(b'Unknown option', err)
self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1)
self.assertEqual(b'', out)
def test_main(): def test_main():
test.test_support.run_unittest(CmdLineTest) test.test_support.run_unittest(CmdLineTest)
test.test_support.reap_children() test.test_support.reap_children()
......
...@@ -701,6 +701,7 @@ Tony Nelson ...@@ -701,6 +701,7 @@ Tony Nelson
Chad Netzer Chad Netzer
Max Neunhöffer Max Neunhöffer
George Neville-Neil George Neville-Neil
Hieu Nguyen
Johannes Nicolai Johannes Nicolai
Samuel Nicolary Samuel Nicolary
Gustavo Niemeyer Gustavo Niemeyer
......
...@@ -9,6 +9,9 @@ What's New in Python 2.7.4 ...@@ -9,6 +9,9 @@ What's New in Python 2.7.4
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #16306: Fix multiple error messages when unknown command line
parameters where passed to the interpreter. Patch by Hieu Nguyen.
- Issue #15379: Fix passing of non-BMP characters as integers for the charmap - Issue #15379: Fix passing of non-BMP characters as integers for the charmap
decoder (already working as unicode strings). Patch by Serhiy Storchaka. decoder (already working as unicode strings). Patch by Serhiy Storchaka.
......
...@@ -41,7 +41,7 @@ static char *opt_ptr = ""; ...@@ -41,7 +41,7 @@ static char *opt_ptr = "";
void _PyOS_ResetGetOpt(void) void _PyOS_ResetGetOpt(void)
{ {
_PyOS_opterr = 1; _PyOS_opterr = 0; /* prevent printing the error in 2nd loop in main.c */
_PyOS_optind = 1; _PyOS_optind = 1;
_PyOS_optarg = NULL; _PyOS_optarg = NULL;
opt_ptr = ""; opt_ptr = "";
...@@ -86,17 +86,19 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring) ...@@ -86,17 +86,19 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring)
opt_ptr = &argv[_PyOS_optind++][1]; opt_ptr = &argv[_PyOS_optind++][1];
} }
if ( (option = *opt_ptr++) == '\0') if ((option = *opt_ptr++) == '\0')
return -1; return -1;
if (option == 'J') { if (option == 'J') {
fprintf(stderr, "-J is reserved for Jython\n"); if (_PyOS_opterr)
fprintf(stderr, "-J is reserved for Jython\n");
return '_'; return '_';
} }
if (option == 'X') { if (option == 'X') {
fprintf(stderr, if (_PyOS_opterr)
"-X is reserved for implementation-specific arguments\n"); fprintf(stderr,
"-X is reserved for implementation-specific arguments\n");
return '_'; return '_';
} }
...@@ -117,7 +119,7 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring) ...@@ -117,7 +119,7 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring)
if (_PyOS_optind >= argc) { if (_PyOS_optind >= argc) {
if (_PyOS_opterr) if (_PyOS_opterr)
fprintf(stderr, fprintf(stderr,
"Argument expected for the -%c option\n", option); "Argument expected for the -%c option\n", option);
return '_'; return '_';
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment