Skip to content

Conversation

liamappelbe
Copy link
Contributor

@liamappelbe liamappelbe commented Jul 9, 2025

  • Add a --coverage-path option to dart test, which takes a filename. This option works like --coverage, except that instead of generating multiple JSON reports, it generates a single LCOV report.
    • Aside from plumbing, the main change is in pkgs/test_core/lib/src/runner/coverage.dart's coverage collection functions, and how pkgs/test_core/lib/src/runner/engine.dart invokes them.
    • In LCOV mode, writeCoverage is still called, but doesn't write the JSON file. Instead it returns the generated coverage report. The Engine merges all these coverage reports into _allCoverageData, and once all the tests are done it calls writeCoverageLcov to finalize the report and write it to the lcov file.
  • Add a --branch-coverage flag that is plumbed through to collect's branchCoverage param.
  • Update the README to mention the --coverage-path workflow.
  • Set collect's scopedOutput param to the current package name. This front load the filtering of the coverage report, improving performance by removing unnecessary information as early as possible.
  • The test util runPub was using the deprecated standalone pub tool. This didn't cause problems because it was dead code. But I had to use it in the new tests, so I updated it to use dart pub.

Fixes #2511

Copy link

github-actions bot commented Jul 9, 2025

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

@liamappelbe

This comment was marked as resolved.

@liamappelbe liamappelbe changed the title WIP: Add --coverage-lcov and --branch-cov options Add --coverage-lcov and --branch-cov options Jul 11, 2025
@liamappelbe liamappelbe marked this pull request as ready for review July 11, 2025 04:23
@liamappelbe liamappelbe requested a review from a team as a code owner July 11, 2025 04:23
@liamappelbe liamappelbe changed the title Add --coverage-lcov and --branch-cov options Add --coverage-lcov and --branch-coverage options Jul 13, 2025
@liamappelbe liamappelbe requested a review from jakemac53 July 14, 2025 03:00
@liamappelbe
Copy link
Contributor Author

The remaining test failures don't seem related to this PR

@liamappelbe liamappelbe requested a review from natebosch July 21, 2025 00:37
@liamappelbe
Copy link
Contributor Author

This is ready for review. @jakemac53 @natebosch PTAL.

@liamappelbe
Copy link
Contributor Author

@jakemac53 @natebosch Friendly ping

@jakemac53 jakemac53 removed their request for review August 4, 2025 16:24
@jakemac53
Copy link
Contributor

Just FYI I am no longer officially on this project and don't have time to do reviews at the moment 😭 .

Copy link
Member

@natebosch natebosch left a comment

Choose a reason for hiding this comment

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

I think if we rename --coverage-lcov to --coverage-path as mentioned on the issue we'll be pretty well set up to normalize things in the future. It's a bit less obvious in the mean time, but I think it'll be a better place to end up long term.

@liamappelbe liamappelbe merged commit 9354f23 into master Aug 7, 2025
59 checks passed
@liamappelbe liamappelbe deleted the coverage_update branch August 7, 2025 02:56
@liamappelbe liamappelbe changed the title Add --coverage-lcov and --branch-coverage options Add --coverage-path and --branch-coverage options Aug 7, 2025
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 7, 2025
Revisions updated by `dart tools/rev_sdk_deps.dart`.

