Skip to content

Commit

Permalink
add fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
shenxianpeng committed Aug 16, 2024
1 parent df5c583 commit 1a5ee37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions tests/test_clang_tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
from cpp_linter_hooks.clang_tidy import run_clang_tidy


@pytest.fixture(scope='function')
def generate_compilation_database():
# Generate compilation database
subprocess.run(['mkdir', '-p', 'build', '&&', 'cmake', '-Bbuild', 'testing/'], shell=True)


@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):
subprocess.run(['mkdir', '-p', 'build', '&&', 'cmake', '-Bbuild', 'testing/'], shell=True)
def test_run_clang_tidy_valid(args, expected_retval, tmp_path, generate_compilation_database):
# copy test file to tmp_path to prevent modifying repo data
generate_compilation_database
test_file = tmp_path / "main.c"
test_file.write_bytes(Path("testing/main.c").read_bytes())
ret, output = run_clang_tidy(args + [str(test_file)])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_ensure_installed(tool, version, tmp_path, monkeypatch, caplog):
# first run should install
assert caplog.record_tuples[0][2] == f"Checking for {tool}, version {bin_version}"
if run == 0:
# FIXME
# 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
Expand Down

0 comments on commit 1a5ee37

Please sign in to comment.