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

Function test_sarif_null_pointer

test/cli/sarif_test.py:153–188  ·  view source on GitHub ↗

Test SARIF output for null pointer dereference.

()

Source from the content-addressed store, hash-verified

151
152
153def test_sarif_null_pointer():
154 """Test SARIF output for null pointer dereference."""
155 sarif = run_sarif_check(BASIC_TEST_CODE)
156
157 run = sarif["runs"][0]
158 results = run["results"]
159
160 # Should have at least one result
161 assert len(results) > 0
162
163 # Find null pointer result
164 null_pointer_results = [r for r in results if r["ruleId"] == "nullPointer"]
165 assert len(null_pointer_results) > 0
166
167 result = null_pointer_results[0]
168 assert result["level"] == "error"
169 assert "message" in result
170 assert "text" in result["message"]
171 assert (
172 "null" in result["message"]["text"].lower()
173 or "nullptr" in result["message"]["text"].lower()
174 )
175
176 # Check location information
177 assert "locations" in result
178 assert len(result["locations"]) > 0
179 location = result["locations"][0]
180 assert "physicalLocation" in location
181 assert "artifactLocation" in location["physicalLocation"]
182 assert "region" in location["physicalLocation"]
183
184 region = location["physicalLocation"]["region"]
185 assert "startLine" in region
186 assert region["startLine"] > 0
187 assert "startColumn" in region
188 assert region["startColumn"] > 0
189
190
191def test_sarif_security_rules():

Callers

nothing calls this directly

Calls 1

run_sarif_checkFunction · 0.85

Tested by

no test coverage detected