-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add parameter documention in Statement
.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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,
...
Will fix CoverageTest too |
There was a problem hiding this 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
Also, rebase and regenerate the check files. There are some conflicts with one of my PRs, sorry. |
9cfda90
to
c966b5d
Compare
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
c966b5d
to
86aaea9
Compare
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
In the latter picture, they are "3" even though the actual line number is 4, because
scoverage.coverage
's line number as it isline
number without adjustment (to 1-base)3.4.0-RC1-bin-SNAPSHOT
seems ok 👍