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

Function test_sarif_rule_coverage

test/cli/sarif_test.py:458–493  ·  view source on GitHub ↗

Test that a variety of rules are triggered by comprehensive test code.

()

Source from the content-addressed store, hash-verified

456
457
458def test_sarif_rule_coverage():
459 """Test that a variety of rules are triggered by comprehensive test code."""
460 sarif = run_sarif_check(TEST_CODE)
461
462 run = sarif["runs"][0]
463 driver = run["tool"]["driver"]
464 rules = driver["rules"]
465
466 # Collect all rule IDs
467 rule_ids = set(rule["id"] for rule in rules)
468
469 # Should have at least 5 different rules triggered
470 assert (
471 len(rule_ids) >= 5
472 ), f"Expected at least 5 rules, found {len(rule_ids)}: {rule_ids}"
473
474 # Check for some specific expected rules from different categories
475 expected_rules = [
476 "nullPointer", # Security
477 "arrayIndexOutOfBounds", # Security
478 "memleak", # Security
479 "uninitvar", # Security
480 "unusedVariable", # Style
481 "redundantAssignment", # Style
482 "unusedFunction", # Style (if enabled)
483 "constParameter", # Style/Performance
484 "cstyleCast", # Style
485 "variableScope", # Style
486 ]
487
488 found_expected_rules = sum(1 for rule in expected_rules if rule in rule_ids)
489
490 # Should find at least 3 of our expected rules
491 assert (
492 found_expected_rules >= 3
493 ), f"Expected at least 3 known rules, found {found_expected_rules}"
494
495
496def test_sarif_generic_descriptions():

Callers

nothing calls this directly

Calls 2

run_sarif_checkFunction · 0.85
setFunction · 0.85

Tested by

no test coverage detected