MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / test_suggest_nullptr

Function test_suggest_nullptr

test/cli/rules_test.py:135–159  ·  view source on GitHub ↗
(tmp_path)

Source from the content-addressed store, hash-verified

133
134
135def test_suggest_nullptr(tmp_path):
136 test_file = tmp_path / 'test.cpp'
137 with open(test_file, 'wt') as f:
138 f.write("""
139void 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
162def test_unused_deref(tmp_path):

Callers

nothing calls this directly

Calls 5

cppcheckFunction · 0.90
strFunction · 0.85
formatMethod · 0.80
writeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected