| 2277 | |
| 2278 | |
| 2279 | def test_builddir_hash_check_level(tmp_path): # #13376 |
| 2280 | test_file = tmp_path / 'test.c' |
| 2281 | with open(test_file, 'wt') as f: |
| 2282 | f.write(""" |
| 2283 | void f(bool b) |
| 2284 | { |
| 2285 | for (int i = 0; i < 2; ++i) |
| 2286 | { |
| 2287 | if (i == 0) {} |
| 2288 | if (b) continue; |
| 2289 | } |
| 2290 | } |
| 2291 | """) |
| 2292 | |
| 2293 | build_dir = tmp_path / 'b1' |
| 2294 | os.mkdir(build_dir) |
| 2295 | |
| 2296 | args = [ # // #14029 |
| 2297 | '--enable=warning', # to execute the code which generates the normalCheckLevelMaxBranches message |
| 2298 | '--cppcheck-build-dir={}'.format(build_dir), |
| 2299 | '--template=simple', |
| 2300 | str(test_file) |
| 2301 | ] |
| 2302 | |
| 2303 | exitcode, stdout, stderr = cppcheck(args) |
| 2304 | assert exitcode == 0, stdout |
| 2305 | assert stderr == '' |
| 2306 | |
| 2307 | args = [ |
| 2308 | '--enable=warning', # to execute the code which generates the normalCheckLevelMaxBranches message |
| 2309 | '--enable=information', # to show the normalCheckLevelMaxBranches message |
| 2310 | '--cppcheck-build-dir={}'.format(build_dir), |
| 2311 | '--template=simple', |
| 2312 | str(test_file) |
| 2313 | ] |
| 2314 | |
| 2315 | exitcode, stdout, stderr = cppcheck(args) |
| 2316 | assert exitcode == 0, stdout |
| 2317 | assert stderr == '{}:0:0: information: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches. [normalCheckLevelMaxBranches]\n'.format(test_file) |
| 2318 | |
| 2319 | cache_file = (build_dir / 'test.a1') |
| 2320 | |
| 2321 | root = ElementTree.fromstring(cache_file.read_text()) |
| 2322 | hash_1 = root.get('hash') |
| 2323 | |
| 2324 | args += ['--check-level=exhaustive'] |
| 2325 | |
| 2326 | exitcode, stdout, stderr = cppcheck(args) |
| 2327 | assert exitcode == 0, stdout |
| 2328 | assert stderr == '' |
| 2329 | |
| 2330 | root = ElementTree.fromstring(cache_file.read_text()) |
| 2331 | hash_2 = root.get('hash') |
| 2332 | |
| 2333 | assert hash_1 != hash_2 |
| 2334 | |
| 2335 | |
| 2336 | def test_def_undef(tmp_path): |