| 133 | |
| 134 | |
| 135 | def test_suggest_nullptr(tmp_path): |
| 136 | test_file = tmp_path / 'test.cpp' |
| 137 | with open(test_file, 'wt') as f: |
| 138 | f.write(""" |
| 139 | void f() |
| 140 | { |
| 141 | const char* p = 0; |
| 142 | } |
| 143 | """) |
| 144 | |
| 145 | rule_file = os.path.join(__rules_dir, 'suggest_nullptr.xml') |
| 146 | args = [ |
| 147 | '--template=simple', |
| 148 | '--rule-file={}'.format(rule_file), |
| 149 | str(test_file) |
| 150 | ] |
| 151 | ret, stdout, stderr = cppcheck(args) |
| 152 | assert ret == 0 |
| 153 | assert stdout.splitlines() == [ |
| 154 | 'Checking {} ...'.format(test_file), |
| 155 | 'Processing rule: (\\b\\w+\\b) \\* (\\b\\w+\\b) = 0 ;' |
| 156 | ] |
| 157 | assert stderr.splitlines() == [ |
| 158 | "{}:4:0: style: Prefer to use a 'nullptr' instead of initializing a pointer with 0. [modernizeUseNullPtr]".format(test_file) |
| 159 | ] |
| 160 | |
| 161 | |
| 162 | def test_unused_deref(tmp_path): |