Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions integration_tests/test_program.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import subprocess
from pathlib import Path

import pytest
from sarif_pydantic.sarif import Run, Sarif, Tool, ToolDriver

from core_codemods.remove_assertion_in_pytest_raises import (
RemoveAssertionInPytestRaises,
Expand Down Expand Up @@ -26,14 +30,50 @@ def test_codemods_include_exclude_conflict(self):
)
assert completed_process.returncode == 3

def test_load_sast_only_by_flag(self, tmp_path):
@pytest.mark.parametrize(
"cli_args",
[
"--sonar-issues-json",
"--sonar-hotspots-json",
"--sonar-json",
],
)
def test_load_sast_only_by_sonar_flag(self, tmp_path, cli_args):
tmp_file_path = tmp_path / "sonar.json"
tmp_file_path.touch()
completed_process = subprocess.run(
[
"codemodder",
"tests/samples/",
"--sonar-issues-json",
cli_args,
f"{tmp_file_path}",
"--dry-run",
],
check=False,
capture_output=True,
text=True,
)
print(completed_process.stdout)
print(completed_process.stderr)
assert completed_process.returncode == 0
assert RemoveAssertionInPytestRaises.id not in completed_process.stdout

def test_load_sast_only_by_sarif_flag(self, tmp_path: Path):
tmp_file_path = tmp_path / "sarif.json"
sarif_run = Run(
tool=Tool(driver=ToolDriver(name="test")),
results=[],
)
sarif = Sarif(runs=[sarif_run], **{"$schema": ""})
tmp_file_path.write_text(
sarif.model_dump_json(indent=2, exclude_none=True, by_alias=True)
)

completed_process = subprocess.run(
[
"codemodder",
"tests/samples/",
"--sarif",
f"{tmp_file_path}",
"--dry-run",
],
Expand Down
5 changes: 4 additions & 1 deletion src/codemodder/codemodder.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ def _run_cli(original_args, remediation=False) -> int:
max_workers=argv.max_workers,
original_cli_args=original_args,
codemod_registry=codemod_registry,
sast_only=argv.sonar_issues_json or argv.sarif,
sast_only=argv.sonar_issues_json
or argv.sarif
or argv.sonar_hotspots_json
or argv.sonar_json,
log_matched_files=True,
remediation=remediation,
)
Expand Down
Loading