-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_clang_format.py
More file actions
41 lines (35 loc) · 1.41 KB
/
test_clang_format.py
File metadata and controls
41 lines (35 loc) · 1.41 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
import pytest
from pathlib import Path
from cpp_linter_hooks.clang_format import run_clang_format
@pytest.mark.parametrize(
('args', 'expected_retval'), (
(['--style=Google'], (0, "")),
(['--style=Google', '--version=16'], (0, "")),
(['--style=Google', '--version=17'], (0, "")),
(['--style=Google', '--version=18'], (0, "")),
(['--style=Google', '--version=19'], (0, "")),
(['--style=Google', '--version=20'], (0, "")),
),
)
def test_run_clang_format_valid(args, expected_retval, tmp_path):
# copy test file to tmp_path to prevent modifying repo data
test_file = tmp_path / "main.c"
test_file.write_bytes(Path("testing/main.c").read_bytes())
ret = run_clang_format(args + [str(test_file)])
assert ret == expected_retval
assert test_file.read_text() == Path("testing/good.c").read_text()
@pytest.mark.parametrize(
('args', 'expected_retval'), (
(['--style=Google',], 1),
(['--style=Google', '--version=16'], 1),
(['--style=Google', '--version=17'], 1),
(['--style=Google', '--version=18'], 1),
(['--style=Google', '--version=19'], 1),
(['--style=Google', '--version=20'], 1),
),
)
def test_run_clang_format_invalid(args, expected_retval, tmp_path):
# non existent file
test_file = tmp_path / "main.c"
ret, _ = run_clang_format(args + [str(test_file)])
assert ret == expected_retval