dartdoc (https://github.com/dart-lang/dartdoc/compare/414953e..82b48b5):
  82b48b53  2025-08-05  István Soós  Update highlight.js download instructions and resources. (dart-lang/dartdoc#4081)

ecosystem (https://github.com/dart-lang/ecosystem/compare/2fe3618..4543c38):
  4543c38  2025-08-06  Devon Carew  address a `Bad state: No element` element exception (dart-lang/ecosystem#321)
  e14472f  2025-08-06  Devon Carew  add a roadmap to our various mono-repos (dart-lang/ecosystem#318)
  e83479a  2025-08-06  Moritz  Fixes to health (dart-lang/ecosystem#363)
  552f534  2025-08-06  Moritz  Update API tool hash (dart-lang/ecosystem#362)

i18n (https://github.com/dart-lang/i18n/compare/c45e050..25cdb1b):
  25cdb1b4  2025-08-07  Moritz  Reenable mac size checks (dart-lang/i18n#1001)

shelf (https://github.com/dart-lang/shelf/compare/082d3ac..2a46b4f):
  2a46b4f  2025-08-05  Kevin Moore  Update dependencies across 3 packages (dart-lang/shelf#479)

test (https://github.com/dart-lang/test/compare/5aef971..9354f23):
  9354f239  2025-08-07  Liam Appelbe  Add `--coverage-path` and `--branch-coverage` options (dart-lang/test#2517)

tools (https://github.com/dart-lang/tools/compare/5e977d6..1b52e89):
  1b52e89e  2025-08-06  Moritz  Configure Gemini code review (dart-lang/tools#2141)

web (https://github.com/dart-lang/web/compare/1d5771b..f3c960f):
  f3c960f  2025-08-06  Nikechukwu  [web_generator] Add support for passing files as globs (dart-lang/web#427)
  f51cc85  2025-08-06  Nikechukwu  [interop] Add Support for Namespaces (dart-lang/web#436)

webdev (https://github.com/dart-lang/webdev/compare/7ff2d07..94c172c):
  94c172cc  2025-08-05  Nicholas Shahan  Wait for any remaining output in e2e_test.dart (dart-lang/webdev#2663)

Change-Id: Ie18635903f7379bc27e7ae23b916e10e4bdcef94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444360
Auto-Submit: Devon Carew <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 7, 2025
… webdev"

This reverts commit 00240e8.

Reason for revert: failures on HHH

Original change's description:
> [deps] rev dartdoc, ecosystem, i18n, shelf, test, tools, web, webdev
>
> Revisions updated by `dart tools/rev_sdk_deps.dart`.
>
> dartdoc (https://github.com/dart-lang/dartdoc/compare/414953e..82b48b5):
>   82b48b53  2025-08-05  István Soós  Update highlight.js download instructions and resources. (dart-lang/dartdoc#4081)
>
> ecosystem (https://github.com/dart-lang/ecosystem/compare/2fe3618..4543c38):
>   4543c38  2025-08-06  Devon Carew  address a `Bad state: No element` element exception (dart-lang/ecosystem#321)
>   e14472f  2025-08-06  Devon Carew  add a roadmap to our various mono-repos (dart-lang/ecosystem#318)
>   e83479a  2025-08-06  Moritz  Fixes to health (dart-lang/ecosystem#363)
>   552f534  2025-08-06  Moritz  Update API tool hash (dart-lang/ecosystem#362)
>
> i18n (https://github.com/dart-lang/i18n/compare/c45e050..25cdb1b):
>   25cdb1b4  2025-08-07  Moritz  Reenable mac size checks (dart-lang/i18n#1001)
>
> shelf (https://github.com/dart-lang/shelf/compare/082d3ac..2a46b4f):
>   2a46b4f  2025-08-05  Kevin Moore  Update dependencies across 3 packages (dart-lang/shelf#479)
>
> test (https://github.com/dart-lang/test/compare/5aef971..9354f23):
>   9354f239  2025-08-07  Liam Appelbe  Add `--coverage-path` and `--branch-coverage` options (dart-lang/test#2517)
>
> tools (https://github.com/dart-lang/tools/compare/5e977d6..1b52e89):
>   1b52e89e  2025-08-06  Moritz  Configure Gemini code review (dart-lang/tools#2141)
>
> web (https://github.com/dart-lang/web/compare/1d5771b..f3c960f):
>   f3c960f  2025-08-06  Nikechukwu  [web_generator] Add support for passing files as globs (dart-lang/web#427)
>   f51cc85  2025-08-06  Nikechukwu  [interop] Add Support for Namespaces (dart-lang/web#436)
>
> webdev (https://github.com/dart-lang/webdev/compare/7ff2d07..94c172c):
>   94c172cc  2025-08-05  Nicholas Shahan  Wait for any remaining output in e2e_test.dart (dart-lang/webdev#2663)
>
> Change-Id: Ie18635903f7379bc27e7ae23b916e10e4bdcef94
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444360
> Auto-Submit: Devon Carew <[email protected]>
> Commit-Queue: Konstantin Shcheglov <[email protected]>
> Reviewed-by: Konstantin Shcheglov <[email protected]>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I239eff7add9e5432c67b05c8f7731e1a79d4e4db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444387
Bot-Commit: Rubber Stamper <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Rubber Stamper <[email protected]>
Auto-Submit: Devon Carew <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Alexander Aprelev <[email protected]>
@natebosch
Copy link
Member

This may need some attention before we can publish it. The dependency on package:coverage from lib/src/runner/coverage.dart causes a cycle in the targets split out for blaze.

@liamappelbe
Copy link
Contributor Author

This may need some attention before we can publish it. The dependency on package:coverage from lib/src/runner/coverage.dart causes a cycle in the targets split out for blaze.

Can you give some more details? package:coverage doesn't depend on package:test afaik (aside from a dev dep)

@natebosch
Copy link
Member

Ah sorry I should have updated this issue - after I dug further I found it wasn't a cycle and we just needed a tweak in the build targets to fix the config around a conditional import. No worries here - I have the roll to google3 working.

copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Sep 8, 2025
Revisions updated by `dart tools/rev_sdk_deps.dart`.

test (https://github.com/dart-lang/test/compare/5aef971..b99d556):
  b99d556  2025-09-01  dependabot[bot]  Bump the github-actions group across 1 directory with 3 updates (dart-lang/test#2534)
  abe4939b  2025-08-27  Nate Bosch  Remove executable argument forwarding in tests (dart-lang/test#2533)
  81e0579c  2025-08-26  Ömer Sinan Ağacan  Serve dart2wasm source map files (dart-lang/test#2532)
  9354f239  2025-08-07  Liam Appelbe  Add `--coverage-path` and `--branch-coverage` options (dart-lang/test#2517)

Change-Id: I7297cc534d03de343218c829a8e94d70ba35a023
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448423
Auto-Submit: Devon Carew <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
@alexmarkov
Copy link

It looks like this PR broke Flutter build (after package:test was rolled to Dart SDK):

[10037/10156] ACTION //flutter/testing/dart:compile_assets_test.dart(//build/toolchain/linux:clang_x64)
FAILED: gen/assets_test.dart.dill 
vpython3 ../../flutter/third_party/dart/build/gn_run_binary.py compiled_action ../../flutter/third_party/dart/tools/sdks/dart-sdk/bin/dart --dfe=../../flutter/third_party/dart/tools/sdks/dart-sdk/bin/snapshots/kernel-service.dart.snapshot ../../flutter/third_party/dart/pkg/frontend_server/bin/frontend_server_starter.dart -DkFlutterSrcDirectory=/b/s/w/ir/cache/builder/flutter/engine/src/flutter -DkFlutterBuildDirectory=/b/s/w/ir/cache/builder/flutter/engine/src/out/host_debug_unopt/gen -DkSkiaGoldWorkDirectory=/b/s/w/ir/cache/builder/flutter/engine/src/out/host_debug_unopt/gen/skia_gold_assets_test.dart --packages /b/s/w/ir/cache/builder/flutter/engine/src/flutter/.dart_tool/package_config.json --sdk-root flutter_patched_sdk --target=flutter --depfile gen/assets_test.dart.dill.d --output-dill gen/assets_test.dart.dill ../../flutter/testing/dart/assets_test.dart
Command failed: /b/s/w/ir/cache/builder/flutter/engine/src/flutter/third_party/dart/tools/sdks/dart-sdk/bin/dart --dfe=../../flutter/third_party/dart/tools/sdks/dart-sdk/bin/snapshots/kernel-service.dart.snapshot ../../flutter/third_party/dart/pkg/frontend_server/bin/frontend_server_starter.dart -DkFlutterSrcDirectory=/b/s/w/ir/cache/builder/flutter/engine/src/flutter -DkFlutterBuildDirectory=/b/s/w/ir/cache/builder/flutter/engine/src/out/host_debug_unopt/gen -DkSkiaGoldWorkDirectory=/b/s/w/ir/cache/builder/flutter/engine/src/out/host_debug_unopt/gen/skia_gold_assets_test.dart --packages /b/s/w/ir/cache/builder/flutter/engine/src/flutter/.dart_tool/package_config.json --sdk-root flutter_patched_sdk --target=flutter --depfile gen/assets_test.dart.dill.d --output-dill gen/assets_test.dart.dill ../../flutter/testing/dart/assets_test.dart
exitCode: 254
output: result 22932273-0a39-494a-9f33-4d23e514ffc2
../../flutter/third_party/dart/third_party/pkg/test/pkgs/test_core/lib/src/runner/coverage.dart:43:48: Error: The method 'filterIgnored' isn't defined for the type 'Map<String, HitMap>'.
 - 'Map' is from 'dart:core'.
 - 'HitMap' is from 'package:coverage/src/hitmap.dart' ('../../flutter/third_party/pkg/coverage/lib/src/hitmap.dart').
Try correcting the name to the name of an existing method, or defining a method named 'filterIgnored'.
  final filteredCoverageData = allCoverageData.filterIgnored(

full log

copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Sep 10, 2025
This reverts commit caece5d.

Reason for revert: broke Flutter build (dart-lang/test#2517 (comment))

Original change's description:
> [deps] rev test
>
> Revisions updated by `dart tools/rev_sdk_deps.dart`.
>
> test (https://github.com/dart-lang/test/compare/5aef971..b99d556):
>   b99d556  2025-09-01  dependabot[bot]  Bump the github-actions group across 1 directory with 3 updates (dart-lang/test#2534)
>   abe4939b  2025-08-27  Nate Bosch  Remove executable argument forwarding in tests (dart-lang/test#2533)
>   81e0579c  2025-08-26  Ömer Sinan Ağacan  Serve dart2wasm source map files (dart-lang/test#2532)
>   9354f239  2025-08-07  Liam Appelbe  Add `--coverage-path` and `--branch-coverage` options (dart-lang/test#2517)
>
> Change-Id: I7297cc534d03de343218c829a8e94d70ba35a023
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448423
> Auto-Submit: Devon Carew <[email protected]>
> Reviewed-by: Konstantin Shcheglov <[email protected]>
> Commit-Queue: Konstantin Shcheglov <[email protected]>

Change-Id: I5404155f0de9330d37ff74741dd64a1a8d0436d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448906
Reviewed-by: Alexander Aprelev <[email protected]>
Bot-Commit: Rubber Stamper <[email protected]>
Commit-Queue: Alexander Markov <[email protected]>
@DanTup
Copy link
Contributor

DanTup commented Sep 15, 2025

@liamappelbe pkg:test in the SDK has been updated now (since @alexmarkov's comment above, it re-landed in 277c4a1f50826c8bab1bdbd73ea586f3cba8c8a0 and has rolled into Flutter successfully).

However, when using a bleeding-edge build based on 44207f801bafa97152a722bc794a22d67719a7e5 I get errors that --coverage-path is not valid:

PS D:\Dev\Test Projects\dartcode_5693> dart --version
Dart SDK version: 3.10.0-edge.44207f801bafa97152a722bc794a22d67719a7e5 (main) (Mon Sep 15 06:20:22 2025 -0700) on "windows_x64"


PS D:\Dev\Test Projects\dartcode_5693> dart test --coverage-path x.y .\test\foo5_test.dart
Could not find an option named "--coverage-path".

Usage: dart test [files or directories...]

-h, --help                            Show this usage information.
    --version                         Show the package:test version.

My first thought was that the dart test command in pkg:dartdev was doing its own parsing of args, but I see it's using ArgParser.allowAnything(). Any ideas why this might not work?

@DanTup
Copy link
Contributor

DanTup commented Sep 15, 2025

Oh, never mind - this is because it depends on the version of pkg:test my project is using, not what was in the SDK. I'll test it using a git dependency, and wait for a new pkg:test release before shipping anything. Thanks!

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.

Align dart test --coverage with package:coverage's test_with_coverage and flutter test --coverage
5 participants