-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(coverage): clean ups, use normalized source code for locations #9438
Conversation
let bytes_end = (loc.start + loc.length.unwrap_or(0)) as u32; | ||
let bytes = bytes_start..bytes_end; | ||
|
||
let start_line = self.source[..bytes.start as usize].lines().count() as u32; |
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.
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 pass normalized source code to solc so source locations are relative to that instead of the original source code
Normalized here means in Source::new
we strip '\r' from the source code.
That fix was wrong because char positions are not the same as byte positions.
let name = format!("{}.{name}", item.loc.contract_name); | ||
writeln!(self.destination, "FN:{line},{name}")?; | ||
writeln!(self.destination, "FNDA:{hits},{name}")?; | ||
writeln!(self.out, "FN:{line},{line_end},{name}")?; |
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.
that's awesome, we can get rid of this from book after merged https://book.getfoundry.sh/reference/forge/forge-coverage#description
not sure if it's relevant, but i noticed comments like
breaks the coverage output (contract is basically skipped in .lcov export) |
@krakovia-evm where exactly you put that in sources you attached? I am not able to replicate and check is solved with PR, would be great to have a unit test for the case. thanks |
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.
lgtm! made some more testing and lcov report shows up accurately now
Between the import & contract definition |
ah, I see the motivation for this was to ensure deterministic metadata on both windows and unix which was useful in context of #7711 but should be fine as long as project performs deployments from the same system every time removing normalization will result in some breaking tests but there are no hard blockers for it afaict |
@DaniPopes @grandizzy Are there any tests that actually use |
Please open an issue instead of commenting on closed PRs! I tested manually with lcov 2, I didn't try with lcov 1, sorry about that, but I also can't seem to reproduce what you said, so an issue would be great with info such as what version and how you're running lcov... |
@DaniPopes Ok, will make a new issue with a reproduction. I commented on the issue as I did a bisect of commits and arrived at this issue that introduced the bug. |
I see, thanks for bisecting |
@DaniPopes Created the issue: #9461 |
Fixes #9437.
We pass normalized source code to solc so source locations are relative to that instead of the original source code. This is quite the footgun, I would like to see if we can remove this normalization upstream. CC @klkvr
With this PR LCOV 2.X works with no errors on the generated lcov.info file. This required adding "end line" to functions, and
Line
statements for all functions, see commits.cc @grandizzy
#9437 lcov.info diff