Skip to content

Commit c773375

Browse files
committed
fix test failure
1 parent d561507 commit c773375

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Use -header-filter=.* to display errors from all non-system headers. Use -system
155155

156156
### Debugging `clang-format` hook
157157

158-
If you encounter issues with the clang-format hook (such as exit code 247 or other errors), you can enable verbose output to show the list of processed files.
158+
If you encounter issues with the clang-format hook (such as exit code 247 or other errors), you can enable verbose output to show the list of processed files by passing the `-v` or `--verbose` argument in the `args` section.
159159

160160
```yaml
161161
repos:

cpp_linter_hooks/clang_format.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ def run_clang_format(args=None) -> Tuple[int, str]:
2222
output = ""
2323
try:
2424
if "--dry-run" in command:
25-
sp = subprocess.run(command, stdout=subprocess.PIPE, encoding="utf-8")
25+
sp = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
2626
retval = -1 # Not a fail just identify it's a dry-run.
27-
output = sp.stdout
27+
output = sp.stdout + sp.stderr
2828
else:
29-
retval = subprocess.run(command, stdout=subprocess.PIPE).returncode
29+
retval = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode
3030
return retval, output
3131
except FileNotFoundError as stderr:
3232
retval = 1

testing/pre-commit-config-verbose.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ repos:
44
hooks:
55
- id: clang-format
66
args: [--style=file, --version=16, --verbose] # test with verbose output
7+
- repo: .
8+
rev: HEAD
9+
hooks:
10+
- id: clang-format
11+
args: [--style=file, --version=16, -v] # test with verbose output

tests/test_clang_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_run_clang_format_verbose(tmp_path):
7373
test_file.write_bytes(Path("testing/main.c").read_bytes())
7474

7575
# Test with verbose flag
76-
ret, output = run_clang_format(["--verbose", "--style=Google", str(test_file)])
76+
ret, _ = run_clang_format(["--verbose", "--style=Google", str(test_file)])
7777

7878
# Should succeed
7979
assert ret == 0

0 commit comments

Comments
 (0)