| 160 | |
| 161 | |
| 162 | def test_unused_deref(tmp_path): |
| 163 | test_file = tmp_path / 'test.cpp' |
| 164 | with open(test_file, 'wt') as f: |
| 165 | f.write(""" |
| 166 | void f(const char* p) |
| 167 | { |
| 168 | *p++; |
| 169 | } |
| 170 | """) |
| 171 | |
| 172 | rule_file = os.path.join(__rules_dir, 'unused-deref.xml') |
| 173 | args = [ |
| 174 | '--template=simple', |
| 175 | '--rule-file={}'.format(rule_file), |
| 176 | str(test_file) |
| 177 | ] |
| 178 | ret, stdout, stderr = cppcheck(args) |
| 179 | assert ret == 0 |
| 180 | assert stdout.splitlines() == [ |
| 181 | 'Checking {} ...'.format(test_file), |
| 182 | 'Processing rule: [;{}] [*] \\w+? (\\+\\+|\\-\\-) ; ' |
| 183 | ] |
| 184 | assert stderr.splitlines() == [ |
| 185 | '{}:3:0: style: Redundant * found, "*p++" is the same as "*(p++)". [UnusedDeref]'.format(test_file) |
| 186 | ] |