diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1ddcb47..77a20de 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,11 +34,4 @@ jobs: fail_ci_if_error: true # optional (default = false) verbose: true # optional (default = false) - name: Test cpp-linter-hooks - run: | - pip install pre-commit - pre-commit install - pre-commit try-repo . -c testing/.pre-commit-config.yaml --files testing/main.c | tee result.txt || true - grep -e "Failed" result.txt - if [ $? -ne 0 ]; then - exit 1 - fi + run: sh testing/run.sh diff --git a/.gitignore b/.gitignore index 9dc11d2..ab736da 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ tests/__pycache__ .coverage __pycache__ venv -result.txt \ No newline at end of file +result.txt +testing/main.c diff --git a/README.md b/README.md index 2e9cf07..ea431a5 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The example of using custom config: `.clang-format` and `.clang-tidy` ```yaml repos: - repo: https://github.com/cpp-linter/cpp-linter-hooks - rev: v0.2.1 + rev: v0.2.5 hooks: - id: clang-format args: [--style=file] # to load .clang-format @@ -44,12 +44,12 @@ The example of using any version of [clang-tools](https://github.com/cpp-linter/ ```yaml repos: - repo: https://github.com/cpp-linter/cpp-linter-hooks - rev: v0.2.1 + rev: v0.2.5 hooks: - id: clang-format - args: [--style=file, --version=13] + args: [--style=file, --version=16] - id: clang-tidy - args: [--checks=.clang-tidy, --version=12] + args: [--checks=.clang-tidy, --version=16] ``` ## Output @@ -107,25 +107,21 @@ int main() {for (;;) break; printf("Hello world!\n");return 0;} ^ ``` -### chang-tidy output +### clang-tidy output ```bash clang-tidy...............................................................Failed - hook id: clang-tidy - exit code: 1 -418 warnings and 1 error generated. -Error while processing /home/ubuntu/cpp-linter-hooks/testing/main.c. -Suppressed 417 warnings (417 in non-user code). +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. -Found compiler error(s). -/home/ubuntu/cpp-linter-hooks/testing/main.c:3:11: warning: statement should be inside braces [readability-braces-around-statements] - for (;;) break; - ^ - { -/usr/include/stdio.h:33:10: error: 'stddef.h' file not found [clang-diagnostic-error] -#include - ^~~~~~~~~~ +/home/runner/work/cpp-linter-hooks/cpp-linter-hooks/testing/main.c:4:13: warning: statement should be inside braces [readability-braces-around-statements] + for (;;) + ^ + { + ``` ## Contributing diff --git a/cpp_linter_hooks/clang_format.py b/cpp_linter_hooks/clang_format.py index c635af8..438da87 100644 --- a/cpp_linter_hooks/clang_format.py +++ b/cpp_linter_hooks/clang_format.py @@ -24,9 +24,9 @@ def run_clang_format(args) -> int: else: retval = subprocess.run(command, stdout=subprocess.PIPE).returncode return retval, output - except FileNotFoundError as e: + except FileNotFoundError as stderr: retval = 1 - return retval, e + return retval, stderr def main() -> int: diff --git a/cpp_linter_hooks/clang_tidy.py b/cpp_linter_hooks/clang_tidy.py index 2ce4f7c..a029d7d 100644 --- a/cpp_linter_hooks/clang_tidy.py +++ b/cpp_linter_hooks/clang_tidy.py @@ -23,9 +23,9 @@ def run_clang_tidy(args) -> int: if "warning:" in output or "error:" in output: retval = 1 return retval, output - except FileNotFoundError as e: + except FileNotFoundError as stderr: retval = 1 - return retval, e + return retval, stderr def main() -> int: diff --git a/cpp_linter_hooks/util.py b/cpp_linter_hooks/util.py index 8a86a4c..101aa02 100644 --- a/cpp_linter_hooks/util.py +++ b/cpp_linter_hooks/util.py @@ -19,7 +19,7 @@ def install_clang_tools(version: str) -> int: # clang-tools exist because install_requires=['clang-tools'] in setup.py install_tool_cmd = ['clang-tools', '-i', version] else: - # install verison 13 by default if clang-tools not exist. + # install version 13 by default if clang-tools not exist. install_tool_cmd = ['clang-tools', '-i', '13'] try: subprocess.run(install_tool_cmd, stdout=subprocess.PIPE) diff --git a/pyproject.toml b/pyproject.toml index 7396fc6..b450ecb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ authors = [ ] classifiers = [ # https://pypi.org/pypi?%3Aaction=list_classifiers - "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "Intended Audience :: Information Technology", diff --git a/requirements-dev.txt b/requirements-dev.txt index 7093b61..4dbfffa 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,3 @@ coverage +pre-commit pytest diff --git a/testing/.pre-commit-config.yaml b/testing/.pre-commit-config.yaml index 0116dec..14e7205 100644 --- a/testing/.pre-commit-config.yaml +++ b/testing/.pre-commit-config.yaml @@ -1,8 +1,8 @@ repos: - repo: https://github.com/cpp-linter/cpp-linter-hooks - rev: + rev: 2a92e91720ca4bc79d67c3e4aea57642f598d534 hooks: - id: clang-format - args: [--style=file] # to load .clang-format + args: [--style=file, --version=16] # to load .clang-format - id: clang-tidy - args: [--checks=.clang-tidy] # path/to/.clang-tidy + args: [--checks=.clang-tidy, --version=16] # path/to/.clang-tidy diff --git a/testing/README.md b/testing/README.md new file mode 100644 index 0000000..7c339a3 --- /dev/null +++ b/testing/README.md @@ -0,0 +1,8 @@ +# Test cpp-linter-hooks + +## Test locally + +```bash +pre-commit try-repo ./.. clang-format --verbose --all-files +pre-commit try-repo ./.. clang-tidy --verbose --all-files +``` diff --git a/testing/run.sh b/testing/run.sh new file mode 100644 index 0000000..5d96fac --- /dev/null +++ b/testing/run.sh @@ -0,0 +1,17 @@ +pre-commit install +pre-commit try-repo . -c testing/.pre-commit-config.yaml --files testing/main.c | tee result.txt || true + +failed_cases=`grep -c "Failed" result.txt` + +if [ $failed_cases -eq 2 ]; then + echo "==============================" + echo "Test cpp-linter-hooks success." + echo "==============================" + exit 0 + rm result.txt +else + echo "=============================" + echo "Test cpp-linter-hooks failed." + echo "=============================" + exit 1 +fi