forked from danmar/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpremium_test.py
More file actions
55 lines (40 loc) · 1.58 KB
/
premium_test.py
File metadata and controls
55 lines (40 loc) · 1.58 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
# python -m pytest premium_test.py
import os
import shutil
import sys
import time
from testutils import cppcheck, __lookup_cppcheck_exe
PRODUCT_NAME = 'Cppcheck Premium ' + str(time.time())
def copy_cppcheck_premium(tmpdir):
exe = shutil.copy2(__lookup_cppcheck_exe(), tmpdir)
# add minimum cfg/std.cfg
test_cfg_folder = tmpdir.mkdir('cfg')
with open(test_cfg_folder.join('std.cfg'), 'wt') as f:
f.write('<?xml version="1.0"?>\n<def format="2"/>')
# add simple cppcheck.cfg
with open(tmpdir.join('cppcheck.cfg'), 'wt') as f:
f.write("""
{
"addons": [],
"productName": "NAME",
"about": "NAME",
"safety": true
}
""".replace('NAME', PRODUCT_NAME))
return exe
def test_misra_c_builtin_style_checks(tmpdir):
# FIXME this test does not work in ci-windows.yml (release build)
if sys.platform == 'win32':
return
test_file = os.path.join(tmpdir, 'test.cpp')
with open(test_file, 'wt') as f:
f.write('void foo() { int x; y = 0; }')
exe = copy_cppcheck_premium(tmpdir)
exitcode, _, stderr = cppcheck(['--premium=autosar', '--xml', test_file], cppcheck_exe=exe)
assert exitcode == 0
assert 'id="unusedVariable"' in stderr
assert 'id="checkersReport"' in stderr
exitcode, _, stderr = cppcheck(['--premium=autosar', '--premium=safety-off', '--xml', test_file], cppcheck_exe=exe)
assert exitcode == 0
assert 'id="unusedVariable"' in stderr
assert 'id="checkersReport"' not in stderr