diff --git a/.gitignore b/.gitignore index 104d3fd..dcc969f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ coverage.xml __pycache__ venv result.txt -testing/main.c +testing/bad.c diff --git a/README.md b/README.md index f128005..0be050d 100644 --- a/README.md +++ b/README.md @@ -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 -int main() {for (;;) break; printf("Hello world!\n");return 0;} @@ -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;} ^ ``` @@ -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 (;;) ^ { diff --git a/testing/main.c b/testing/main.c deleted file mode 100644 index 6b1a169..0000000 --- a/testing/main.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -int main() {for (;;) break; printf("Hello world!\n");return 0;} diff --git a/testing/run.sh b/testing/run.sh index 7a88fcc..db88468 100644 --- a/testing/run.sh +++ b/testing/run.sh @@ -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` diff --git a/tests/test_clang_format.py b/tests/test_clang_format.py index 7a1b7b7..8d914f3 100644 --- a/tests/test_clang_format.py +++ b/tests/test_clang_format.py @@ -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() @@ -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 diff --git a/tests/test_clang_tidy.py b/tests/test_clang_tidy.py index acf5f7a..11d9c5a 100644 --- a/tests/test_clang_tidy.py +++ b/tests/test_clang_tidy.py @@ -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), @@ -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) @@ -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