@@ -76,7 +76,7 @@ main([List<String> arguments = const []]) =>
7676
7777Future <Context > createContext (
7878 Chain suite, Map <String , String > environment) async {
79- return new Context ();
79+ return new Context (environment[ "updateExpectations" ] == "true" );
8080}
8181
8282class 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 {
9699class TestData {
97100 YamlMap map;
98101 Directory outDir;
102+ Uri loadedFrom;
99103}
100104
101105class 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\n component:\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 ();
0 commit comments