Skip to content

Skip reporting coverage on main source files that aren't uniquely named - #465

Merged
cirras merged 1 commit into
integrated-application-development:masterfrom
romain-cureau:fix/coverage-ambiguous-file-names
Sep 22, 2026
Merged

cirras merged 1 commit into
integrated-application-development:masterfrom
romain-cureau:fix/coverage-ambiguous-file-names

Conversation

@romain-cureau

Copy link
Copy Markdown
Contributor

What

DelphiCodeCoverageParser.indexInputFiles() builds its file-name index with
ImmutableSortedMap, whose build() throws on duplicate keys. The index is keyed by the
bare file name, so any two source files sharing a name make it throw:

java.lang.IllegalArgumentException: Multiple entries with same key:
  AlimProcess.pas=Outils/ICHCL/Alim/AlimProcess.pas
  and AlimProcess.pas=Integration/...

The exception is caught in parseReportFile, so the analysis completes — but the entire
coverage report is discarded
, leaving the project at 0 % with only an ERROR line in the
scanner log to explain it.

Why it matters

Sharing a file name across units is ordinary in Delphi codebases. On the project where this
surfaced, 274 of 2012 files in scope share 92 names: MainForm.pas (×20),
SvcDefinitionsImpl.pas (×14, one per service), Main.pas (×10), CommonGateway_TLB.pas
(×10). These are conventions, not defects — excluding them would mean excluding the core of
the codebase.

The failure is all-or-nothing: that project's report covers 67 files, of which only 3
have an ambiguous name, yet all 67 were dropped.

What this changes

Ambiguous names are removed from the index and reported once, instead of aborting the whole
report. Coverage is still recorded for every file whose name is unique — 64 of 67 in the
case above, rather than none.

The ambiguity itself isn't resolvable here: Delphi Code Coverage identifies files by bare
name, with no path to disambiguate against. Skipping those entries and saying so seemed more
useful than losing everything.

Notes

  • Behaviour is unchanged when no file name is shared.
  • ImmutableSortedMap is no longer used in this class, so the import is removed.
  • Adds testAmbiguousFileNamesDoNotDiscardTheWholeReport, which registers a second
    MainWindow.pas and asserts that Globals.pas coverage is still recorded while the
    ambiguous name is skipped. The full DelphiCoverageToolParserTest suite passes (10 tests).
  • Verified end to end against a real report (67 source files, 43 949 lines, 3 451 covered) on
    SonarQube 26.1 with the plugin built from this branch: coverage went from unreported to
    7.5 %, with Coverage data skipped for 92 ambiguous file name(s) in the log.

@romain-cureau
romain-cureau force-pushed the fix/coverage-ambiguous-file-names branch from 75e9b96 to f2406d1 Compare September 14, 2026 18:49
@cirras cirras changed the title fix(coverage): don't discard the whole report when two sources share a file name Skip reporting coverage on main source files that aren't uniquely named Sep 22, 2026
@cirras
cirras self-requested a review September 22, 2026 04:03
@cirras
cirras force-pushed the fix/coverage-ambiguous-file-names branch from f2406d1 to 26d810c Compare September 22, 2026 04:03
@cirras
cirras merged commit f1b67ba into integrated-application-development:master Sep 22, 2026
2 checks passed
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.

2 participants