Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a0dd22e5
Commit
a0dd22e5
authored
Nov 23, 2012
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#16306: report only the first unknown option and add more tests. Patch by Serhiy Storchaka.
parent
3c76aa6b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
4 deletions
+17
-4
Lib/test/test_cmd_line.py
Lib/test/test_cmd_line.py
+15
-3
Modules/main.c
Modules/main.c
+1
-0
Python/getopt.c
Python/getopt.c
+1
-1
No files found.
Lib/test/test_cmd_line.py
View file @
a0dd22e5
...
...
@@ -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
)
...
...
Modules/main.c
View file @
a0dd22e5
...
...
@@ -339,6 +339,7 @@ Py_Main(int argc, wchar_t **argv)
/* Hash randomization needed early for all string operations
(including -W and -X options). */
_PyOS_opterr
=
0
;
/* prevent printing the error in 1st pass */
while
((
c
=
_PyOS_GetOpt
(
argc
,
argv
,
PROGRAM_OPTS
))
!=
EOF
)
{
if
(
c
==
'm'
||
c
==
'c'
)
{
/* -c / -m is the last option: following arguments are
...
...
Python/getopt.c
View file @
a0dd22e5
...
...
@@ -45,7 +45,7 @@ static wchar_t *opt_ptr = L"";
void
_PyOS_ResetGetOpt
(
void
)
{
_PyOS_opterr
=
0
;
/* prevent printing the error in 2nd loop in main.c */
_PyOS_opterr
=
1
;
_PyOS_optind
=
1
;
_PyOS_optarg
=
NULL
;
opt_ptr
=
L""
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment