| 74 | |
| 75 | |
| 76 | def test_stl(tmp_path): |
| 77 | test_file = tmp_path / 'test.cpp' |
| 78 | with open(test_file, 'wt') as f: |
| 79 | f.write(""" |
| 80 | void f() |
| 81 | { |
| 82 | std::string s; |
| 83 | if (s.find("t") == 17) |
| 84 | { |
| 85 | } |
| 86 | } |
| 87 | """) |
| 88 | |
| 89 | rule_file = os.path.join(__rules_dir, 'stl.xml') |
| 90 | args = [ |
| 91 | '--template=simple', |
| 92 | '--rule-file={}'.format(rule_file), |
| 93 | str(test_file) |
| 94 | ] |
| 95 | ret, stdout, stderr = cppcheck(args) |
| 96 | assert ret == 0 |
| 97 | assert stdout.splitlines() == [ |
| 98 | 'Checking {} ...'.format(test_file), |
| 99 | 'Processing rule: \\. find \\( "[^"]+?" \\) == \\d+ ' |
| 100 | ] |
| 101 | assert stderr.splitlines() == [ |
| 102 | '{}:5:0: performance: When looking for a string at a fixed position compare [UselessSTDStringFind]'.format(test_file) |
| 103 | ] |
| 104 | |
| 105 | |
| 106 | def test_strlen_empty_str(tmp_path): |