Returns marked as uncoverable
If you have a code like this:
void f(int? i) {
if (i == null) {
return;
}
// work...
}
And you want to make sure you test the null case, you can't actually be sure it is covered, because the return is marked as uncoverable.
This is a request to start tracking it as coverable.
CC @liamappelbe
I found this odd too - you can't see which path was taken in code like this:
Although IIRC the same is true for things like var a = x ? 1 : 2 because coverage is all line-based right now.
I don't know whether the limitation is in pkg:coverage or in the data the VM collects though (I suspect the latter, but @liamappelbe would know for sure).
Yeah, it's a limitation in the VM. By default coverage is only tracked for function calls. If your return statement had a function call in it, it would be marked as coverable.
You can fix this by passing the --branch-coverage flag to the coverage:test_with_coverage script. The flag is plumbed through to both the VM and package:coverage. If you're using dart test you have to pass it to both the VM and test, so it looks like dart --branch-coverage test --branch-coverage 😅
In Dart 3.10 this flag is enabled by default in the VM, though I probably need to give a little more thought to whether I enable it by default in the test tools as well.
How are you running your tests, and what version of Dart are you using?
How are you running your tests, and what version of Dart are you using?
Was this question for me or @FMorschel? For my example above, I was using flutter test. We don't support coverage for Dart yet (we need a pkg:test release with your recent changes for that). We do pass --branch-coverage there already.