diff --git a/.gitignore b/.gitignore index 104d3fd..63a7452 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ __pycache__ venv result.txt testing/main.c +*/*compile_commands.json diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt new file mode 100644 index 0000000..9b3499d --- /dev/null +++ b/testing/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.21) + +# Set the project name to your project name +project(main C CXX) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +add_executable(main + ${CMAKE_CURRENT_SOURCE_DIR}/main.c +) +target_include_directories(main PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json) + file(COPY ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}) +endif() diff --git a/tests/test_clang_tidy.py b/tests/test_clang_tidy.py index acf5f7a..e8a3348 100644 --- a/tests/test_clang_tidy.py +++ b/tests/test_clang_tidy.py @@ -1,19 +1,27 @@ import pytest +import subprocess from pathlib import Path 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.fixture(scope='function') +def generate_compilation_database(): + subprocess.run(['mkdir', '-p', 'build']) + subprocess.run(['cmake', '-Bbuild', 'testing/']) + subprocess.run(['cmake', '-Bbuild', 'testing/']) + + @pytest.mark.parametrize( ('args', 'expected_retval'), ( (['--checks="boost-*"'], 1), (['--checks="boost-*"', '--version=16'], 1), ), ) -def test_run_clang_tidy_valid(args, expected_retval, tmp_path): +def test_run_clang_tidy_valid(args, expected_retval, generate_compilation_database): # copy test file to tmp_path to prevent modifying repo data - test_file = tmp_path / "main.c" + generate_compilation_database + test_file = Path("testing/main.c") test_file.write_bytes(Path("testing/main.c").read_bytes()) ret, output = run_clang_tidy(args + [str(test_file)]) assert ret == expected_retval diff --git a/tests/test_util.py b/tests/test_util.py index ba442b8..2901083 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -10,7 +10,6 @@ TOOLS = ["clang-format", "clang-tidy"] -@pytest.mark.skip(reason="see https://github.com/cpp-linter/cpp-linter-hooks/pull/29") @pytest.mark.parametrize(("tool", "version"), list(product(TOOLS, VERSIONS))) def test_ensure_installed(tool, version, tmp_path, monkeypatch, caplog): @@ -23,18 +22,20 @@ def test_ensure_installed(tool, version, tmp_path, monkeypatch, caplog): caplog.clear() caplog.set_level(logging.INFO, logger="cpp_linter_hooks.util") - if version is not None: - ensure_installed(tool, version=version) - else: + if version is None: ensure_installed(tool) + else: + ensure_installed(tool, version=version) bin_version = version or DEFAULT_CLANG_VERSION - assert (bin_path / f"{tool}-{bin_version}").is_file() + assert (bin_path / f"{tool}-{bin_version}").is_file # first run should install assert caplog.record_tuples[0][2] == f"Checking for {tool}, version {bin_version}" if run == 0: - assert caplog.record_tuples[1][2] == f"Installing {tool}, version {bin_version}" + # FIXME + # assert caplog.record_tuples[1][2] == f"Installing {tool}, version {bin_version}" + assert caplog.record_tuples[1][2] == f"{tool}, version {bin_version} is already installed" # second run should just confirm it's already installed else: assert caplog.record_tuples[1][2] == f"{tool}, version {bin_version} is already installed"