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

Function run_sarif_check

test/cli/sarif_test.py:106–126  ·  view source on GitHub ↗

Run cppcheck with SARIF output on the given code.

(code, extra_args=None)

Source from the content-addressed store, hash-verified

104
105
106def run_sarif_check(code, extra_args=None):
107 """Run cppcheck with SARIF output on the given code."""
108 with tempfile.TemporaryDirectory() as tmpdir:
109 tmp_path = os.path.join(tmpdir, "test.cpp")
110 with open(tmp_path, "w") as f:
111 f.write(code)
112
113 args = ["--output-format=sarif", "--enable=all", tmp_path]
114
115 if extra_args:
116 args.extend(extra_args)
117
118 _, _, stderr = cppcheck(args)
119
120 # SARIF output is in stderr
121 try:
122 sarif_data = json.loads(stderr)
123 return sarif_data
124 except json.JSONDecodeError as e:
125 pytest.fail(f"Failed to parse SARIF JSON: {e}\nOutput: {stderr}")
126 return None
127
128
129def test_sarif_basic_structure():

Calls 4

cppcheckFunction · 0.90
failMethod · 0.80
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected