-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_clang_tidy.py
42 lines (34 loc) · 1.24 KB
/
test_clang_tidy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pytest
import subprocess
from pathlib import Path
from cpp_linter_hooks.clang_tidy import run_clang_tidy
@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, generate_compilation_database):
# copy test file to tmp_path to prevent modifying repo data
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
print(output)
@pytest.mark.parametrize(
('args', 'expected_retval'), (
(['--checks="boost-*"'], 1),
(['--checks="boost-*"', '--version=16'], 1),
),
)
def test_run_clang_tidy_invalid(args, expected_retval, tmp_path):
# non existent file
test_file = tmp_path / "main.c"
ret, _ = run_clang_tidy(args + [str(test_file)])
assert ret == expected_retval