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
Code that is optimized out is considered coverable but never covered #46012
Comments
I wonder if what's going on here is that asserts that are always true are marked as not covered, but are still marked as runnable code. It makes sense that they not count towards coverage (they're redundant no-op code), but in that case they should be marked as not coverable as well. FWIW, this is actually making it quite hard for me to improve the coverage for Flutter because so many of our "uncovered" lines are things like this, where there's an assert that's optimized out and gets marked as untested. |
It would make sense if asserts didn't count towards coverage when assertions are disabled. It's slightly tricky for const constructor assertions since they are always executed during const evaluation. I don't know how const evaluation counts towards coverage in general. |
As far as I can tell what's actually going on is that the asserts (and other code, I don't think it's strictly only asserts) that the compiler can prove are always true (or are always dead code) are being optimised out, but still count towards code that could be covered, and thus end up as "uncovered" code in the coverage results. Code that's optimized out should just count as uncoverable, like blank lines or comments. cc @liamappelbe |
I think this bug is the same underlying issue as #47017. Asserts just weren't having their coverage tracked properly. Should be fixed now. |
woot! thanks @liamappelbe! |
lib/foo.dart:
pubspec.yaml:
test/test_test.dart:
Collect coverage however you wish, I used this:
Expected result: 100% coverage.
Actual result: 50% coverage. Specifically:
In other words, asserts in constructors count against coverage. This seems suboptimal and is dragging down our coverage numbers over here in Flutter land because some of our libraries with 100% coverage actually score less than that and the only lines that aren't covered are the asserts.
The text was updated successfully, but these errors were encountered: