-
Notifications
You must be signed in to change notification settings - Fork 51
Added uncovered files detection - Issue #529 #2029
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,10 @@ const _debugTokenPositions = bool.fromEnvironment('DEBUG_COVERAGE'); | |
/// If [scopedOutput] is non-empty, coverage will be restricted so that only | ||
/// scripts that start with any of the provided paths are considered. | ||
/// | ||
/// If [isolateIds] is set, the coverage gathering will be restricted to only | ||
/// those VM isolates. | ||
/// If [isolateIds] is set, coverage gathering **will not be restricted** to | ||
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. Unrelated change (from #2032 ?) |
||
/// only those VM isolates. Instead, coverage will be collected for | ||
/// **all isolates | ||
/// in the same isolate group** as the provided isolate(s). | ||
/// | ||
/// If [coverableLineCache] is set, the collector will avoid recompiling | ||
/// libraries it has already seen (see VmService.getSourceReport's | ||
|
@@ -56,11 +58,12 @@ const _debugTokenPositions = bool.fromEnvironment('DEBUG_COVERAGE'); | |
Future<Map<String, dynamic>> collect(Uri serviceUri, bool resume, | ||
bool waitPaused, bool includeDart, Set<String>? scopedOutput, | ||
{Set<String>? isolateIds, | ||
Duration? timeout, | ||
bool functionCoverage = false, | ||
bool branchCoverage = false, | ||
Map<String, Set<int>>? coverableLineCache, | ||
VmService? serviceOverrideForTesting}) async { | ||
Duration? timeout, | ||
bool functionCoverage = false, | ||
bool branchCoverage = false, | ||
Map<String, Set<int>>? coverableLineCache, | ||
VmService? serviceOverrideForTesting, | ||
bool Function(String)? filter}) async { // Correct function type | ||
scopedOutput ??= <String>{}; | ||
|
||
late VmService service; | ||
|
@@ -94,7 +97,7 @@ Future<Map<String, dynamic>> collect(Uri serviceUri, bool resume, | |
} | ||
|
||
try { | ||
return await _getAllCoverage( | ||
final coverageData = await _getAllCoverage( | ||
service, | ||
includeDart, | ||
functionCoverage, | ||
|
@@ -103,6 +106,13 @@ Future<Map<String, dynamic>> collect(Uri serviceUri, bool resume, | |
isolateIds, | ||
coverableLineCache, | ||
waitPaused); | ||
|
||
// Apply filtering if a filter function is provided | ||
if (filter != null) { | ||
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. What are these changes for? They seem unrelated to the PR. There's already a bunch of ways of filtering the coverage, so I'm not sure what this is for. If you check what the |
||
coverageData.removeWhere((key, value) => !filter(key)); | ||
} | ||
|
||
return coverageData; | ||
} finally { | ||
if (resume && !waitPaused) { | ||
await _resumeIsolates(service); | ||
|
@@ -113,6 +123,8 @@ Future<Map<String, dynamic>> collect(Uri serviceUri, bool resume, | |
} | ||
} | ||
|
||
|
||
|
||
Future<Map<String, dynamic>> _getAllCoverage( | ||
VmService service, | ||
bool includeDart, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
// 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. | ||
|
||
// ignore_for_file: unnecessary_this | ||
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. Remove this |
||
|
||
import 'package:glob/glob.dart'; | ||
import 'package:path/path.dart' as p; | ||
|
||
|
@@ -78,26 +80,27 @@ extension FileHitMapsFormatter on Map<String, HitMap> { | |
String? basePath, | ||
List<String>? reportOn, | ||
Set<Glob>? ignoreGlobs, | ||
bool Function(String path)? includeUncovered, | ||
}) { | ||
final pathFilter = _getPathFilter( | ||
reportOn: reportOn, | ||
ignoreGlobs: ignoreGlobs, | ||
); | ||
final buf = StringBuffer(); | ||
|
||
// Get all Dart files in the project | ||
final allDartFiles = resolver.listAllDartFiles().toSet(); | ||
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. Lots of duplicated code between |
||
final coveredFiles = this.keys.toSet(); | ||
final uncoveredFiles = allDartFiles.difference(coveredFiles); | ||
|
||
for (final entry in entries) { | ||
final v = entry.value; | ||
final lineHits = v.lineHits; | ||
final funcHits = v.funcHits; | ||
final funcNames = v.funcNames; | ||
final branchHits = v.branchHits; | ||
var source = resolver.resolve(entry.key); | ||
if (source == null) { | ||
continue; | ||
} | ||
|
||
if (!pathFilter(source)) { | ||
continue; | ||
} | ||
if (source == null || !pathFilter(source)) continue; | ||
|
||
if (basePath != null) { | ||
source = p.relative(source, from: basePath); | ||
|
@@ -129,6 +132,21 @@ extension FileHitMapsFormatter on Map<String, HitMap> { | |
buf.write('end_of_record\n'); | ||
} | ||
|
||
// Add uncovered files if allowed | ||
for (final file in uncoveredFiles) { | ||
if (includeUncovered != null && !includeUncovered(file)) continue; | ||
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. If |
||
var source = resolver.resolve(file); | ||
if (source == null || !pathFilter(source)) continue; | ||
if (basePath != null) { | ||
source = p.relative(source, from: basePath); | ||
} | ||
|
||
buf.write('SF:$source\n'); | ||
buf.write('LF:0\n'); | ||
buf.write('LH:0\n'); | ||
buf.write('end_of_record\n'); | ||
} | ||
|
||
return buf.toString(); | ||
} | ||
|
||
|
@@ -144,12 +162,19 @@ extension FileHitMapsFormatter on Map<String, HitMap> { | |
Set<Glob>? ignoreGlobs, | ||
bool reportFuncs = false, | ||
bool reportBranches = false, | ||
bool Function(String path)? includeUncovered, | ||
}) async { | ||
final pathFilter = _getPathFilter( | ||
reportOn: reportOn, | ||
ignoreGlobs: ignoreGlobs, | ||
); | ||
final buf = StringBuffer(); | ||
|
||
// Get all Dart files in the project | ||
final allDartFiles = resolver.listAllDartFiles().toSet(); | ||
final coveredFiles = this.keys.toSet(); | ||
final uncoveredFiles = allDartFiles.difference(coveredFiles); | ||
|
||
for (final entry in entries) { | ||
final v = entry.value; | ||
if (reportFuncs && v.funcHits == null) { | ||
|
@@ -171,18 +196,10 @@ extension FileHitMapsFormatter on Map<String, HitMap> { | |
? v.branchHits! | ||
: v.lineHits; | ||
final source = resolver.resolve(entry.key); | ||
if (source == null) { | ||
continue; | ||
} | ||
|
||
if (!pathFilter(source)) { | ||
continue; | ||
} | ||
if (source == null || !pathFilter(source)) continue; | ||
|
||
final lines = await loader.load(source); | ||
if (lines == null) { | ||
continue; | ||
} | ||
if (lines == null) continue; | ||
buf.writeln(source); | ||
for (var line = 1; line <= lines.length; line++) { | ||
var prefix = _prefix; | ||
|
@@ -193,6 +210,20 @@ extension FileHitMapsFormatter on Map<String, HitMap> { | |
} | ||
} | ||
|
||
// Add uncovered files if allowed | ||
for (final file in uncoveredFiles) { | ||
if (includeUncovered != null && !includeUncovered(file)) continue; | ||
final source = resolver.resolve(file); | ||
if (source == null || !pathFilter(source)) continue; | ||
|
||
final lines = await loader.load(source); | ||
if (lines == null) continue; | ||
buf.writeln(source); | ||
for (final line in lines) { | ||
buf.writeln(' |$line'); | ||
} | ||
} | ||
|
||
return buf.toString(); | ||
} | ||
} | ||
|
@@ -221,3 +252,4 @@ _PathFilter _getPathFilter({List<String>? reportOn, Set<Glob>? ignoreGlobs}) { | |
return true; | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,33 @@ import 'package:path/path.dart' as p; | |
|
||
/// [Resolver] resolves imports with respect to a given environment. | ||
class Resolver { | ||
|
||
@Deprecated('Use Resolver.create') | ||
Resolver({this.packagesPath, this.sdkRoot}) | ||
|
||
Resolver | ||
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. Can you revert all these unrelated formatting changes? |
||
({this.packagesPath, this.sdkRoot}) | ||
: _packages = packagesPath != null ? _parsePackages(packagesPath) : null, | ||
packagePath = null; | ||
|
||
Resolver._( | ||
Resolver._ | ||
( | ||
{this.packagesPath, | ||
this.packagePath, | ||
this.sdkRoot, | ||
Map<String, Uri>? packages}) | ||
: _packages = packages; | ||
/// Returns a list of all Dart files in the project. | ||
List<String> listAllDartFiles({String directoryPath = '.'}) { | ||
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. This util doesn't need to be on |
||
final dir = Directory(directoryPath); | ||
if (!dir.existsSync()) return []; | ||
|
||
return dir | ||
.listSync(recursive: true) | ||
.whereType<File>() | ||
.where((file) => file.path.endsWith('.dart')) | ||
.map((file) => file.path) | ||
.toList(); | ||
} | ||
|
||
static Future<Resolver> create({ | ||
String? packagesPath, | ||
|
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.
You can fix this lint, you don't need to add an exception.