Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

Victowolf
Copy link

@Victowolf Victowolf commented Mar 6, 2025

  • Thanks for your contribution! Please replace this text with a description of what this PR is changing or adding and why, list any relevant issues, and review the contribution guidelines below.

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Summary

This PR enhances package:coverage by adding support for detecting uncovered files.

Changes

  • Implemented logic to identify files that are missing from coverage reports.
  • Updated test cases to validate detection of all files.
  • Ensured compatibility with existing workflows.

Testing

  • Ran dart test and all tests passed successfully.

Issue Reference

Copy link
Contributor

@liamappelbe liamappelbe left a comment

Choose a reason for hiding this comment

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

This PR needs tests.

@@ -1,6 +1,8 @@
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
errors:
unnecessary_this: ignore
Copy link
Contributor

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.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change (from #2032 ?)

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this

@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 _getAllCoverage function actually returns, this filter definitely won't work as you intend. Did you test your code?

}) {
final pathFilter = _getPathFilter(
reportOn: reportOn,
ignoreGlobs: ignoreGlobs,
);
final buf = StringBuffer();

// Get all Dart files in the project
final allDartFiles = resolver.listAllDartFiles().toSet();
Copy link
Contributor

Choose a reason for hiding this comment

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

Lots of duplicated code between formatLcov and prettyPrint. Can you factorize them?

@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

If includeUncovered is null, then no uncovered files should be included. That's to ensure we don't change behavior for existing users.

@Deprecated('Use Resolver.create')
Resolver({this.packagesPath, this.sdkRoot})

Resolver
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you revert all these unrelated formatting changes?

{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 = '.'}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This util doesn't need to be on Resolver. It doesn't use any of the fields.

@Victowolf Victowolf closed this by deleting the head repository Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a tool to find uncovered files
2 participants