Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 26d2176

Browse files
authored
Test that const decls are not marked coverable (#277)
Constant declarations are evaluated during kernel compilation, not by the VM. This patch adds a const to `test_app_isolate.dart` and verifies that it doesn't appear in the coverage hitmap in `collect_coverage_test.dart` and `run_and_collect_test.dart`.
1 parent e1b19ec commit 26d2176

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed

test/collect_coverage_api_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ void main() {
8686
final Map<String, dynamic> isolateCoverage =
8787
_getScriptCoverage(coverage, 'test_app_isolate.dart');
8888
hits = isolateCoverage['hits'];
89-
_expectHitCount(hits, 9, 1);
90-
_expectHitCount(hits, 16, 1);
89+
_expectHitCount(hits, 11, 1);
90+
_expectHitCount(hits, 18, 1);
9191
});
9292
}
9393

test/collect_coverage_test.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,31 @@ void main() {
5757

5858
final Map<int, int> isolateFile = hitMap[_isolateLibFileUri];
5959
final Map<int, int> expectedHits = {
60-
10: 1,
61-
11: 1,
62-
13: 0,
63-
17: 1,
64-
18: 1,
65-
20: 0,
66-
27: 1,
60+
12: 1,
61+
13: 1,
62+
15: 0,
63+
19: 1,
64+
20: 1,
65+
22: 0,
6766
29: 1,
68-
30: 2,
6967
31: 1,
70-
32: 3,
68+
32: 2,
7169
33: 1,
70+
34: 3,
71+
35: 1,
7272
};
7373
if (Platform.version.startsWith('1.')) {
7474
// Dart VMs prior to 2.0.0-dev.5.0 contain a bug that emits coverage on the
7575
// closing brace of async function blocks.
7676
// See: https://github.com/dart-lang/coverage/issues/196
77-
expectedHits[21] = 0;
77+
expectedHits[23] = 0;
7878
} else {
7979
// Dart VMs version 2.0.0-dev.6.0 mark the opening brace of a function as
8080
// coverable.
81-
expectedHits[9] = 1;
82-
expectedHits[16] = 1;
83-
expectedHits[26] = 1;
84-
expectedHits[30] = 3;
81+
expectedHits[11] = 1;
82+
expectedHits[18] = 1;
83+
expectedHits[28] = 1;
84+
expectedHits[32] = 3;
8585
}
8686
expect(isolateFile, expectedHits);
8787
});

test/run_and_collect_test.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,31 @@ void main() {
4545

4646
final Map<int, int> isolateFile = hitMap[_isolateLibFileUri];
4747
final Map<int, int> expectedHits = {
48-
10: 1,
49-
11: 1,
50-
13: 0,
51-
17: 1,
52-
18: 1,
53-
20: 0,
54-
27: 1,
48+
12: 1,
49+
13: 1,
50+
15: 0,
51+
19: 1,
52+
20: 1,
53+
22: 0,
5554
29: 1,
56-
30: 2,
5755
31: 1,
58-
32: 3,
56+
32: 2,
5957
33: 1,
58+
34: 3,
59+
35: 1,
6060
};
6161
// Dart VMs prior to 2.0.0-dev.5.0 contain a bug that emits coverage on the
6262
// closing brace of async function blocks.
6363
// See: https://github.com/dart-lang/coverage/issues/196
6464
if (Platform.version.startsWith('1.')) {
65-
expectedHits[21] = 0;
65+
expectedHits[23] = 0;
6666
} else {
6767
// Dart VMs version 2.0.0-dev.6.0 mark the opening brace of a function as
6868
// coverable.
69-
expectedHits[9] = 1;
70-
expectedHits[16] = 1;
71-
expectedHits[26] = 1;
72-
expectedHits[30] = 3;
69+
expectedHits[11] = 1;
70+
expectedHits[18] = 1;
71+
expectedHits[28] = 1;
72+
expectedHits[32] = 3;
7373
}
7474
expect(isolateFile, expectedHits);
7575
});

test/test_files/test_app_isolate.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ import 'dart:async';
66
import 'dart:io';
77
import 'dart:isolate';
88

9+
const int answer = 42;
10+
911
String fooSync(int x) {
10-
if (x == 42) {
12+
if (x == answer) {
1113
return '*' * x;
1214
}
1315
return List.generate(x, (_) => 'xyzzy').join(' ');
1416
}
1517

1618
Future<String> fooAsync(int x) async {
17-
if (x == 42) {
19+
if (x == answer) {
1820
return '*' * x;
1921
}
2022
return List.generate(x, (_) => 'xyzzy').join(' ');
@@ -26,8 +28,8 @@ Future<String> fooAsync(int x) async {
2628
void isolateTask(dynamic threeThings) {
2729
sleep(const Duration(milliseconds: 500));
2830

29-
fooSync(42);
30-
fooAsync(42).then((_) {
31+
fooSync(answer);
32+
fooAsync(answer).then((_) {
3133
final SendPort port = threeThings.first;
3234
final int sum = threeThings[1] + threeThings[2];
3335
port.send(sum);

0 commit comments

Comments
 (0)