Use libraryFilters flag to speed up coverage collection (#104122)
* Use libraryFilters flag to speed up coverage collection * Allow libraryNames to be null * Unconditionally enable the reportLines flag * Fix analysis errors
This commit is contained in:
@@ -16,7 +16,7 @@ void main() {
|
||||
requests: <VmServiceExpectation>[
|
||||
FakeVmServiceRequest(
|
||||
method: 'getVersion',
|
||||
jsonResponse: Version(major: 3, minor: 50).toJson(),
|
||||
jsonResponse: Version(major: 3, minor: 51).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getVM',
|
||||
@@ -42,7 +42,7 @@ void main() {
|
||||
|
||||
final Map<String, Object> result = await collect(
|
||||
null,
|
||||
(String predicate) => true,
|
||||
<String>{'foo'},
|
||||
connector: (Uri uri) async {
|
||||
return fakeVmServiceHost.vmService;
|
||||
},
|
||||
@@ -53,104 +53,6 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('Coverage collector processes coverage and script data', () async {
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
FakeVmServiceRequest(
|
||||
method: 'getVersion',
|
||||
jsonResponse: Version(major: 3, minor: 50).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getVM',
|
||||
jsonResponse: (VM.parse(<String, Object>{})
|
||||
..isolates = <IsolateRef>[
|
||||
IsolateRef.parse(<String, Object>{
|
||||
'id': '1',
|
||||
}),
|
||||
]
|
||||
).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getScripts',
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
},
|
||||
jsonResponse: ScriptList(scripts: <ScriptRef>[
|
||||
ScriptRef(uri: 'foo.dart', id: '1'),
|
||||
]).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getSourceReport',
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
'reports': <Object>['Coverage'],
|
||||
'scriptId': '1',
|
||||
'forceCompile': true,
|
||||
},
|
||||
jsonResponse: SourceReport(
|
||||
ranges: <SourceReportRange>[
|
||||
SourceReportRange(
|
||||
scriptIndex: 0,
|
||||
startPos: 0,
|
||||
endPos: 0,
|
||||
compiled: true,
|
||||
coverage: SourceReportCoverage(
|
||||
hits: <int>[],
|
||||
misses: <int>[],
|
||||
),
|
||||
),
|
||||
],
|
||||
scripts: <ScriptRef>[
|
||||
ScriptRef(
|
||||
uri: 'foo.dart',
|
||||
id: '1',
|
||||
),
|
||||
],
|
||||
).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getObject',
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
'objectId': '1',
|
||||
},
|
||||
jsonResponse: Script(
|
||||
uri: 'foo.dart',
|
||||
id: '1',
|
||||
library: LibraryRef(name: '', id: '1111', uri: 'foo.dart'),
|
||||
tokenPosTable: <List<int>>[],
|
||||
).toJson(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
final Map<String, Object> result = await collect(
|
||||
null,
|
||||
(String predicate) => true,
|
||||
connector: (Uri uri) async {
|
||||
return fakeVmServiceHost.vmService;
|
||||
},
|
||||
);
|
||||
|
||||
expect(result, <String, Object>{
|
||||
'type': 'CodeCoverage',
|
||||
'coverage': <Object>[
|
||||
<String, Object>{
|
||||
'source': 'foo.dart',
|
||||
'script': <String, Object>{
|
||||
'type': '@Script',
|
||||
'fixedId': true,
|
||||
'id': 'libraries/1/scripts/foo.dart',
|
||||
'uri': 'foo.dart',
|
||||
'_kind': 'library',
|
||||
},
|
||||
'hits': <Object>[],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(fakeVmServiceHost.hasRemainingExpectations, false);
|
||||
});
|
||||
|
||||
testWithoutContext('Coverage collector skips loading Script objects when reportLines is available', () async {
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
FakeVmServiceRequest(
|
||||
@@ -173,7 +75,8 @@ void main() {
|
||||
'isolateId': '1',
|
||||
},
|
||||
jsonResponse: ScriptList(scripts: <ScriptRef>[
|
||||
ScriptRef(uri: 'foo.dart', id: '1'),
|
||||
ScriptRef(uri: 'package:foo/foo.dart', id: '1'),
|
||||
ScriptRef(uri: 'package:bar/bar.dart', id: '2'),
|
||||
]).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
@@ -200,7 +103,7 @@ void main() {
|
||||
],
|
||||
scripts: <ScriptRef>[
|
||||
ScriptRef(
|
||||
uri: 'foo.dart',
|
||||
uri: 'package:foo/foo.dart',
|
||||
id: '1',
|
||||
),
|
||||
],
|
||||
@@ -211,7 +114,7 @@ void main() {
|
||||
|
||||
final Map<String, Object> result = await collect(
|
||||
null,
|
||||
(String predicate) => true,
|
||||
<String>{'foo'},
|
||||
connector: (Uri uri) async {
|
||||
return fakeVmServiceHost.vmService;
|
||||
},
|
||||
@@ -221,12 +124,293 @@ void main() {
|
||||
'type': 'CodeCoverage',
|
||||
'coverage': <Object>[
|
||||
<String, Object>{
|
||||
'source': 'foo.dart',
|
||||
'source': 'package:foo/foo.dart',
|
||||
'script': <String, Object>{
|
||||
'type': '@Script',
|
||||
'fixedId': true,
|
||||
'id': 'libraries/1/scripts/foo.dart',
|
||||
'uri': 'foo.dart',
|
||||
'id': 'libraries/1/scripts/package%3Afoo%2Ffoo.dart',
|
||||
'uri': 'package:foo/foo.dart',
|
||||
'_kind': 'library',
|
||||
},
|
||||
'hits': <Object>[1, 1, 3, 1, 2, 0],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(fakeVmServiceHost.hasRemainingExpectations, false);
|
||||
});
|
||||
|
||||
testWithoutContext('Coverage collector with null libraryNames accepts all libraries', () async {
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
FakeVmServiceRequest(
|
||||
method: 'getVersion',
|
||||
jsonResponse: Version(major: 3, minor: 51).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getVM',
|
||||
jsonResponse: (VM.parse(<String, Object>{})
|
||||
..isolates = <IsolateRef>[
|
||||
IsolateRef.parse(<String, Object>{
|
||||
'id': '1',
|
||||
}),
|
||||
]
|
||||
).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getScripts',
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
},
|
||||
jsonResponse: ScriptList(scripts: <ScriptRef>[
|
||||
ScriptRef(uri: 'package:foo/foo.dart', id: '1'),
|
||||
ScriptRef(uri: 'package:bar/bar.dart', id: '2'),
|
||||
]).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getSourceReport',
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
'reports': <Object>['Coverage'],
|
||||
'scriptId': '1',
|
||||
'forceCompile': true,
|
||||
'reportLines': true,
|
||||
},
|
||||
jsonResponse: SourceReport(
|
||||
ranges: <SourceReportRange>[
|
||||
SourceReportRange(
|
||||
scriptIndex: 0,
|
||||
startPos: 0,
|
||||
endPos: 0,
|
||||
compiled: true,
|
||||
coverage: SourceReportCoverage(
|
||||
hits: <int>[1, 3],
|
||||
misses: <int>[2],
|
||||
),
|
||||
),
|
||||
],
|
||||
scripts: <ScriptRef>[
|
||||
ScriptRef(
|
||||
uri: 'package:foo/foo.dart',
|
||||
id: '1',
|
||||
),
|
||||
],
|
||||
).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getSourceReport',
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
'reports': <Object>['Coverage'],
|
||||
'scriptId': '2',
|
||||
'forceCompile': true,
|
||||
'reportLines': true,
|
||||
},
|
||||
jsonResponse: SourceReport(
|
||||
ranges: <SourceReportRange>[
|
||||
SourceReportRange(
|
||||
scriptIndex: 0,
|
||||
startPos: 0,
|
||||
endPos: 0,
|
||||
compiled: true,
|
||||
coverage: SourceReportCoverage(
|
||||
hits: <int>[47, 21],
|
||||
misses: <int>[32, 86],
|
||||
),
|
||||
),
|
||||
],
|
||||
scripts: <ScriptRef>[
|
||||
ScriptRef(
|
||||
uri: 'package:bar/bar.dart',
|
||||
id: '2',
|
||||
),
|
||||
],
|
||||
).toJson(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
final Map<String, Object> result = await collect(
|
||||
null,
|
||||
null,
|
||||
connector: (Uri uri) async {
|
||||
return fakeVmServiceHost.vmService;
|
||||
},
|
||||
);
|
||||
|
||||
expect(result, <String, Object>{
|
||||
'type': 'CodeCoverage',
|
||||
'coverage': <Object>[
|
||||
<String, Object>{
|
||||
'source': 'package:foo/foo.dart',
|
||||
'script': <String, Object>{
|
||||
'type': '@Script',
|
||||
'fixedId': true,
|
||||
'id': 'libraries/1/scripts/package%3Afoo%2Ffoo.dart',
|
||||
'uri': 'package:foo/foo.dart',
|
||||
'_kind': 'library',
|
||||
},
|
||||
'hits': <Object>[1, 1, 3, 1, 2, 0],
|
||||
},
|
||||
<String, Object>{
|
||||
'source': 'package:bar/bar.dart',
|
||||
'script': <String, Object>{
|
||||
'type': '@Script',
|
||||
'fixedId': true,
|
||||
'id': 'libraries/1/scripts/package%3Abar%2Fbar.dart',
|
||||
'uri': 'package:bar/bar.dart',
|
||||
'_kind': 'library',
|
||||
},
|
||||
'hits': <Object>[47, 1, 21, 1, 32, 0, 86, 0],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(fakeVmServiceHost.hasRemainingExpectations, false);
|
||||
});
|
||||
|
||||
testWithoutContext('Coverage collector with libraryFilters', () async {
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
FakeVmServiceRequest(
|
||||
method: 'getVersion',
|
||||
jsonResponse: Version(major: 3, minor: 57).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getVM',
|
||||
jsonResponse: (VM.parse(<String, Object>{})
|
||||
..isolates = <IsolateRef>[
|
||||
IsolateRef.parse(<String, Object>{
|
||||
'id': '1',
|
||||
}),
|
||||
]
|
||||
).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getSourceReport',
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
'reports': <Object>['Coverage'],
|
||||
'forceCompile': true,
|
||||
'reportLines': true,
|
||||
'libraryFilters': <Object>['package:foo/'],
|
||||
},
|
||||
jsonResponse: SourceReport(
|
||||
ranges: <SourceReportRange>[
|
||||
SourceReportRange(
|
||||
scriptIndex: 0,
|
||||
startPos: 0,
|
||||
endPos: 0,
|
||||
compiled: true,
|
||||
coverage: SourceReportCoverage(
|
||||
hits: <int>[1, 3],
|
||||
misses: <int>[2],
|
||||
),
|
||||
),
|
||||
],
|
||||
scripts: <ScriptRef>[
|
||||
ScriptRef(
|
||||
uri: 'package:foo/foo.dart',
|
||||
id: '1',
|
||||
),
|
||||
],
|
||||
).toJson(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
final Map<String, Object> result = await collect(
|
||||
null,
|
||||
<String>{'foo'},
|
||||
connector: (Uri uri) async {
|
||||
return fakeVmServiceHost.vmService;
|
||||
},
|
||||
);
|
||||
|
||||
expect(result, <String, Object>{
|
||||
'type': 'CodeCoverage',
|
||||
'coverage': <Object>[
|
||||
<String, Object>{
|
||||
'source': 'package:foo/foo.dart',
|
||||
'script': <String, Object>{
|
||||
'type': '@Script',
|
||||
'fixedId': true,
|
||||
'id': 'libraries/1/scripts/package%3Afoo%2Ffoo.dart',
|
||||
'uri': 'package:foo/foo.dart',
|
||||
'_kind': 'library',
|
||||
},
|
||||
'hits': <Object>[1, 1, 3, 1, 2, 0],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(fakeVmServiceHost.hasRemainingExpectations, false);
|
||||
});
|
||||
|
||||
testWithoutContext('Coverage collector with libraryFilters and null libraryNames', () async {
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
FakeVmServiceRequest(
|
||||
method: 'getVersion',
|
||||
jsonResponse: Version(major: 3, minor: 57).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getVM',
|
||||
jsonResponse: (VM.parse(<String, Object>{})
|
||||
..isolates = <IsolateRef>[
|
||||
IsolateRef.parse(<String, Object>{
|
||||
'id': '1',
|
||||
}),
|
||||
]
|
||||
).toJson(),
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getSourceReport',
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
'reports': <Object>['Coverage'],
|
||||
'forceCompile': true,
|
||||
'reportLines': true,
|
||||
},
|
||||
jsonResponse: SourceReport(
|
||||
ranges: <SourceReportRange>[
|
||||
SourceReportRange(
|
||||
scriptIndex: 0,
|
||||
startPos: 0,
|
||||
endPos: 0,
|
||||
compiled: true,
|
||||
coverage: SourceReportCoverage(
|
||||
hits: <int>[1, 3],
|
||||
misses: <int>[2],
|
||||
),
|
||||
),
|
||||
],
|
||||
scripts: <ScriptRef>[
|
||||
ScriptRef(
|
||||
uri: 'package:foo/foo.dart',
|
||||
id: '1',
|
||||
),
|
||||
],
|
||||
).toJson(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
final Map<String, Object> result = await collect(
|
||||
null,
|
||||
null,
|
||||
connector: (Uri uri) async {
|
||||
return fakeVmServiceHost.vmService;
|
||||
},
|
||||
);
|
||||
|
||||
expect(result, <String, Object>{
|
||||
'type': 'CodeCoverage',
|
||||
'coverage': <Object>[
|
||||
<String, Object>{
|
||||
'source': 'package:foo/foo.dart',
|
||||
'script': <String, Object>{
|
||||
'type': '@Script',
|
||||
'fixedId': true,
|
||||
'id': 'libraries/1/scripts/package%3Afoo%2Ffoo.dart',
|
||||
'uri': 'package:foo/foo.dart',
|
||||
'_kind': 'library',
|
||||
},
|
||||
'hits': <Object>[1, 1, 3, 1, 2, 0],
|
||||
|
||||
Reference in New Issue
Block a user