test-coverage
test-coverage copied to clipboard
Null safety migration
This pull request removes discontinued lcov dependency and migrates the package to null safety.
Following Flutter guidelines, package version gets updated from 0.5.0 to 0.6.0
Closes #38 , #37, #33
Hmm, if I use 0.4.2, I can still see sub-100 coverage, like Overall line coverage rate: 94%., but if I checkout this branch, it just reads as 100%. Something will break --min-coverage usecase?
Does that behavior appear also if you checkout the master branch?
I am asking this because since you are referring to version 0.4.2 but master is at 0.5.0, the issue may be unrelated to this PR.
Yes, at commit 2bfaa88b9aa1fd0a3a921e6ead9ae59f54920224, I see Overall line coverage rate: 99%..
Ok, then I think creating a new issue may be the best way to go to keep track of everything in a dedicated thread. Let me know what you think about that.
Apologies, did I miscommunicate? The commit, 4bc829607f5aef3562528478c6aec39f8d1a4480, introduces the problem.
Are you still suggesting to file a new issue?
You can try this diff:
modified test/stub_package/lib/stub_package.dart
@@ -1,3 +1,7 @@
int add(int a, int b) {
return a + b;
}
+
+int subtract(int a, int b) {
+ return a - b;
+}
Then run dart run test_coverage --min-coverage=90 --no-badge. It correctly fails at 2bfaa88b9aa1fd0a3a921e6ead9ae59f54920224, since 50 is less than 90. But at 4bc829607f5aef3562528478c6aec39f8d1a4480, it incorrectly succeeds, with 100 >= 90.
Thank you very much for the additional information. I think I have understood now 👍
I can confirm that there was a problem with overall line coverage in commit 4bc829607f5aef3562528478c6aec39f8d1a4480. It should now be fixed.
I manually tested dart run test_coverage in the following cases:
- when total coverage is below the
--min-coveragethreshold - when a test fails
- when all tests succeed and coverage is >= than the threshold
All three cases produced the expected result (respectively failed, failed, succeeded)
You should not be experiencing the issue anymore. Can you verify?
Looks great!
% dart run test_coverage --no-badge --min-coverage=90
Found 2 test files.
Generated test-all script in test/.test_coverage.dart. Please make sure it is added to .gitignore.
Coverage report saved to "coverage/lcov.info".
Overall line coverage rate: 50%.
Overall coverage 50 is less than minimum required coverage 90
% echo $?
1
@pulyaevskiy Can we get this merged? or give some more direction if it needs changes.
@civts Would you be keen to publish a fork?
I haven't looked closer what was changed but there's already one fork: https://pub.dev/packages/test_cov
@jpnurmi from what I can see https://pub.dev/packages/test_cov diverged quite a bit from this implementation.
Even though it is indeed null-safe, --min-coverage option and badge generation do not appear to be supported there.
Looking around, I found another package, https://github.com/f3ath/check-coverage, which is meant to only check when the coverage is below a given threshold, without generating the report.
Given that, @QuirijnGB, I am thinking about making a new package from scratch that works similar to this one but does not require to generate the intemediate .test_coverage.dart file.
Let me know if have any thoughts on the idea and/or would like to contribute 👍🏻
https://github.com/civts/gen-coverage
@civts Oh, ok. I'm using Codecov + their ready-made GitHub Actions so all I needed was lcov.info. For me, test_cov was a drop-in replacement for test_coverage. Badges and options are provided by Codecov.
@jpnurmi For purely generating the lcov.info file, you may also consider making your package depend directly on test and coverage and generating the file with a script like the one below.
#Run tests and collect coverage info
dart run test --coverage .tempCoverageDir
#Generate lcov.info file in ./coverage
dart run coverage:format_coverage -l -c --report-on lib -i .tempCoverageDir --packages .packages -o coverage/lcov.info
#Clean up unneeded coverage info
rm -r .tempCoverageDir
Worth noting that both these packages are maintained by dart-lang.
Or just run dart run test_cov and be done with it 😏
Yep. I myself would prefer to have a package that takes care of everything for me.
On the other hand, I think those commands may be quite useful for making the CI pipelines more robust, so I included them anyway.
As for test_cov, I tried to run it in one project and it freezed 😅
Thanks, this pull request did the trick for me, the old code is no longer compatible with moor. The test_cov package did also not work for me. I enforced the pull request with:
test_coverage:
git:
url: https://github.com/civts/test-coverage.git
ref: aa6ffb41c28d7dec4e3bb11c3b7c4729e8271a69
in the pubspec.yaml
Edit: hopefully this PR gets merged soon.
why is taking so long to approve this pull request?
I do not know if this repository is being maintained anymore.
While I was waiting, I created my own package for generating the lcov.info file and enforcing minimum coverage.
If you want to give it a try, fork it or create a PR, this is the link https://github.com/civts/gen-coverage