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

Function test_strlen_empty_str

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

Source from the content-addressed store, hash-verified

104
105
106def test_strlen_empty_str(tmp_path):
107 test_file = tmp_path / 'test.cpp'
108 with open(test_file, 'wt') as f:
109 f.write("""
110void f(const char* s)
111{
112 if (strlen(s) > 0)
113 {
114 }
115}
116""")
117
118 rule_file = os.path.join(__rules_dir, 'strlen-empty-str.xml')
119 args = [
120 '--template=simple',
121 '--rule-file={}'.format(rule_file),
122 str(test_file)
123 ]
124 ret, stdout, stderr = cppcheck(args)
125 assert ret == 0
126 assert stdout.splitlines() == [
127 'Checking {} ...'.format(test_file),
128 'Processing rule: if \\( ([!] )*?(strlen) \\( \\w+? \\) ([>] [0] )*?\\) { '
129 ]
130 assert stderr.splitlines() == [
131 '{}:4:0: performance: Using strlen() to check if a string is empty is not efficient. [StrlenEmptyString]'.format(test_file)
132 ]
133
134
135def test_suggest_nullptr(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