|
3 | 3 |
|
4 | 4 | import os |
5 | 5 | import json |
| 6 | +import pytest |
6 | 7 | from testutils import cppcheck |
7 | 8 |
|
8 | 9 | __script_dir = os.path.dirname(os.path.abspath(__file__)) |
@@ -30,185 +31,140 @@ def __create_compdb(tmpdir, projpath): |
30 | 31 | return compile_commands |
31 | 32 |
|
32 | 33 |
|
33 | | -def test_unused_functions(): |
34 | | - ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '-j1', __project_dir]) |
| 34 | +def __test_unused_functions(extra_args): |
| 35 | + args = ['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', __project_dir] |
| 36 | + args += extra_args |
| 37 | + ret, stdout, stderr = cppcheck(args) |
35 | 38 | assert stdout.splitlines() == [] |
36 | 39 | assert stderr.splitlines() == [ |
37 | 40 | "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) |
38 | 41 | ] |
39 | 42 | assert ret == 0, stdout |
40 | 43 |
|
41 | 44 |
|
| 45 | +def test_unused_functions(): |
| 46 | + __test_unused_functions(['-j1', '--no-cppcheck-build-dir']) |
| 47 | + |
| 48 | + |
42 | 49 | def test_unused_functions_j(): |
43 | | - ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '-j2', __project_dir]) |
| 50 | + ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '-j2', '--no-cppcheck-build-dir', __project_dir]) |
44 | 51 | assert stdout.splitlines() == [ |
45 | 52 | "cppcheck: unusedFunction check requires --cppcheck-build-dir to be active with -j." |
46 | 53 | ] |
47 | 54 | assert stderr.splitlines() == [] |
48 | 55 | assert ret == 0, stdout |
49 | 56 |
|
50 | 57 |
|
51 | | -def test_unused_functions_project(): |
52 | | - ret, stdout, stderr = cppcheck(['-q', |
53 | | - '--template=simple', |
54 | | - '--enable=unusedFunction', |
55 | | - '--inline-suppr', |
56 | | - '--project={}'.format(os.path.join(__project_dir, 'unusedFunction.cppcheck')), |
57 | | - '-j1']) |
| 58 | +def test_unused_functions_builddir(tmpdir): |
| 59 | + build_dir = os.path.join(tmpdir, 'b1') |
| 60 | + os.mkdir(build_dir) |
| 61 | + __test_unused_functions(['-j1', '--cppcheck-build-dir={}'.format(build_dir)]) |
| 62 | + |
| 63 | + |
| 64 | +@pytest.mark.xfail(strict=True) |
| 65 | +def test_unused_functions_builddir_j(tmpdir): |
| 66 | + build_dir = os.path.join(tmpdir, 'b1') |
| 67 | + os.mkdir(build_dir) |
| 68 | + __test_unused_functions(['-j2', '--cppcheck-build-dir={}'.format(build_dir)]) |
| 69 | + |
| 70 | +def __test_unused_functions_project(extra_args): |
| 71 | + project_file = os.path.join(__project_dir, 'unusedFunction.cppcheck') |
| 72 | + args = ['-q', |
| 73 | + '--template=simple', |
| 74 | + '--enable=unusedFunction', |
| 75 | + '--inline-suppr', |
| 76 | + '--project={}'.format(project_file), |
| 77 | + ] |
| 78 | + args += extra_args |
| 79 | + ret, stdout, stderr = cppcheck(args) |
58 | 80 | assert stdout.splitlines() == [] |
59 | 81 | assert [ |
60 | 82 | "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) |
61 | 83 | ] == stderr.splitlines() |
62 | 84 | assert ret == 0, stdout |
63 | 85 |
|
64 | 86 |
|
65 | | -def test_unused_functions_project_j(): |
66 | | - ret, stdout, stderr = cppcheck(['-q', |
67 | | - '--template=simple', |
68 | | - '--enable=unusedFunction', |
69 | | - '--inline-suppr', |
70 | | - '--project={}'.format(os.path.join(__project_dir, 'unusedFunction.cppcheck')), |
71 | | - '-j2']) |
72 | | - assert stdout.splitlines() == [ |
73 | | - "cppcheck: unusedFunction check requires --cppcheck-build-dir to be active with -j." |
74 | | - ] |
75 | | - assert [] == stderr.splitlines() |
76 | | - assert ret == 0, stdout |
77 | | - |
78 | | - |
79 | | -def test_unused_functions_compdb(tmpdir): |
80 | | - compdb_file = __create_compdb(tmpdir, __project_dir) |
81 | | - ret, stdout, stderr = cppcheck(['-q', |
82 | | - '--template=simple', |
83 | | - '--enable=unusedFunction', |
84 | | - '--inline-suppr', |
85 | | - '--project={}'.format(compdb_file), |
86 | | - '-j1' |
87 | | - ]) |
88 | | - assert stdout.splitlines() == [] |
89 | | - assert stderr.splitlines() == [ |
90 | | - "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) |
91 | | - ] |
92 | | - assert ret == 0, stdout |
| 87 | +def test_unused_functions_project(): |
| 88 | + __test_unused_functions_project(['-j1', '--no-cppcheck-build-dir']) |
93 | 89 |
|
94 | 90 |
|
95 | | -def test_unused_functions_compdb_j(tmpdir): |
96 | | - compdb_file = __create_compdb(tmpdir, __project_dir) |
| 91 | +def test_unused_functions_project_j(): |
| 92 | + project_file = os.path.join(__project_dir, 'unusedFunction.cppcheck') |
97 | 93 | ret, stdout, stderr = cppcheck(['-q', |
98 | 94 | '--template=simple', |
99 | 95 | '--enable=unusedFunction', |
100 | 96 | '--inline-suppr', |
101 | | - '--project={}'.format(compdb_file), |
102 | | - '-j2' |
| 97 | + '--project={}'.format(project_file), |
| 98 | + '-j2', |
| 99 | + '--no-cppcheck-build-dir' |
103 | 100 | ]) |
104 | 101 | assert stdout.splitlines() == [ |
105 | 102 | "cppcheck: unusedFunction check requires --cppcheck-build-dir to be active with -j." |
106 | 103 | ] |
107 | | - assert stderr.splitlines() == [] |
| 104 | + assert [] == stderr.splitlines() |
108 | 105 | assert ret == 0, stdout |
109 | 106 |
|
110 | 107 |
|
111 | | -def test_unused_functions_builddir(tmpdir): |
| 108 | +def test_unused_functions_project_builddir(tmpdir): |
112 | 109 | build_dir = os.path.join(tmpdir, 'b1') |
113 | 110 | os.mkdir(build_dir) |
114 | | - ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '-j1', '--cppcheck-build-dir={}'.format(build_dir), __project_dir]) |
115 | | - assert stdout.splitlines() == [] |
116 | | - assert stderr.splitlines() == [ |
117 | | - "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) |
118 | | - ] |
119 | | - assert ret == 0, stdout |
| 111 | + __test_unused_functions_project(['-j1', '--cppcheck-build-dir={}'.format(build_dir)]) |
120 | 112 |
|
121 | 113 |
|
122 | | -# TODO: only f3_3 is unused |
123 | | -def test_unused_functions_builddir_j(tmpdir): |
| 114 | +@pytest.mark.xfail(strict=True) |
| 115 | +def test_unused_functions_project_builddir_j(tmpdir): |
124 | 116 | build_dir = os.path.join(tmpdir, 'b1') |
125 | 117 | os.mkdir(build_dir) |
126 | | - ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '-j2', '--cppcheck-build-dir={}'.format(build_dir), __project_dir]) |
127 | | - assert stdout.splitlines() == [] |
128 | | - assert stderr.splitlines() == [ |
129 | | - "{}1.c:4:0: style: The function 'f1' is never used. [unusedFunction]".format(__project_dir_sep), |
130 | | - "{}2.c:4:0: style: The function 'f2' is never used. [unusedFunction]".format(__project_dir_sep), |
131 | | - "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep), |
132 | | - "{}4.c:4:0: style: The function 'f4_1' is never used. [unusedFunction]".format(__project_dir_sep) |
133 | | - ] |
134 | | - assert ret == 0, stdout |
| 118 | + __test_unused_functions_project(['-j2', '--cppcheck-build-dir={}'.format(build_dir)]) |
135 | 119 |
|
136 | 120 |
|
137 | | -def test_unused_functions_builddir_project(tmpdir): |
138 | | - build_dir = os.path.join(tmpdir, 'b1') |
139 | | - os.mkdir(build_dir) |
140 | | - ret, stdout, stderr = cppcheck(['-q', |
141 | | - '--template=simple', |
142 | | - '--enable=unusedFunction', |
143 | | - '--inline-suppr', |
144 | | - '--project={}'.format(os.path.join(__project_dir, 'unusedFunction.cppcheck')), |
145 | | - '--cppcheck-build-dir={}'.format(build_dir), |
146 | | - '-j1']) |
| 121 | +def __test_unused_functions_compdb(tmpdir, extra_args): |
| 122 | + compdb_file = __create_compdb(tmpdir, __project_dir) |
| 123 | + args = ['-q', |
| 124 | + '--template=simple', |
| 125 | + '--enable=unusedFunction', |
| 126 | + '--inline-suppr', |
| 127 | + '--project={}'.format(compdb_file), |
| 128 | + '-j1' |
| 129 | + ] |
| 130 | + args += extra_args |
| 131 | + ret, stdout, stderr = cppcheck(args) |
147 | 132 | assert stdout.splitlines() == [] |
148 | 133 | assert stderr.splitlines() == [ |
149 | 134 | "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) |
150 | 135 | ] |
151 | 136 | assert ret == 0, stdout |
152 | 137 |
|
153 | 138 |
|
154 | | -# TODO: only f3_3 is unused |
155 | | -def test_unused_functions_builddir_project_j(tmpdir): |
156 | | - build_dir = os.path.join(tmpdir, 'b1') |
157 | | - os.mkdir(build_dir) |
158 | | - ret, stdout, stderr = cppcheck(['-q', |
159 | | - '--template=simple', |
160 | | - '--enable=unusedFunction', |
161 | | - '--inline-suppr', |
162 | | - '--project={}'.format(os.path.join(__project_dir, 'unusedFunction.cppcheck')), |
163 | | - '--cppcheck-build-dir={}'.format(build_dir), |
164 | | - '-j2']) |
165 | | - assert stdout.splitlines() == [] |
166 | | - assert stderr.splitlines() == [ |
167 | | - "{}1.c:4:0: style: The function 'f1' is never used. [unusedFunction]".format(__project_dir_sep), |
168 | | - "{}2.c:4:0: style: The function 'f2' is never used. [unusedFunction]".format(__project_dir_sep), |
169 | | - "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep), |
170 | | - "{}4.c:4:0: style: The function 'f4_1' is never used. [unusedFunction]".format(__project_dir_sep) |
171 | | - ] |
172 | | - assert ret == 0, stdout |
| 139 | +def test_unused_functions_compdb(tmpdir): |
| 140 | + __test_unused_functions_compdb(tmpdir, ['-j1', '--no-cppcheck-build-dir']) |
173 | 141 |
|
174 | 142 |
|
175 | | -def test_unused_functions_builddir_compdb(tmpdir): |
| 143 | +def test_unused_functions_compdb_j(tmpdir): |
176 | 144 | compdb_file = __create_compdb(tmpdir, __project_dir) |
177 | | - build_dir = os.path.join(tmpdir, 'b1') |
178 | | - os.mkdir(build_dir) |
179 | 145 | ret, stdout, stderr = cppcheck(['-q', |
180 | 146 | '--template=simple', |
181 | 147 | '--enable=unusedFunction', |
182 | 148 | '--inline-suppr', |
183 | 149 | '--project={}'.format(compdb_file), |
184 | | - '--cppcheck-build-dir={}'.format(build_dir), |
185 | | - '-j1' |
| 150 | + '-j2', |
| 151 | + '--no-cppcheck-build-dir' |
186 | 152 | ]) |
187 | | - assert stdout.splitlines() == [] |
188 | | - assert stderr.splitlines() == [ |
189 | | - "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) |
| 153 | + assert stdout.splitlines() == [ |
| 154 | + "cppcheck: unusedFunction check requires --cppcheck-build-dir to be active with -j." |
190 | 155 | ] |
| 156 | + assert stderr.splitlines() == [] |
191 | 157 | assert ret == 0, stdout |
192 | 158 |
|
193 | 159 |
|
194 | | -# TODO: only f3_3 is unused |
195 | | -def test_unused_functions_builddir_compdb_j(tmpdir): |
196 | | - compdb_file = __create_compdb(tmpdir, __project_dir) |
| 160 | +def test_unused_functions_compdb_builddir(tmpdir): |
197 | 161 | build_dir = os.path.join(tmpdir, 'b1') |
198 | 162 | os.mkdir(build_dir) |
199 | | - ret, stdout, stderr = cppcheck(['-q', |
200 | | - '--template=simple', |
201 | | - '--enable=unusedFunction', |
202 | | - '--inline-suppr', |
203 | | - '--project={}'.format(compdb_file), |
204 | | - '--cppcheck-build-dir={}'.format(build_dir), |
205 | | - '-j2' |
206 | | - ]) |
207 | | - assert stdout.splitlines() == [] |
208 | | - assert stderr.splitlines() == [ |
209 | | - "{}1.c:4:0: style: The function 'f1' is never used. [unusedFunction]".format(__project_dir_sep), |
210 | | - "{}2.c:4:0: style: The function 'f2' is never used. [unusedFunction]".format(__project_dir_sep), |
211 | | - "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep), |
212 | | - "{}4.c:4:0: style: The function 'f4_1' is never used. [unusedFunction]".format(__project_dir_sep) |
213 | | - ] |
214 | | - assert ret == 0, stdout |
| 163 | + __test_unused_functions_compdb(tmpdir, ['-j1', '--cppcheck-build-dir={}'.format(build_dir)]) |
| 164 | + |
| 165 | + |
| 166 | +@pytest.mark.xfail(strict=True) |
| 167 | +def test_unused_functions_compdb_buildir_j(tmpdir): |
| 168 | + build_dir = os.path.join(tmpdir, 'b1') |
| 169 | + os.mkdir(build_dir) |
| 170 | + __test_unused_functions_compdb(tmpdir, ['-j2', '--cppcheck-build-dir={}'.format(build_dir)]) |
0 commit comments