Skip to content

Commit 5eaccc2

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
[CFE] Incremental test suite now has expect files
Change-Id: I704b87d56686cb282898511fb95d6b47ee9a1c9a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124323 Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent ec0d042 commit 5eaccc2

159 files changed

Lines changed: 3986 additions & 12 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pkg/front_end/test/incremental_load_from_dill_suite.dart

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ main([List<String> arguments = const []]) =>
7676

7777
Future<Context> createContext(
7878
Chain suite, Map<String, String> environment) async {
79-
return new Context();
79+
return new Context(environment["updateExpectations"] == "true");
8080
}
8181

8282
class Context extends ChainContext {
@@ -85,6 +85,9 @@ class Context extends ChainContext {
8585
const RunCompilations(),
8686
];
8787

88+
final bool updateExpectations;
89+
Context(this.updateExpectations);
90+
8891
@override
8992
Future<void> cleanUp(TestDescription description, Result result) async {
9093
await cleanupHelper?.outDir?.delete(recursive: true);
@@ -96,6 +99,7 @@ class Context extends ChainContext {
9699
class TestData {
97100
YamlMap map;
98101
Directory outDir;
102+
Uri loadedFrom;
99103
}
100104

101105
class ReadTest extends Step<TestDescription, TestData, Context> {
@@ -108,6 +112,7 @@ class ReadTest extends Step<TestDescription, TestData, Context> {
108112
Uri uri = description.uri;
109113
String contents = await new File.fromUri(uri).readAsString();
110114
TestData data = new TestData();
115+
data.loadedFrom = uri;
111116
data.map = loadYamlNode(contents, sourceUrl: uri);
112117
data.outDir =
113118
Directory.systemTemp.createTempSync("incremental_load_from_dill_test");
@@ -144,6 +149,8 @@ class RunCompilations extends Step<TestData, TestData, Context> {
144149
"incrementalSerialization"
145150
]);
146151
await newWorldTest(
152+
data,
153+
context,
147154
map["worlds"],
148155
map["modules"],
149156
map["omitPlatform"],
@@ -286,8 +293,14 @@ Future<Map<String, List<int>>> createModules(
286293
return moduleResult;
287294
}
288295

289-
Future<Null> newWorldTest(List worlds, Map modules, bool omitPlatform,
290-
String targetName, bool incrementalSerialization) async {
296+
Future<Null> newWorldTest(
297+
TestData data,
298+
Context context,
299+
List worlds,
300+
Map modules,
301+
bool omitPlatform,
302+
String targetName,
303+
bool incrementalSerialization) async {
291304
final Uri sdkRoot = computePlatformBinariesLocation(forceBuildDir: true);
292305
final Uri base = Uri.parse("org-dartlang-test:///");
293306
final Uri sdkSummary = base.resolve("vm_platform_strong.dill");
@@ -502,7 +515,8 @@ Future<Null> newWorldTest(List worlds, Map modules, bool omitPlatform,
502515
performErrorAndWarningCheck(
503516
world, gotError, formattedErrors, gotWarning, formattedWarnings);
504517
util.throwOnEmptyMixinBodies(component);
505-
util.throwOnInsufficientUriToSource(component);
518+
await util.throwOnInsufficientUriToSource(component,
519+
fileSystem: gotError ? null : fs);
506520
print("Compile took ${stopwatch.elapsedMilliseconds} ms");
507521

508522
checkExpectedContent(world, component);
@@ -528,8 +542,9 @@ Future<Null> newWorldTest(List worlds, Map modules, bool omitPlatform,
528542

529543
newestWholeComponentData = util.postProcess(component);
530544
newestWholeComponent = component;
545+
String actualSerialized = componentToStringSdkFiltered(component);
531546
print("*****\n\ncomponent:\n"
532-
"${componentToStringSdkFiltered(component)}\n\n\n");
547+
"${actualSerialized}\n\n\n");
533548

534549
if (world["uriToSourcesDoesntInclude"] != null) {
535550
for (String filename in world["uriToSourcesDoesntInclude"]) {
@@ -557,6 +572,24 @@ Future<Null> newWorldTest(List worlds, Map modules, bool omitPlatform,
557572
}
558573
}
559574

575+
Uri uri = data.loadedFrom
576+
.resolve(data.loadedFrom.pathSegments.last + ".world.$worldNum.expect");
577+
String expected;
578+
File file = new File.fromUri(uri);
579+
if (context.updateExpectations) {
580+
file.writeAsStringSync(actualSerialized);
581+
}
582+
if (file.existsSync()) {
583+
expected = file.readAsStringSync();
584+
}
585+
if (context.updateExpectations) {
586+
file.writeAsStringSync(actualSerialized);
587+
} else if (expected != actualSerialized) {
588+
throw "Unexpected serialized representation. "
589+
"Fix or update $uri to contain the below:\n\n"
590+
"$actualSerialized";
591+
}
592+
560593
int nonSyntheticLibraries = countNonSyntheticLibraries(component);
561594
int nonSyntheticPlatformLibraries =
562595
countNonSyntheticPlatformLibraries(component);
@@ -588,6 +621,7 @@ Future<Null> newWorldTest(List worlds, Map modules, bool omitPlatform,
588621
"libraries, got ${syntheticLibraries}";
589622
}
590623
}
624+
591625
if (!noFullComponent) {
592626
List<Library> entryLib = component.libraries
593627
.where((Library lib) =>
@@ -708,7 +742,7 @@ Future<Null> newWorldTest(List worlds, Map modules, bool omitPlatform,
708742
performErrorAndWarningCheck(
709743
world, gotError, formattedErrors, gotWarning, formattedWarnings);
710744
util.throwOnEmptyMixinBodies(component3);
711-
util.throwOnInsufficientUriToSource(component3);
745+
await util.throwOnInsufficientUriToSource(component3);
712746
print("Compile took ${stopwatch.elapsedMilliseconds} ms");
713747

714748
util.postProcess(component3);
@@ -1108,7 +1142,7 @@ Future<Component> normalCompileToComponent(Uri input,
11081142
Component component =
11091143
await normalCompilePlain(input, options: options, compiler: compiler);
11101144
util.throwOnEmptyMixinBodies(component);
1111-
util.throwOnInsufficientUriToSource(component);
1145+
await util.throwOnInsufficientUriToSource(component);
11121146
return component;
11131147
}
11141148

@@ -1130,7 +1164,7 @@ Future<bool> initializedCompile(
11301164
}
11311165
Component initializedComponent = await compiler.computeDelta();
11321166
util.throwOnEmptyMixinBodies(initializedComponent);
1133-
util.throwOnInsufficientUriToSource(initializedComponent);
1167+
await util.throwOnInsufficientUriToSource(initializedComponent);
11341168
bool result = compiler.initializedFromDill;
11351169
new File.fromUri(output)
11361170
.writeAsBytesSync(util.postProcess(initializedComponent));
@@ -1146,7 +1180,7 @@ Future<bool> initializedCompile(
11461180
Component initializedFullComponent =
11471181
await compiler.computeDelta(fullComponent: true);
11481182
util.throwOnEmptyMixinBodies(initializedFullComponent);
1149-
util.throwOnInsufficientUriToSource(initializedFullComponent);
1183+
await util.throwOnInsufficientUriToSource(initializedFullComponent);
11501184
Expect.equals(initializedComponent.libraries.length,
11511185
initializedFullComponent.libraries.length);
11521186
Expect.equals(initializedComponent.uriToSource.length,
@@ -1158,7 +1192,7 @@ Future<bool> initializedCompile(
11581192

11591193
Component partialComponent = await compiler.computeDelta();
11601194
util.throwOnEmptyMixinBodies(partialComponent);
1161-
util.throwOnInsufficientUriToSource(partialComponent);
1195+
await util.throwOnInsufficientUriToSource(partialComponent);
11621196
actuallyInvalidatedCount = (compiler
11631197
.getFilteredInvalidatedImportUrisForTesting(invalidateUris)
11641198
?.length ??
@@ -1170,7 +1204,7 @@ Future<bool> initializedCompile(
11701204

11711205
Component emptyComponent = await compiler.computeDelta();
11721206
util.throwOnEmptyMixinBodies(emptyComponent);
1173-
util.throwOnInsufficientUriToSource(emptyComponent);
1207+
await util.throwOnInsufficientUriToSource(emptyComponent);
11741208

11751209
List<Uri> fullLibUris =
11761210
initializedComponent.libraries.map((lib) => lib.importUri).toList();

pkg/front_end/test/incremental_utils.dart

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:convert' show utf8;
6+
7+
import "package:front_end/src/api_prototype/file_system.dart" show FileSystem;
8+
59
import 'package:front_end/src/fasta/kernel/utils.dart' show serializeComponent;
610

711
import 'package:kernel/kernel.dart'
@@ -57,14 +61,48 @@ int countEmptyMixinBodies(Component component) {
5761
return empty;
5862
}
5963

60-
void throwOnInsufficientUriToSource(Component component) {
64+
Future<void> throwOnInsufficientUriToSource(Component component,
65+
{FileSystem fileSystem}) async {
6166
UriFinder uriFinder = new UriFinder();
6267
component.accept(uriFinder);
6368
Set<Uri> uris = uriFinder.seenUris.toSet();
6469
uris.removeAll(component.uriToSource.keys);
6570
if (uris.length != 0) {
6671
throw "Expected 0 uris with no source, but found ${uris.length} ($uris)";
6772
}
73+
74+
if (fileSystem != null) {
75+
uris = uriFinder.seenUris.toSet();
76+
for (Uri uri in uris) {
77+
if (uri == null) continue;
78+
if (uri.scheme != "org-dartlang-test") continue;
79+
// The file system doesn't have the sources for any modules.
80+
// For now assume that that is always what's going on.
81+
if (!await fileSystem.entityForUri(uri).exists()) continue;
82+
List<int> expected = await fileSystem.entityForUri(uri).readAsBytes();
83+
List<int> actual = component.uriToSource[uri].source;
84+
bool fail = false;
85+
if (expected.length != actual.length) {
86+
fail = true;
87+
}
88+
if (!fail) {
89+
for (int i = 0; i < expected.length; i++) {
90+
if (expected[i] != actual[i]) {
91+
fail = true;
92+
break;
93+
}
94+
}
95+
}
96+
if (fail) {
97+
String expectedString = utf8.decode(expected);
98+
String actualString = utf8.decode(actual);
99+
throw "Not expected source for $uri:\n\n"
100+
"$expectedString\n\n"
101+
"vs\n\n"
102+
"$actualString";
103+
}
104+
}
105+
}
68106
}
69107

70108
class UriFinder extends RecursiveVisitor {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
main = <No Member>;
2+
library from "org-dartlang-test:///main.dart" as main {
3+
4+
static method main() → dynamic {
5+
main::foo();
6+
}
7+
static method foo() → dynamic {}
8+
}
9+
10+
And 19 platform libraries:
11+
- dart:vmservice_io
12+
- dart:_http
13+
- dart:_builtin
14+
- dart:async
15+
- dart:cli
16+
- dart:collection
17+
- dart:convert
18+
- dart:core
19+
- dart:developer
20+
- dart:ffi
21+
- dart:nativewrappers
22+
- dart:_internal
23+
- dart:io
24+
- dart:isolate
25+
- dart:math
26+
- dart:mirrors
27+
- dart:typed_data
28+
- dart:_vmservice
29+
- dart:wasm
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
main = <No Member>;
2+
library from "org-dartlang-test:///main.dart" as main {
3+
//
4+
// Problems in library:
5+
//
6+
// org-dartlang-test:///main.dart:2:3: Error: 'await' can only be used in 'async' or 'async*' methods.
7+
// await foo();
8+
// ^^^^^
9+
//
10+
11+
static method main() → dynamic {
12+
invalid-expression "org-dartlang-test:///main.dart:2:3: Error: 'await' can only be used in 'async' or 'async*' methods.\n await foo();\n ^^^^^";
13+
}
14+
static method foo() → dynamic {}
15+
}
16+
17+
And 19 platform libraries:
18+
- dart:vmservice_io
19+
- dart:_http
20+
- dart:_builtin
21+
- dart:async
22+
- dart:cli
23+
- dart:collection
24+
- dart:convert
25+
- dart:core
26+
- dart:developer
27+
- dart:ffi
28+
- dart:nativewrappers
29+
- dart:_internal
30+
- dart:io
31+
- dart:isolate
32+
- dart:math
33+
- dart:mirrors
34+
- dart:typed_data
35+
- dart:_vmservice
36+
- dart:wasm
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
main = <No Member>;
2+
library from "package:example/a.dart" as a {
3+
4+
static method a() → dynamic {
5+
a::la1();
6+
}
7+
static method la1() → dynamic {
8+
dart.core::print("Hello from v0.1.0");
9+
}
10+
}
11+
library from "package:example/b.dart" as b {
12+
13+
import "package:example/a.dart";
14+
15+
static method b() → dynamic {
16+
a::a();
17+
}
18+
}
19+
library from "org-dartlang-test:///main.dart" as main {
20+
21+
import "package:example/b.dart";
22+
23+
static method main() → dynamic {
24+
dart.core::print("hello");
25+
b::b();
26+
}
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
main = <No Member>;
2+
library from "package:example/a.dart" as a {
3+
4+
static method a() → dynamic {
5+
a::la1();
6+
}
7+
static method la1() → dynamic {
8+
dart.core::print("Hello from v0.1.0");
9+
}
10+
}
11+
library from "package:example/b.dart" as b {
12+
13+
import "package:example/a.dart";
14+
15+
static method b() → dynamic {
16+
a::a();
17+
}
18+
}
19+
library from "package:foo/foo.dart" as foo {
20+
21+
import "package:example/b.dart";
22+
23+
static field dart.core::bool* foo1 = true;
24+
static method foo() → dynamic {
25+
dart.core::print("Hello from foo");
26+
b::b();
27+
}
28+
}
29+
library from "org-dartlang-test:///main.dart" as main {
30+
31+
import "package:foo/foo.dart";
32+
33+
static method main() → dynamic {
34+
dart.core::print("hello");
35+
foo::foo();
36+
}
37+
}

0 commit comments

Comments
 (0)