Skip to content

Commit 3bbfe74

Browse files
authored
Fix sast_only flag behavior to include other sast input flags (#1076)
* Fixed behavior of sast_only flag * Modified test to include new flags
1 parent ed991dc commit 3bbfe74

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

integration_tests/test_program.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import subprocess
2+
from pathlib import Path
3+
4+
import pytest
5+
from sarif_pydantic.sarif import Run, Sarif, Tool, ToolDriver
26

37
from core_codemods.remove_assertion_in_pytest_raises import (
48
RemoveAssertionInPytestRaises,
@@ -26,14 +30,50 @@ def test_codemods_include_exclude_conflict(self):
2630
)
2731
assert completed_process.returncode == 3
2832

29-
def test_load_sast_only_by_flag(self, tmp_path):
33+
@pytest.mark.parametrize(
34+
"cli_args",
35+
[
36+
"--sonar-issues-json",
37+
"--sonar-hotspots-json",
38+
"--sonar-json",
39+
],
40+
)
41+
def test_load_sast_only_by_sonar_flag(self, tmp_path, cli_args):
3042
tmp_file_path = tmp_path / "sonar.json"
3143
tmp_file_path.touch()
3244
completed_process = subprocess.run(
3345
[
3446
"codemodder",
3547
"tests/samples/",
36-
"--sonar-issues-json",
48+
cli_args,
49+
f"{tmp_file_path}",
50+
"--dry-run",
51+
],
52+
check=False,
53+
capture_output=True,
54+
text=True,
55+
)
56+
print(completed_process.stdout)
57+
print(completed_process.stderr)
58+
assert completed_process.returncode == 0
59+
assert RemoveAssertionInPytestRaises.id not in completed_process.stdout
60+
61+
def test_load_sast_only_by_sarif_flag(self, tmp_path: Path):
62+
tmp_file_path = tmp_path / "sarif.json"
63+
sarif_run = Run(
64+
tool=Tool(driver=ToolDriver(name="test")),
65+
results=[],
66+
)
67+
sarif = Sarif(runs=[sarif_run], **{"$schema": ""})
68+
tmp_file_path.write_text(
69+
sarif.model_dump_json(indent=2, exclude_none=True, by_alias=True)
70+
)
71+
72+
completed_process = subprocess.run(
73+
[
74+
"codemodder",
75+
"tests/samples/",
76+
"--sarif",
3777
f"{tmp_file_path}",
3878
"--dry-run",
3979
],

src/codemodder/codemodder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,10 @@ def _run_cli(original_args, remediation=False) -> int:
285285
max_workers=argv.max_workers,
286286
original_cli_args=original_args,
287287
codemod_registry=codemod_registry,
288-
sast_only=argv.sonar_issues_json or argv.sarif,
288+
sast_only=argv.sonar_issues_json
289+
or argv.sarif
290+
or argv.sonar_hotspots_json
291+
or argv.sonar_json,
289292
log_matched_files=True,
290293
remediation=remediation,
291294
)

0 commit comments

Comments
 (0)