Skip to content

Add --test-command with real JaCoCo coverage; fix locale-dependent formatting - #3

Open
sgo wants to merge 1 commit into
unclebob:mainfrom
sgo:add-test-command-coverage-support
Open

Add --test-command with real JaCoCo coverage; fix locale-dependent formatting#3
sgo wants to merge 1 commit into
unclebob:mainfrom
sgo:add-test-command-coverage-support

Conversation

@sgo

@sgo sgo commented Aug 31, 2026

Copy link
Copy Markdown

Why

I hit this while using crap4java through SwarmForge on a project whose Java
tests run through a dedicated test runner instead of mvn test (SwarmForge's
own engineering constitution requires that convention for Java projects —
"avoid using Maven to run tests; build dedicated test runners and run those
instead"). Since crap4java's coverage step hardcoded mvn ... test ...,
Surefire found zero JUnit-discoverable tests, JaCoCo reported 0% coverage for
every method, and CRAP scores came out inflated for code that was actually
well tested.

Separately, ReportFormatter and the threshold message used String.format
with the JVM default locale, so percentages rendered as 85,0% instead of
85.0% under non-English locales.

What this changes

  • --test-command <cmd> (mirrors the flag mutate4java already has):
    runs <cmd> instead of mvn test for the module's tests. Coverage is
    still real, not skipped: the JaCoCo runtime agent is resolved once per
    module (mvn dependency:copy, cached under target/jacoco-agent/) and
    attached to <cmd> via JAVA_TOOL_OPTIONS, so any JVM <cmd> launches —
    including a custom test runner — contributes coverage. The report goal
    runs afterward against the accumulated .exec file.
  • CommandExecutor gets a runShell(cmd, dir, env) default method (falls
    back to the existing no-env behavior), so this doesn't change the
    signature existing lambda-based test doubles implement.
  • ReportFormatter and CliApplication's threshold message now format with
    Locale.ROOT.
  • Updated spec.md (new §4.4, §7.2.1) and README.md to document the flag.
    Build, report generation, and agent resolution all stay Maven-based per
    the existing spec — only the test-execution step itself becomes
    overridable, which is why I didn't touch the "non-Maven execution"
    non-goal in §2/§15.

All 65 existing + new tests pass (mvn test).

I'm not a maintainer here, just someone hitting this through SwarmForge, so
please push back freely if JAVA_TOOL_OPTIONS injection isn't the shape
you'd want for this — happy to rework it.

🤖 Generated with Claude Code

…ormatting

crap4java's coverage step hardcoded `mvn ... test ...`, which requires
JUnit-discoverable tests. Projects that run tests through a dedicated
runner instead of `mvn test` (as SwarmForge's own engineering constitution
requires for Java projects) got 0% coverage for everything and inflated
CRAP scores, since no tests ever actually ran.

- Add --test-command <cmd>, mirroring mutate4java's existing flag: runs
  <cmd> instead of `mvn test`. Coverage is still real: the JaCoCo runtime
  agent is resolved once per module (mvn dependency:copy, cached under
  target/) and attached to <cmd> via JAVA_TOOL_OPTIONS, so any JVM <cmd>
  launches contributes coverage; the report goal runs afterward.
- CommandExecutor grows a runShell(cmd, dir, env) default method so
  existing lambda-based test doubles keep compiling unchanged.
- Fix ReportFormatter and CliApplication's threshold message: %f
  formatting used the JVM default locale, rendering e.g. "85,0%" under
  non-English locales instead of "85.0%". Pinned to Locale.ROOT.
- Update spec.md (§4.4, §7.2.1) and README to document the new flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant