Skip to content
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

--scope-output does not work #530

Closed
gogolon opened this issue Jul 29, 2024 · 2 comments · Fixed by dart-archive/coverage#498
Closed

--scope-output does not work #530

gogolon opened this issue Jul 29, 2024 · 2 comments · Fixed by dart-archive/coverage#498

Comments

@gogolon
Copy link
Contributor

gogolon commented Jul 29, 2024

Sometimes coverage is gathered from external packages even when --scope-output flag is used and set to the name of the app's package.

Reproduction

  1. Create a new dart project with dart create minimal-sample
  2. Add equatable package: dart pub add equatable
  3. Replace the code inside lib/minimal_sample.dart with the code below:
import 'package:equatable/equatable.dart';

class SomeClass with EquatableMixin {
  @override
  List<Object?> get props => [];
}

int calculate() {
  return 6 * 7;
}
  1. run
dart run --pause-isolates-on-exit --disable-service-auth-codes --enable-vm-service=8181 test &
dart pub global run coverage:collect_coverage --wait-paused --uri=http://127.0.0.1:8181/ -o coverage/coverage.json --resume-isolates --scope-output=minimal_sample

After performing the steps above, the generated coverage/coverage.json looks like this:

{
  "type": "CodeCoverage",
  "coverage": [
    {
      "source": "package:minimal_sample/minimal_sample.dart",
      "script": {
        "type": "@Script",
        "fixedId": true,
        "id": "libraries/1/scripts/package%3Aminimal_sample%2Fminimal_sample.dart",
        "uri": "package:minimal_sample/minimal_sample.dart",
        "_kind": "library"
      },
      "hits": [
        4,
        0,
        5,
        0,
        8,
        1,
        9,
        1
      ]
    },
    {
      "source": "package:equatable/src/equatable_mixin.dart",
      "script": {
        "type": "@Script",
        "fixedId": true,
        "id": "libraries/1/scripts/package%3Aequatable%2Fsrc%2Fequatable_mixin.dart",
        "uri": "package:equatable/src/equatable_mixin.dart",
        "_kind": "library"
      },
      "hits": [
        16,
        0,
        18,
        0,
        21,
        0,
        22,
        0,
        23,
        0,
        26,
        0,
        27,
        0,
        29,
        0,
        31,
        0,
        32,
        0,
        33,
        0,
        34,
        0,
        35,
        0,
        37,
        0,
        38,
        0,
        39,
        0
      ]
    }
  ]
}

I use Dart SDK 3.3.3.

@liamappelbe
Copy link
Contributor

There are 2 ways of filtering the output, collect_coverage's --scope-output flag, and format_coverage's --report-on flag. scope-output is passed to the VM, and used to filter which libraries are collected. Due to the way mixins work (essentially copy/pasting their code into the child class), when it reports on SomeClass, it also reports on EquatableMixin. report-on works purely within package:coverage, and doesn't understand language constructs like mixins, so it will filter out EquatableMixin.

I can probably fix the VM logic to be stricter about applying the filters to mixins. In the meantime, you can use --report-on to further filter the result.

@liamappelbe
Copy link
Contributor

Took another look at how the source report is implemented in the VM, and it's not going to be easy to fix it in there. Better to apply the filters to the report returned by the VM (in addition to passing the filters to the VM).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants