Skip to content

Commit

Permalink
rename main.c to bad.c
Browse files Browse the repository at this point in the history
  • Loading branch information
shenxianpeng committed Mar 6, 2024
1 parent d7dca0d commit 18f609e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ coverage.xml
__pycache__
venv
result.txt
testing/main.c
testing/bad.c
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ clang-format.............................................................Failed
Here is the diff between the modified file.

```diff
--- a/testing/main.c
+++ b/testing/main.c
--- a/testing/bad.c
+++ b/testing/bad.c
@@ -1,3 +1,6 @@
#include <stdio.h>
-int main() {for (;;) break; printf("Hello world!\n");return 0;}
Expand All @@ -89,22 +89,22 @@ clang-format.............................................................Failed
- hook id: clang-format
- exit code: 255
main.c:2:11: warning: code should be clang-formatted [-Wclang-format-violations]
bad.c:2:11: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
main.c:2:13: warning: code should be clang-formatted [-Wclang-format-violations]
bad.c:2:13: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
main.c:2:21: warning: code should be clang-formatted [-Wclang-format-violations]
bad.c:2:21: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
main.c:2:28: warning: code should be clang-formatted [-Wclang-format-violations]
bad.c:2:28: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
main.c:2:54: warning: code should be clang-formatted [-Wclang-format-violations]
bad.c:2:54: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
main.c:2:63: warning: code should be clang-formatted [-Wclang-format-violations]
bad.c:2:63: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
```
Expand All @@ -119,7 +119,7 @@ clang-tidy...............................................................Failed
522 warnings generated.
Suppressed 521 warnings (521 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
/home/runner/work/cpp-linter-hooks/cpp-linter-hooks/testing/main.c:4:13: warning: statement should be inside braces [readability-braces-around-statements]
/home/runner/work/cpp-linter-hooks/cpp-linter-hooks/testing/bad.c:4:13: warning: statement should be inside braces [readability-braces-around-statements]
for (;;)
^
{
Expand Down
2 changes: 0 additions & 2 deletions testing/main.c

This file was deleted.

6 changes: 3 additions & 3 deletions testing/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
rm -f result.txt
git restore testing/main.c
git restore testing/bad.c

for config in testing/pre-commit-config.yaml testing/pre-commit-config-version.yaml; do
pre-commit clean
pre-commit run -c $config --files testing/main.c | tee -a result.txt || true
git restore testing/main.c
pre-commit run -c $config --files testing/bad.c | tee -a result.txt || true
git restore testing/bad.c
done

failed_cases=`grep -c "Failed" result.txt`
Expand Down
6 changes: 3 additions & 3 deletions tests/test_clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
)
def test_run_clang_format_valid(args, expected_retval, tmp_path):
# copy test file to tmp_path to prevent modifying repo data
test_file = tmp_path / "main.c"
test_file.write_bytes(Path("testing/main.c").read_bytes())
test_file = tmp_path / "bad.c"
test_file.write_bytes(Path("testing/bad.c").read_bytes())
ret = run_clang_format(args + [str(test_file)])
assert ret == expected_retval
assert test_file.read_text() == Path("testing/good.c").read_text()
Expand All @@ -27,7 +27,7 @@ def test_run_clang_format_valid(args, expected_retval, tmp_path):
)
def test_run_clang_format_invalid(args, expected_retval, tmp_path):
# non existent file
test_file = tmp_path / "main.c"
test_file = tmp_path / "bad.c"

ret, _ = run_clang_format(args + [str(test_file)])
assert ret == expected_retval
7 changes: 3 additions & 4 deletions tests/test_clang_tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from cpp_linter_hooks.clang_tidy import run_clang_tidy


@pytest.mark.skip(reason="see https://github.com/cpp-linter/cpp-linter-hooks/pull/29")
@pytest.mark.parametrize(
('args', 'expected_retval'), (
(['--checks="boost-*"'], 1),
Expand All @@ -13,8 +12,8 @@
)
def test_run_clang_tidy_valid(args, expected_retval, tmp_path):
# copy test file to tmp_path to prevent modifying repo data
test_file = tmp_path / "main.c"
test_file.write_bytes(Path("testing/main.c").read_bytes())
test_file = tmp_path / "bad.c"
test_file.write_bytes(Path("testing/bad.c").read_bytes())
ret, output = run_clang_tidy(args + [str(test_file)])
assert ret == expected_retval
print(output)
Expand All @@ -28,7 +27,7 @@ def test_run_clang_tidy_valid(args, expected_retval, tmp_path):
)
def test_run_clang_tidy_invalid(args, expected_retval, tmp_path):
# non existent file
test_file = tmp_path / "main.c"
test_file = tmp_path / "bad.c"

ret, _ = run_clang_tidy(args + [str(test_file)])
assert ret == expected_retval

0 comments on commit 18f609e

Please sign in to comment.