]> granicus.if.org Git - python/commitdiff
Fix closes issue # 15033 - Return the proper exitcode for failure when modules are...
authorSenthil Kumaran <senthil@uthcode.com>
Thu, 5 Jul 2012 02:50:29 +0000 (19:50 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Thu, 5 Jul 2012 02:50:29 +0000 (19:50 -0700)
Lib/test/test_cmd_line_script.py
Misc/NEWS
Modules/main.c

index 099471fc63f844602a80bc27df49b7f97e71c5ec..8b05227b8b4e45be3957395b8d8189ad37d83ba9 100644 (file)
@@ -6,11 +6,14 @@ import os.path
 import test.test_support
 from test.script_helper import (run_python,
                                 temp_dir, make_script, compile_script,
-                                make_pkg, make_zip_script, make_zip_pkg)
+                                assert_python_failure, make_pkg,
+                                make_zip_script, make_zip_pkg)
 
 verbose = test.test_support.verbose
 
 
+example_args = ['test1', 'test2', 'test3']
+
 test_source = """\
 # Script may be run with optimisation enabled, so don't rely on assert
 # statements being executed
@@ -204,6 +207,19 @@ class CmdLineTest(unittest.TestCase):
             launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
             self._check_import_error(launch_name, msg)
 
+    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:
+            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():
     test.test_support.run_unittest(CmdLineTest)
index baea13ae008535cd7e66082e5c52c19602ccb081..5b1b40cb86f62b06cdf2263210fd99fad7d23772 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ What's New in Python 2.7.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() 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 from within these
index 135ef6ee2283f786062a65e2b310146d7a1fe8bf..1ce7c8f213861d0b71596b924081d94cd4421533 100644 (file)
@@ -583,7 +583,7 @@ Py_Main(int argc, char **argv)
         sts = PyRun_SimpleStringFlags(command, &cf) != 0;
         free(command);
     } else if (module) {
-        sts = RunModule(module, 1);
+        sts = (RunModule(module, 1) != 0);
         free(module);
     }
     else {