Open
Description
Doc comment for the collect
function states:
If [isolateIds] is set, the coverage gathering will be restricted to only those VM isolates.
This does not seem to be true. I'm trying to collect coverage from a single isolate, but the filter simply does not work and code executed on all isolates is included in the report.
Reproduction
- Create a new dart project with
dart create isolate_coverage_sample
- Replace the code inside
bin/isolate_coverage_sample.dart
with the code below:
import 'dart:developer';
import 'dart:isolate';
import 'package:coverage/coverage.dart';
import 'package:isolate_coverage_sample/calculate.dart';
import 'package:isolate_coverage_sample/isolate_calculate.dart';
Future<void> main(List<String> arguments) async {
calculate(); // This function is included by default in packages created using dart create
final isolate = await Isolate.spawn(
(_) => isolateCalculate(),
null,
paused: true,
);
final isolateId = Service.getIsolateId(isolate)!;
final info = await Service.controlWebServer(enable: true);
isolate.resume(isolate.pauseCapability!);
final coverage = await collect(
info.serverUri!,
true,
false,
false,
{'isolate_coverage_sample'},
isolateIds: {isolateId},
);
print(coverage.entries);
}
- Add a file
lib/isolate_calculate.dart
containing this code:
int isolateCalculate() {
return 6 * 7;
}
- While at the package's root, run:
dart --pause-isolates-on-exit bin/isolate_coverage_sample.dart
- Inspect the entries on the output. The file
package:isolate_coverage_sample/calculate.dart
is included in the coverage even though it was called on the main isolate.