Skip to content

fix: Redo SCoverage report parsing logic to parse external XML format #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cchitneedi-ag
Copy link

@cchitneedi-ag cchitneedi-ag commented May 29, 2025

The current parsers use the scoverage-data/scoverage.coverage.xml file which is meant to be used internally for storing data. SCoverage has a different XML reporting format for external consumption. Newer versions of the library default to txt files for internal data instead of xml. SonarQube and other similar tools rely on the external format. The new implementation adds capability to parse the external format from XML attributes and computes partial lines based on the executed statements. Also adds new test case which is inline with the external format.

Changes are not breaking, the previous format is also supported.

Reference Links:

  1. SCoverage XML Writer : https://github.com/scoverage/scalac-scoverage-plugin/blob/da4ca495dde236d6b52dd5e823a7d87324c74e57/reporter/src/main/scala/scoverage/reporter/ScoverageXmlWriter.scala#L73
  2. SonarQube's expected file format : https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/test-coverage/test-coverage-parameters/#scala

The current parsers use the scoverage-data/scoverage.coverage.xml
file which is meant to be used internally for storing data.
SCoverage has a different XML reporting format for external consumption.
Newer versions of the library default to txt files for internal data.
SonarQube and other similar tools rely on the external format.
The new implementation adds capability to parse the external format
from XML attributes and computes partial lines based on
the executed statements. Also adds new test case which
is inline with the external format.

Changes are not breaking, the previous format is also supported.
The current parsers use the scoverage-data/scoverage.coverage.xml
file which is meant to be used internally for storing data.
SCoverage has a different XML reporting format for external consumption.
Newer versions of the library default to txt files for internal data.
SonarQube and other similar tools rely on the external format.
The new implementation adds capability to parse the external format
from XML attributes and computes partial lines based on
the executed statements. Also adds new test case which
is inline with the external format.

Changes are not breaking, the previous format is also supported.
The current parsers use the scoverage-data/scoverage.coverage.xml
file which is meant to be used internally for storing data.
SCoverage has a different XML reporting format for external consumption.
Newer versions of the library default to txt files for internal data.
SonarQube and other similar tools rely on the external format.
The new implementation adds capability to parse the external format
from XML attributes and computes partial lines based on
the executed statements. Also adds new test case which
is inline with the external format.

Changes are not breaking, the previous format is also supported.
The current parsers use the scoverage-data/scoverage.coverage.xml
file which is meant to be used internally for storing data.
SCoverage has a different XML reporting format for external consumption.
Newer versions of the library default to txt files for internal data.
SonarQube and other similar tools rely on the external format.
The new implementation adds capability to parse the external format
from XML attributes and computes partial lines based on
the executed statements. Also adds new test case which
is inline with the external format.

Changes are not breaking, the previous format is also supported.
Copy link
Collaborator

@matt-codecov matt-codecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the PR! it appears our CI is not working for community contributions (i might have broken it with a recent change) but we can get that sorted

left a few comments. i think i (or someone) will need to ramp up a bit on the format you're supporting here because there are some things i don't understand from a quick glance:

  • what the start and end attributes on each statement mean
  • why line="5" appears several times, some having branch="true" and others having branch="false"
  • why something having partial coverage is not tied to the branch attribute
  • why a fully-covered branch should be recorded as a line instead of a branch

does /src/main/scala/CoverageClass.scala have, like, 500-character lines with several totally distinct statements and control flow blocks on them?

if you could explain that'd help, else i'll try to get back to you early next week!

Comment on lines +69 to +71
# We only mark it as a branch if it's a partial coverage
coverage_type = CoverageType.branch if is_partial else CoverageType.line
_file.append(line, report_builder_session.create_coverage_line(cov, coverage_type))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would we want to do this?

# Add the line
ln = int(child_text(statement, "line"))
hits = child_text(statement, "count")
is_partial = len(included_statements) > 1 and len(covered_statements) < len(included_statements)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't is_partial factor in whether the branch attribute is true?

@matt-codecov
Copy link
Collaborator

#199 i think this PR should fix the CI issue

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