Skip to content

Commit 9772903

Browse files
committed
add python tests
1 parent dab6ae6 commit 9772903

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-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

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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, stderr = 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 = ['--project=compile_commands_duplicates.json', '--recheck-project-duplicates']
19+
ret, stdout, stderr = cppcheck(args, cwd=__proj_dir)
20+
assert ret == 0
21+
assert stdout.count('main.cpp') > 1
22+
23+
def test_project_no_duplicates():
24+
args = ['--project=compile_commands_no_duplicates.json']
25+
ret, stdout, stderr = cppcheck(args, cwd=__proj_dir)
26+
assert ret == 0
27+
assert stdout.count('main.cpp') > 1

0 commit comments

Comments
 (0)