Skip to content

Commit 8d45e1c

Browse files
committed
test(sasts): add Cppcheck
1 parent ff6a624 commit 8d45e1c

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

tests/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ RUN apt update -qq && \
2121
curl git \
2222
cloc \
2323
openjdk-17-jdk-headless maven \
24+
build-essential bear \
2425
-y -qq --no-install-recommends && \
2526
rm -rf /var/lib/apt/lists/*
2627

@@ -50,6 +51,10 @@ RUN curl -sfL https://raw.githubusercontent.com/Bearer/bearer/main/contrib/insta
5051
RUN curl -sL https://github.com/spotbugs/spotbugs/releases/download/4.9.7/spotbugs-4.9.7.tgz | tar -xzvf - && \
5152
mv spotbugs-* /tmp/spotbugs
5253
ENV PATH="/tmp/spotbugs/bin:$PATH"
54+
# Cppcheck
55+
RUN apt update -qq && \
56+
DEBIAN_FRONTEND=noninteractive apt install cppcheck -y -qq --no-install-recommends && \
57+
rm -rf /var/lib/apt/lists/*
5358

5459
# === Run tests ===
5560
COPY --from=builder --chown=app:app /app /app

tests/test_sasts.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727

2828
@pytest.fixture(autouse=True, scope="module")
2929
def update_sast_module_state() -> GeneratorType:
30-
"""Update the state of SAST modules between tests."""
30+
"""Update the state of SAST modules before running tests in this module.
31+
32+
This fixture re-initializes each SAST tool's status and missing requirements
33+
to ensure a clean state for the test functions.
34+
35+
"""
3136
for sast_data in SASTS_ALL.values():
3237
sast_instance = sast_data["sast"]()
3338
sast_data["cli_factory"].sast.__init__()
@@ -40,7 +45,12 @@ def update_sast_module_state() -> GeneratorType:
4045
runner = CliRunner(env={"COLUMNS": "200"})
4146

4247
TEST_CODES_DIR = Path("tests/testcodes").resolve()
43-
TEST_CODES = {"java": {"build_command": "javac {filename}"}}
48+
TEST_CODES = {
49+
"java": {"build_command": "javac {filename}"},
50+
"c": {"build_command": "bear -- gcc {filename}"},
51+
}
52+
53+
ARTIFACTS_ARG = {"java": ".", "c": "compile_commands.json"}
4454

4555

4656
@pytest.mark.order(0)
@@ -51,7 +61,7 @@ def test_compile() -> None | AssertionError:
5161
if isinstance(dataset, PrebuiltDatasetMixin):
5262
logging.info(f"Compiling dataset: {dataset.name}")
5363
retcode, stdout = run_command(
54-
dataset.build_command.split(" ") + ["--test"], cwd=dataset.directory
64+
dataset.build_command.split(" "), cwd=dataset.directory
5565
)
5666
assert retcode == 0
5767

@@ -115,7 +125,9 @@ def test_sasts_analyze(monkeypatch: pytest.MonkeyPatch) -> None | AssertionError
115125
for file in Path(TEST_CODES_DIR, lang).iterdir():
116126
Path(temp_dir, file.name).write_bytes(file.read_bytes())
117127

118-
result = runner.invoke(sast_cli, ["analyze", lang, "--artifacts", "."])
128+
result = runner.invoke(
129+
sast_cli, ["analyze", lang, "--artifacts", ARTIFACTS_ARG[lang]]
130+
)
119131
assert result.exit_code == 0
120132
assert "--overwrite" not in result.output
121133

0 commit comments

Comments
 (0)