-
Notifications
You must be signed in to change notification settings - Fork 61
[coverage] Expose filterIgnored
function
#2123
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:coverage/coverage.dart' show Resolver; | ||
import 'package:coverage/src/hitmap.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
String fileUri(String relativePath) => | ||
Uri.file(File(relativePath).absolute.path).toString(); | ||
|
||
void main() { | ||
test('filter ignored', () async { | ||
// The ignored lines come from the comments in the test dart files. But the | ||
// hitmaps are fake, and don't have to correspond to real coverage data. | ||
final hitmaps = { | ||
fileUri('nonexistent_file.dart'): HitMap( | ||
{1: 1, 2: 2, 3: 3}, | ||
{1: 1, 2: 2, 3: 3}, | ||
{1: 'abc', 2: 'def'}, | ||
{1: 1, 2: 2, 3: 3}, | ||
), | ||
fileUri('another_nonexistent_file.dart'): HitMap( | ||
{1: 1, 2: 2, 3: 3}, | ||
), | ||
fileUri('test/test_files/test_app.dart'): HitMap( | ||
{1: 1, 2: 2, 3: 3}, | ||
{1: 1, 2: 2, 3: 3}, | ||
{1: 'abc', 2: 'def'}, | ||
{1: 1, 2: 2, 3: 3}, | ||
), | ||
fileUri('test/test_files/test_app_isolate.dart'): HitMap( | ||
{for (var i = 50; i < 100; ++i) i: i}, | ||
{for (var i = 50; i < 100; ++i) i: i}, | ||
{for (var i = 50; i < 100; ++i) i: '$i'}, | ||
{for (var i = 50; i < 100; ++i) i: i}, | ||
), | ||
}; | ||
|
||
// Lines ignored in test/test_files/test_app_isolate.dart. | ||
const ignores = [ | ||
52, | ||
54, | ||
55, | ||
56, | ||
57, | ||
58, | ||
63, | ||
64, | ||
65, | ||
66, | ||
67, | ||
68, | ||
69, | ||
70, | ||
71, | ||
72, | ||
73, | ||
]; | ||
|
||
final expected = { | ||
fileUri('nonexistent_file.dart'): HitMap( | ||
{1: 1, 2: 2, 3: 3}, | ||
{1: 1, 2: 2, 3: 3}, | ||
{1: 'abc', 2: 'def'}, | ||
{1: 1, 2: 2, 3: 3}, | ||
), | ||
fileUri('another_nonexistent_file.dart'): HitMap( | ||
{1: 1, 2: 2, 3: 3}, | ||
), | ||
fileUri('test/test_files/test_app_isolate.dart'): HitMap( | ||
{ | ||
for (var i = 50; i < 100; ++i) | ||
if (!ignores.contains(i)) i: i | ||
}, | ||
{ | ||
for (var i = 50; i < 100; ++i) | ||
if (!ignores.contains(i)) i: i | ||
}, | ||
{for (var i = 50; i < 100; ++i) i: '$i'}, | ||
{ | ||
for (var i = 50; i < 100; ++i) | ||
if (!ignores.contains(i)) i: i | ||
}, | ||
), | ||
}; | ||
|
||
final resolver = await Resolver.create(packagePath: '.'); | ||
|
||
final actual = | ||
hitmaps.filterIgnored(ignoredLinesInFilesCache: {}, resolver: resolver); | ||
|
||
expect(actual.keys.toList(), expected.keys.toList()); | ||
for (final source in expected.keys) { | ||
expect(actual[source]!.lineHits, expected[source]!.lineHits); | ||
expect(actual[source]!.funcHits, expected[source]!.funcHits); | ||
expect(actual[source]!.funcNames, expected[source]!.funcNames); | ||
expect(actual[source]!.branchHits, expected[source]!.branchHits); | ||
} | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there any chance that
this[0].isEmpty
?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.
No, every inner list has exactly 2 elements: the start and end of a range. It's a poorly designed API. I wanted to define a little
Range
class and change this to aList<Range>
, but unfortunately theList<List<int>>
type is exposed in the public API inparseJsonSync
'sMap<String, List<List<int>>?> ignoredLinesInFilesCache
, so that would be a breaking change. I've added it to my list of tech debt to clean up in v2.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.
Thanks for clarifying! But yeah, that's not great. I wonder why we didn't use a class in the first place... It'd be good to switch to a record type when we do plan for a v2 release.