This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Apply --scope-output
filters after getSourceReport
#498
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8756c9c
Add a test, but without the fix
liamappelbe e54a673
fmt
liamappelbe bd3638b
Now apply the fix
liamappelbe e0b07b2
Changelog
liamappelbe fa250dd
Merge branch 'master' into fix495
liamappelbe 6ce09b9
Ben's comments
liamappelbe 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 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 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 |
---|---|---|
|
@@ -178,11 +178,8 @@ Future<Map<String, dynamic>> _getAllCoverage( | |
continue; | ||
} | ||
for (final script in scripts.scripts!) { | ||
final uri = Uri.parse(script.uri!); | ||
if (uri.scheme != 'package') continue; | ||
final scope = uri.path.split('/').first; | ||
// Skip scripts which should not be included in the report. | ||
if (!scopedOutput.contains(scope)) continue; | ||
if (!scopedOutput.includesScript(script.uri)) continue; | ||
late final SourceReport scriptReport; | ||
try { | ||
scriptReport = await service.getSourceReport( | ||
|
@@ -203,7 +200,8 @@ Future<Map<String, dynamic>> _getAllCoverage( | |
includeDart, | ||
functionCoverage, | ||
reportLines, | ||
coverableLineCache); | ||
coverableLineCache, | ||
scopedOutput); | ||
allCoverage.addAll(coverage); | ||
} | ||
} else { | ||
|
@@ -229,7 +227,8 @@ Future<Map<String, dynamic>> _getAllCoverage( | |
includeDart, | ||
functionCoverage, | ||
reportLines, | ||
coverableLineCache); | ||
coverableLineCache, | ||
scopedOutput); | ||
allCoverage.addAll(coverage); | ||
} | ||
} | ||
|
@@ -312,7 +311,8 @@ Future<List<Map<String, dynamic>>> _processSourceReport( | |
bool includeDart, | ||
bool functionCoverage, | ||
bool reportLines, | ||
Map<String, Set<int>>? coverableLineCache) async { | ||
Map<String, Set<int>>? coverableLineCache, | ||
Set<String> scopedOutput) async { | ||
final hitMaps = <Uri, HitMap>{}; | ||
final scripts = <ScriptRef, Script>{}; | ||
final libraries = <LibraryRef>{}; | ||
|
@@ -362,8 +362,14 @@ Future<List<Map<String, dynamic>>> _processSourceReport( | |
|
||
for (var range in report.ranges!) { | ||
final scriptRef = report.scripts![range.scriptIndex!]; | ||
final scriptUriString = scriptRef.uri!; | ||
final scriptUri = Uri.parse(scriptUriString); | ||
final scriptUriString = scriptRef.uri; | ||
if (!scopedOutput.includesScript(scriptUriString)) { | ||
// Sometimes a range's script can be different to the function's script | ||
// (eg mixins), so we have to re-check the scope filter. | ||
// See https://github.com/dart-lang/coverage/issues/495 | ||
continue; | ||
} | ||
final scriptUri = Uri.parse(scriptUriString!); | ||
|
||
// If we have a coverableLineCache, use it in the same way we use | ||
// SourceReportCoverage.misses: to add zeros to the coverage result for all | ||
|
@@ -497,3 +503,14 @@ class StdoutLog extends Log { | |
@override | ||
void severe(String message) => print(message); | ||
} | ||
|
||
extension _ScopedOutput on Set<String> { | ||
bool includesScript(String? scriptUriString) { | ||
if (scriptUriString == null) return false; | ||
if (isEmpty) return true; | ||
final scriptUri = Uri.parse(scriptUriString); | ||
if (scriptUri.scheme != 'package') return false; | ||
final scope = scriptUri.path.split('/').first; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
return contains(scope); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -628,5 +628,52 @@ void main() { | |
'package:baz/baz.dart': {36, 81}, | ||
}); | ||
}); | ||
|
||
test( | ||
'Collect coverage, scoped output, library filters, ' | ||
'handles SourceReports that contain unfiltered ranges', () async { | ||
// Regression test for https://github.com/dart-lang/coverage/issues/495 | ||
final service = _mockService(3, 57); | ||
when(service.getSourceReport('isolate', ['Coverage'], | ||
forceCompile: true, | ||
reportLines: true, | ||
libraryFilters: ['package:foo/'])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ubernit: consider adding trailing commas for formatting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
.thenAnswer((_) async => SourceReport( | ||
ranges: [ | ||
_range( | ||
0, | ||
SourceReportCoverage( | ||
hits: [12], | ||
misses: [47], | ||
), | ||
), | ||
_range( | ||
1, | ||
SourceReportCoverage( | ||
hits: [86], | ||
misses: [91], | ||
), | ||
), | ||
], | ||
scripts: [ | ||
ScriptRef( | ||
uri: 'package:foo/foo.dart', | ||
id: 'foo', | ||
), | ||
ScriptRef( | ||
uri: 'package:bar/bar.dart', | ||
id: 'bar', | ||
), | ||
], | ||
)); | ||
|
||
final jsonResult = await collect(Uri(), false, false, false, {'foo'}, | ||
serviceOverrideForTesting: service); | ||
final result = await HitMap.parseJson( | ||
jsonResult['coverage'] as List<Map<String, dynamic>>); | ||
|
||
expect(result.length, 1); | ||
expect(result['package:foo/foo.dart']?.lineHits, {12: 1, 47: 0}); | ||
}); | ||
}); | ||
} |
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.
Shouldn't this return false if the set is empty? If not, can you leave a comment explaining why we're considering an empty set to include all scripts?
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.
Added a comment
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! That makes sense.