summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-07-05 02:28:16 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-07-05 02:28:16 (GMT)
commitf01a337950bdcd6905d12b2335ba4d8773f6b8e5 (patch)
tree69ff081aab477227ca4f239023b0dda4ef34cb3a
parent035997f1a3f2edd53a5f72cf381e5e9a12743a30 (diff)
downloadcpython-f01a337950bdcd6905d12b2335ba4d8773f6b8e5.zip
cpython-f01a337950bdcd6905d12b2335ba4d8773f6b8e5.tar.gz
cpython-f01a337950bdcd6905d12b2335ba4d8773f6b8e5.tar.bz2
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
-rw-r--r--Lib/test/test_cmd_line_script.py15
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/main.c2
3 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index 77af347..6b59d96 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -279,6 +279,21 @@ class CmdLineTest(unittest.TestCase):
self._check_output(script_name, rc, out,
script_name, script_name, '', '')
+ def test_dash_m_error_code_is_one(self):
+ # If a module is invoked with the -m command line flag
+ # and results in an error that the return code to the
+ # shell is '1'
+ with temp_dir() as script_dir:
+ with support.temp_cwd(path=script_dir):
+ pkg_dir = os.path.join(script_dir, 'test_pkg')
+ make_pkg(pkg_dir)
+ script_name = _make_test_script(pkg_dir, 'other',
+ "if __name__ == '__main__': raise ValueError")
+ rc, out, err = assert_python_failure('-m', 'test_pkg.other', *example_args)
+ if verbose > 1:
+ print(out)
+ self.assertEqual(rc, 1)
+
def test_main():
support.run_unittest(CmdLineTest)
support.reap_children()
diff --git a/Misc/NEWS b/Misc/NEWS
index 99515c0..5adf15e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
Core and Builtins
-----------------
+- Issue #15033: Fix the exit status bug when modules invoked using -m swith,
+ return the proper failure return value (1). Patch contributed by Jeff Knupp.
+
- Issue #12268: File readline, readlines and read() or readall() methods
no longer lose data when an underlying read system call is interrupted.
IOError is no longer raised due to a read system call returning EINTR
diff --git a/Modules/main.c b/Modules/main.c
index 1282f46..5b4a7e2 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -673,7 +673,7 @@ Py_Main(int argc, wchar_t **argv)
sts = run_command(command, &cf);
free(command);
} else if (module) {
- sts = RunModule(module, 1);
+ sts = (RunModule(module, 1) != 0);
}
else {