|
1 | 1 |
|
2 | 2 | # python -m pytest test-helloworld.py |
3 | 3 |
|
4 | | -import logging |
5 | 4 | import os |
6 | 5 | import re |
7 | | -import subprocess |
8 | | - |
9 | | -# Run Cppcheck with args |
10 | | -def cppcheck(args): |
11 | | - if os.path.isfile('../../bin/debug/cppcheck.exe'): |
12 | | - cmd = '../../bin/debug/cppcheck.exe ' + args |
13 | | - elif os.path.isfile('../../../bin/debug/cppcheck.exe'): |
14 | | - cmd = '../../../bin/debug/cppcheck.exe ' + args |
15 | | - elif os.path.isfile('../../cppcheck'): |
16 | | - cmd = '../../cppcheck ' + args |
17 | | - else: |
18 | | - cmd = '../../../cppcheck ' + args |
19 | | - logging.info(cmd) |
20 | | - p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
21 | | - comm = p.communicate() |
22 | | - stdout = comm[0].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') |
23 | | - stderr = comm[1].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') |
24 | | - return p.returncode, stdout, stderr |
| 6 | +from testutils import create_gui_project_file, cppcheck |
25 | 7 |
|
26 | 8 | # Run Cppcheck from project path |
27 | 9 | def cppcheck_local(args): |
@@ -52,39 +34,6 @@ def getVsConfigs(stdout, filename): |
52 | 34 | ret.sort() |
53 | 35 | return ' '.join(ret) |
54 | 36 |
|
55 | | -# Create Cppcheck project file |
56 | | -def create_gui_project_file(project_file, root_path=None, import_project=None, paths=None, exclude_paths=None, suppressions=None): |
57 | | - cppcheck_xml = ('<?xml version="1.0" encoding="UTF-8"?>\n' |
58 | | - '<project version="1">\n') |
59 | | - if root_path: |
60 | | - cppcheck_xml += ' <root name="' + root_path + '"/>\n' |
61 | | - if import_project: |
62 | | - cppcheck_xml += ' <importproject>' + import_project + '</importproject>\n' |
63 | | - if paths: |
64 | | - cppcheck_xml += ' <paths>\n' |
65 | | - for path in paths: |
66 | | - cppcheck_xml += ' <dir name="' + path + '"/>\n' |
67 | | - cppcheck_xml += ' </paths>\n' |
68 | | - if exclude_paths: |
69 | | - cppcheck_xml += ' <exclude>\n' |
70 | | - for path in exclude_paths: |
71 | | - cppcheck_xml += ' <path name="' + path + '"/>\n' |
72 | | - cppcheck_xml += ' </exclude>\n' |
73 | | - if suppressions: |
74 | | - cppcheck_xml += ' <suppressions>\n' |
75 | | - for suppression in suppressions: |
76 | | - cppcheck_xml += ' <suppression' |
77 | | - if 'fileName' in suppression: |
78 | | - cppcheck_xml += ' fileName="' + suppression['fileName'] + '"' |
79 | | - cppcheck_xml += '>' + suppression['id'] + '</suppression>\n' |
80 | | - cppcheck_xml += ' </suppressions>\n' |
81 | | - cppcheck_xml += '</project>\n' |
82 | | - |
83 | | - f = open(project_file, 'wt') |
84 | | - f.write(cppcheck_xml) |
85 | | - f.close() |
86 | | - |
87 | | - |
88 | 37 | def test_relative_path(): |
89 | 38 | ret, stdout, stderr = cppcheck('1-helloworld') |
90 | 39 | filename = os.path.join('1-helloworld', 'main.c') |
|
0 commit comments