Skip to content
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

fix: scoverage statement's line number should be 1-base #18932

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

tanishiking
Copy link
Member

@tanishiking tanishiking commented Nov 15, 2023

fix #18916

This PR makes scoverage statements' line number 1-base, instead of 0-base. FYI @tarao

It would be ideal if we could find specifications of many of coverage report fomats (such as Jacoco XML, cobertura.xml, lcov.txt...) and confirm most of them expect the line numbers 1-base.

However, it seems there's no formal specification for them AFAIK. Since we've been using 1-base so far in Scala2 and it hasn't been a problem, so I guess it's OK to change to 1-base (and most of coverage report format and visualizer expect 1-base probably).

I believe we should make coverage report 1-base by default, and it should be reporter / aggregator's responsibility to adjust the line numbers if some coverage format expects 0-base.


I tested on https://github.com/scoverage/sbt-scoverage-samples with HTML reporter

3.3.1

Screenshot 2023-11-15 at 16 55 06

Screenshot 2023-11-15 at 16 55 11

In the latter picture, they are "3" even though the actual line number is 4, because

3.4.0-RC1-bin-SNAPSHOT

Screenshot 2023-11-15 at 17 41 06

seems ok 👍

Screenshot 2023-11-15 at 17 41 01

@@ -97,7 +97,9 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer:
id = id,
start = pos.start,
end = pos.end,
line = pos.line,
// +1 to account for the line number starting at 1
// the internal line number is 0-base https://github.com/lampepfl/dotty/blob/18ada516a85532524a39a962b2ddecb243c65376/compiler/src/dotty/tools/dotc/util/SourceFile.scala#L173-L176
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! do you mean, the parameter document that says line in Statement is 1-base ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean add something like this

/** A statement that can be invoked, and thus counted as "covered" by code coverage tools. 
 *
 *  @param location ...
 *  ...
 *  @param line 1-indexed line number
 *  ...
 */
case class Statement(
    location: Location,
    id: Int,
    start: Int,
    end: Int,
    line: Int,
    ...

@tanishiking
Copy link
Member Author

Will fix CoverageTest too

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

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

Could you squash all commits into one to avoid having failing commits?

Otherwise LGTM

@nicolasstucki
Copy link
Contributor

Could you squash all commits into one to avoid having failing commits?

Also, rebase and regenerate the check files. There are some conflicts with one of my PRs, sorry.

fix scala#18916

This PR makes scoverage statements' line number 1-base,
instead of 0-base, as @tarao described.

It would be ideal if we could find specifications of many of
coverage report fomats (such as Jacoco XML, cobertura.xml, lcov.txt...)
and confirm most of them expect the line numbers 1-base.

However, it seems there's no formal specification for them AFAIK.
Since we've been using 1-base so far in Scala2 and it hasn't been a problem,
so I guess it's OK to change to 1-base (and most of coverage report
format and visualizer expect 1-base maybe).

I believe it should be reporter / aggregator's responsibility to
adjust the line numbers if some coverage format expects 0-base.

Add doc comment to Statement @param line that it's 1-base

Update scoverage.check files

sbt> scala3-compiler-bootstrapped / Test / testCompilation --update-checkfiles
@nicolasstucki nicolasstucki merged commit f3a6ce3 into scala:main Nov 17, 2023
18 checks passed
@tanishiking tanishiking deleted the fix-instrument-line branch November 17, 2023 13:24
Kordyjan added a commit that referenced this pull request Dec 13, 2023
… LTS (#19236)

Backports #18932 to the LTS branch.

PR submitted by the release tooling.
@Kordyjan Kordyjan added this to the 3.3.2 milestone Dec 14, 2023
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.

-coverage-out outputs incompatible line numbers
3 participants