-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_clang_tidy.py
More file actions
55 lines (47 loc) · 1.75 KB
/
test_clang_tidy.py
File metadata and controls
55 lines (47 loc) · 1.75 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
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.benchmark
@pytest.mark.parametrize(
("args", "expected_retval"),
(
(['--checks="boost-*"'], 1),
(['--checks="boost-*"', "--version=16"], 1),
(['--checks="boost-*"', "--version=17"], 1),
(['--checks="boost-*"', "--version=18"], 1),
(['--checks="boost-*"', "--version=19"], 1),
(['--checks="boost-*"', "--version=20"], 1),
(['--checks="boost-*"', "--version=21"], 1),
),
)
def test_run_clang_tidy_valid(args, expected_retval):
# copy test file to tmp_path to prevent modifying repo data
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.benchmark
@pytest.mark.parametrize(
("args", "expected_retval"),
(
(['--checks="boost-*"'], 1),
(['--checks="boost-*"', "--version=16"], 1),
(['--checks="boost-*"', "--version=17"], 1),
(['--checks="boost-*"', "--version=18"], 1),
(['--checks="boost-*"', "--version=19"], 1),
(['--checks="boost-*"', "--version=20"], 1),
(['--checks="boost-*"', "--version=21"], 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