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

Function test_stl

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

Source from the content-addressed store, hash-verified

74
75
76def test_stl(tmp_path):
77 test_file = tmp_path / 'test.cpp'
78 with open(test_file, 'wt') as f:
79 f.write("""
80void 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
106def test_strlen_empty_str(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