|
7 | 7 | import json |
8 | 8 |
|
9 | 9 | from testutils import cppcheck, assert_cppcheck, cppcheck_ex |
| 10 | +from xml.etree import ElementTree |
10 | 11 |
|
11 | 12 |
|
12 | 13 | def __remove_std_lookup_log(l : list, exepath): |
@@ -2269,3 +2270,49 @@ def test_dumpfile_platform(tmpdir): |
2269 | 2270 | break |
2270 | 2271 | assert ' wchar_t_bit="' in platform |
2271 | 2272 | assert ' size_t_bit="' in platform |
| 2273 | + |
| 2274 | + |
| 2275 | +def test_builddir_hash_check_level(tmp_path): # #13376 |
| 2276 | + test_file = tmp_path / 'test.c' |
| 2277 | + with open(test_file, 'wt') as f: |
| 2278 | + f.write(""" |
| 2279 | +void f(bool b) |
| 2280 | +{ |
| 2281 | + for (int i = 0; i < 2; ++i) |
| 2282 | + { |
| 2283 | + if (i == 0) {} |
| 2284 | + if (b) continue; |
| 2285 | + } |
| 2286 | +} |
| 2287 | +""") |
| 2288 | + |
| 2289 | + build_dir = tmp_path / 'b1' |
| 2290 | + os.mkdir(build_dir) |
| 2291 | + |
| 2292 | + args = [ |
| 2293 | + '--enable=warning', # to execute the code which generates the normalCheckLevelMaxBranches message |
| 2294 | + '--enable=information', # to show the normalCheckLevelMaxBranches message |
| 2295 | + '--cppcheck-build-dir={}'.format(build_dir), |
| 2296 | + '--template=simple', |
| 2297 | + str(test_file) |
| 2298 | + ] |
| 2299 | + |
| 2300 | + exitcode, stdout, stderr = cppcheck(args) |
| 2301 | + assert exitcode == 0, stdout |
| 2302 | + assert stderr == '{}:0:0: information: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches. [normalCheckLevelMaxBranches]\n'.format(test_file) |
| 2303 | + |
| 2304 | + cache_file = (build_dir / 'test.a1') |
| 2305 | + |
| 2306 | + root = ElementTree.fromstring(cache_file.read_text()) |
| 2307 | + hash_1 = root.get('hash') |
| 2308 | + |
| 2309 | + args += ['--check-level=exhaustive'] |
| 2310 | + |
| 2311 | + exitcode, stdout, stderr = cppcheck(args) |
| 2312 | + assert exitcode == 0, stdout |
| 2313 | + assert stderr == '' |
| 2314 | + |
| 2315 | + root = ElementTree.fromstring(cache_file.read_text()) |
| 2316 | + hash_2 = root.get('hash') |
| 2317 | + |
| 2318 | + assert hash_1 != hash_2 |
0 commit comments