mirror of
https://github.com/python/cpython.git
synced 2026-10-28 10:25:05 +08:00
gh-118158: Fix missing newline in py_compile CLI error output (#149008)
Restore trailing newline in error messages from `python -m py_compile`, lost when `main()` was refactored to use argparse.
This commit is contained in:
1 parent
627adb517f
commit
7edcaedc53
3 files changed
+9
-2
No files matched your search
+2
-2
@@ -202,12 +202,12 @@ def main():
|
||||
if args.quiet:
|
||||
parser.exit(1)
|
||||
else:
|
||||
parser.exit(1, error.msg)
|
||||
parser.exit(1, error.msg + '\n')
|
||||
except OSError as error:
|
||||
if args.quiet:
|
||||
parser.exit(1)
|
||||
else:
|
||||
parser.exit(1, str(error))
|
||||
parser.exit(1, str(error) + '\n')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -327,6 +327,12 @@ class PyCompileCLITestCase(unittest.TestCase):
|
||||
self.assertEqual(stdout, b'')
|
||||
self.assertEqual(stderr, b'')
|
||||
|
||||
def test_bad_syntax_stderr_ends_with_newline(self):
|
||||
with open(self.source_path, 'w') as file:
|
||||
file.write(' print("hello world")\n')
|
||||
rc, stdout, stderr = self.pycompilecmd_failure(self.source_path)
|
||||
self.assertTrue(stderr.endswith(b'\n'))
|
||||
|
||||
def test_file_not_exists(self):
|
||||
should_not_exists = os.path.join(os.path.dirname(__file__), 'should_not_exists.py')
|
||||
rc, stdout, stderr = self.pycompilecmd_failure(self.source_path, should_not_exists)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Ensure py_compile CLI error messages end with a newline. Contributed by Xiao Yuan.
|
||||
Reference in new issue
Block a user