| 9 | |
| 10 | |
| 11 | def test_empty_catch_block(tmp_path): |
| 12 | test_file = tmp_path / 'test.cpp' |
| 13 | with open(test_file, 'wt') as f: |
| 14 | f.write(""" |
| 15 | void f() |
| 16 | { |
| 17 | try |
| 18 | { |
| 19 | } |
| 20 | catch (...) |
| 21 | { |
| 22 | } |
| 23 | } |
| 24 | """) |
| 25 | |
| 26 | rule_file = os.path.join(__rules_dir, 'empty-catch-block.xml') |
| 27 | args = [ |
| 28 | '--template=simple', |
| 29 | '--rule-file={}'.format(rule_file), |
| 30 | str(test_file) |
| 31 | ] |
| 32 | ret, stdout, stderr = cppcheck(args) |
| 33 | assert ret == 0 |
| 34 | assert stdout.splitlines() == [ |
| 35 | 'Checking {} ...'.format(test_file), |
| 36 | 'Processing rule: \\}\\s*catch\\s*\\(.*\\)\\s*\\{\\s*\\}' |
| 37 | ] |
| 38 | assert stderr.splitlines() == [ |
| 39 | '{}:6:0: style: Empty catch block found. [rule]'.format(test_file) |
| 40 | ] |
| 41 | |
| 42 | |
| 43 | def test_show_all_defines(tmp_path): |