Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Branch coverage #361

Merged
merged 13 commits into from
Feb 25, 2022
Merged

Branch coverage #361

merged 13 commits into from
Feb 25, 2022

Conversation

liamappelbe
Copy link
Contributor

@liamappelbe liamappelbe commented Jan 19, 2022

Implement branch coverage, using the new branch coverage source report from the VM service API.

To collect branch coverage information, pass --branch-coverage to both collect_coverage and the Dart command you're gathering coverage from. Branch coverage information can be pretty printed or included in lcov info. You'll also need a very recent version of the VM (service API v3.56, Dart VM v2.17).

Fixes dart-lang/tools#575

@liamappelbe liamappelbe marked this pull request as ready for review February 24, 2022 18:45
@liamappelbe
Copy link
Contributor Author

I need to handle the case where the VM is too old and the branch coverage source report isn't available. Something analogous to how we check if reportLines is available in collect.dart. If it's not available, I'll need to report a warning to the user. I'll also need to disable all those failing tests for the v2.14.0 bot that's failing.

@liamappelbe
Copy link
Contributor Author

I need to handle the case where the VM is too old and the branch coverage source report isn't available. Something analogous to how we check if reportLines is available in collect.dart. If it's not available, I'll need to report a warning to the user. I'll also need to disable all those failing tests for the v2.14.0 bot that's failing.

Done

* Add flag `--pretty-print-branch` to format_coverage that works
similarly to pretty print, but outputs branch level coverage, rather than
line level.
* Update `--lcov` (abbr `-l`) in format_coverage to output branch level
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. I'm adding significant functionality, but not changing existing functionality, so I think that makes it a minor version bump.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does any of our internal testing infrastructure consume lcov reports? Will they be broken with the change in format? If not, then it's probably fine to model as a non breaking releases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lcov output was also modified when I added function coverage, and that didn't seem to be an issue, so I guess not.

@natebosch
Copy link
Contributor

Should we consider bumping the min SDK constraint in the pubspec?

@liamappelbe
Copy link
Contributor Author

Should we consider bumping the min SDK constraint in the pubspec?

Hmmm. Not sure about that. We'd be bumping to a version that isn't actually released yet. The latest version of the VM is only required for branch coverage. If most users don't use branch coverage, then it seems unnecessary to me.

return map;
});

if (platformVersionCheck(2, 17)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about making it a separate test and add skip: !platformVersionCheck(2, 17)? Tests should ideally have only 1 reason to fail.

go/unit-testing-practices#behavior-testing

If it's infeasible to split to separate tests, the expect call also has a skip argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


if (platformVersionCheck(2, 17)) {
// Dart VM versions before 2.17 don't support branch coverage.
for (var sampleCoverageData in sources[_sampleAppFileUri]!) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to avoid for loops in the tests. If this fails the message wont give much information.

We could do something like

expect(sources[_sampleAppFileUri], everyElement(containsPair('branchHits', isNotEmpty)));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -179,6 +179,11 @@ void main() {
28: 'fooAsync',
38: 'isolateTask'
});
if (platformVersionCheck(2, 17)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, can this be a separate test, or can you pass skip: !platformVersionCheck(2, 17) to the expect call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@coveralls
Copy link

coveralls commented Feb 25, 2022

Coverage Status

Coverage increased (+0.2%) to 90.559% when pulling d68ebff on branch_cov into 6e8a258 on master.

@liamappelbe liamappelbe merged commit 84f5ef3 into master Feb 25, 2022
@kevmoo kevmoo deleted the branch_cov branch January 25, 2023 02:54
mosuem pushed a commit to dart-lang/tools that referenced this pull request Aug 28, 2024
* WIP: branch coverage

* Pretty printing of branch coverage

* WIP: testing

* Finish testing

* Changelog and pubspec

* Warn user if their VM is too old to support branch coverage

* Update readme to mention function and branch coverage

* Fix some of the failing tests on older VM versions

* Fix run_and_collect_test

* Actually fix run_and_collect_test

* Use skips instead of ifs in tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add Branch and Function coverage to lcov output.
4 participants