diff options
author | Cindy Liu <hcindyl@google.com> | 2022-07-26 19:18:07 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-07-26 19:18:07 +0000 |
commit | ec62d8ce1dffc943d14fb91742c115d8202a4891 (patch) | |
tree | 3cb9615424d301ef5ed721c37f857b72d7e12551 | |
parent | 78a09afc68a6c21b994029b8aac5a7e173026fac (diff) | |
parent | d33794cf512aeedcfdf68b11ea2e08fa6aedf24a (diff) | |
download | repohooks-ec62d8ce1dffc943d14fb91742c115d8202a4891.tar.gz |
clang-format: fix exit(1) from git-clang-format --diff am: d33794cf51
Original change: https://android-review.googlesource.com/c/platform/tools/repohooks/+/2135637
Change-Id: Ie9d9760c6b624f7ec9713a5b085cf06ee6b08c5e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rwxr-xr-x | tools/clang-format.py | 6 | ||||
-rwxr-xr-x | tools/clang-format_unittest.py | 8 |
2 files changed, 10 insertions, 4 deletions
diff --git a/tools/clang-format.py b/tools/clang-format.py index 24ef711..31514d0 100755 --- a/tools/clang-format.py +++ b/tools/clang-format.py @@ -26,7 +26,7 @@ del _path # We have to import our local modules after the sys.path tweak. We can't use # relative imports because this is an executable program, not a module. -# pylint: disable=wrong-import-position +# pylint: disable=wrong-import-position,import-error import rh.shell import rh.utils @@ -82,10 +82,10 @@ def main(argv): result = rh.utils.run(cmd, capture_output=True, check=False) # Newer versions of git-clang-format will exit 1 when it worked. Assume a # real failure is any exit code above 1, or any time stderr is used, or if - # it exited 1 but didn't produce anything useful to stdout. If it exited 0, + # it exited 1 and produce useful format diffs to stdout. If it exited 0, # then assume all is well and we'll attempt to parse its output below. if (result.returncode > 1 or result.stderr or - (not result.stdout and result.returncode)): + (result.stdout and result.returncode)): print(f'clang-format failed:\ncmd: {result.cmdstr}\n' f'stdout:\n{result.stdout}\nstderr:\n{result.stderr}', file=sys.stderr) diff --git a/tools/clang-format_unittest.py b/tools/clang-format_unittest.py index 1128f65..c83699f 100755 --- a/tools/clang-format_unittest.py +++ b/tools/clang-format_unittest.py @@ -27,7 +27,7 @@ sys.path.insert(0, str(DIR.parent)) # We have to import our local modules after the sys.path tweak. We can't use # relative imports because this is an executable program, not a module. -# pylint: disable=wrong-import-position +# pylint: disable=wrong-import-position,import-error import rh.utils @@ -71,6 +71,12 @@ class GitClangFormatExit(unittest.TestCase): def test_diff_exit_1_no_output(self): """Test exit 1 w/no output.""" with git_clang_format('exit 1') as script: + result = run_clang_format(script, ['--working-tree']) + self.assertEqual(result.stdout, '') + + def test_diff_exit_1_output(self): + """Test exit 1 with output.""" + with git_clang_format('echo bad; exit 1') as script: with self.assertRaises(rh.utils.CalledProcessError) as e: run_clang_format(script, ['--working-tree']) self.assertIn('clang-format failed', e.exception.stderr) |