Skip to content

Commit 4937d15

Browse files
committed
add python tests
1 parent dab6ae6 commit 4937d15

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"directory": "./.",
4+
"command": "/usr/bin/c++ -std=gnu++11 -c ./main.cpp",
5+
"file": "./main.cpp"
6+
},
7+
{
8+
"directory": "./.",
9+
"command": "/usr/bin/c++ -std=gnu++11 -c ./main.cpp",
10+
"file": "./main.cpp"
11+
}
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"directory": "./.",
4+
"command": "/usr/bin/c++ -std=gnu++11 -c ./main.cpp",
5+
"file": "./main.cpp"
6+
},
7+
{
8+
"directory": "./.",
9+
"command": "/usr/bin/c++ -DHELLO -std=gnu++11 -c ./main.cpp",
10+
"file": "./main.cpp"
11+
}
12+
]

test/cli/duplicates/main.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <iostream>
2+
3+
int main(int argc, char **argv)
4+
{
5+
std::cout << "Hello, world!" << std::endl;
6+
}

test/cli/duplicates_test.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
# python -m pytest test-helloworld.py
3+
4+
import os
5+
6+
from testutils import cppcheck
7+
8+
__script_dir = os.path.dirname(os.path.abspath(__file__))
9+
__proj_dir = os.path.join(__script_dir, 'duplicates')
10+
11+
def test_project_duplicates():
12+
args = ['--project=compile_commands_duplicates.json']
13+
ret, stdout, _ = cppcheck(args, cwd=__proj_dir)
14+
assert ret == 0
15+
assert stdout.count('main.cpp') == 1
16+
17+
def test_project_duplicates_recheck():
18+
args = [
19+
'--project=compile_commands_duplicates.json',
20+
'--recheck-project-duplicates'
21+
]
22+
ret, stdout, _ = cppcheck(args, cwd=__proj_dir)
23+
assert ret == 0
24+
assert stdout.count('main.cpp') > 1
25+
26+
def test_project_no_duplicates():
27+
args = ['--project=compile_commands_no_duplicates.json']
28+
ret, stdout, _ = cppcheck(args, cwd=__proj_dir)
29+
assert ret == 0
30+
assert stdout.count('main.cpp') > 1
31+
32+
def test_project_duplicates_builddir(tmpdir):
33+
args = [
34+
'--project=compile_commands_duplicates.json',
35+
f'--cppcheck-build-dir={tmpdir}'
36+
]
37+
ret, _, _ = cppcheck(args, cwd=__proj_dir)
38+
assert ret == 0
39+
files = os.listdir(tmpdir)
40+
assert 'main.a1' in files
41+
assert 'main.a2' not in files
42+
43+
def test_project_no_duplicates_builddir(tmpdir):
44+
args = [
45+
'--project=compile_commands_no_duplicates.json',
46+
f'--cppcheck-build-dir={tmpdir}'
47+
]
48+
ret, _, _ = cppcheck(args, cwd=__proj_dir)
49+
assert ret == 0
50+
files = os.listdir(tmpdir)
51+
assert 'main.a1' in files
52+
assert 'main.a2' in files

0 commit comments

Comments
 (0)