@@ -222,9 +222,7 @@ class TestFileEdit {
222222 TestFileEdit (this .generation, this .fileUri);
223223}
224224
225- // TODO(nshahan): Make this abstract again when there are subclasses for all
226- // runtimes.
227- class HotReloadSuiteRunner {
225+ abstract class HotReloadSuiteRunner {
228226 Options options;
229227
230228 /// The root directory containing generated code for all tests.
@@ -681,91 +679,17 @@ class HotReloadSuiteRunner {
681679 return updatedFilesInCurrentGeneration;
682680 }
683681
684- /// Compile all [updatedFiles] in [test] for the given [generation] with the
685- /// front end server [controller] and copy outputs to [outputDirectory] .
682+ /// Compiles all [updatedFiles] in [test] for the given [generation] with the
683+ /// front end server [controller] , copies all outputs to [outputDirectory] ,
684+ /// and returns whether the compilation was successful.
686685 ///
687686 /// Reports test failures on compile time errors.
688- // TODO(nshahan): Move to a DDC specific suite runner.
689687 Future <bool > compileGeneration (
690688 HotReloadTest test,
691689 int generation,
692690 Directory outputDirectory,
693691 List <String > updatedFiles,
694- HotReloadFrontendServerController controller) async {
695- var hasCompileError = false ;
696- // The first generation calls `compile`, but subsequent ones call
697- // `recompile`.
698- // Likewise, use the incremental output directory for `recompile` calls.
699- String outputDillPath;
700- _print ('Compiling generation $generation with the Frontend Server.' ,
701- label: test.name);
702- CompilerOutput compilerOutput;
703- if (generation == 0 ) {
704- _debugPrint (
705- 'Compiling snapshot entrypoint: $snapshotEntrypointWithScheme ' ,
706- label: test.name);
707- outputDillPath = outputDillUri.toFilePath ();
708- compilerOutput =
709- await controller.sendCompile (snapshotEntrypointWithScheme);
710- } else {
711- _debugPrint (
712- 'Recompiling snapshot entrypoint: $snapshotEntrypointWithScheme ' ,
713- label: test.name);
714- outputDillPath = outputIncrementalDillUri.toFilePath ();
715- // TODO(markzipan): Add logic to reject bad compiles.
716- compilerOutput = await controller.sendRecompile (
717- snapshotEntrypointWithScheme,
718- invalidatedFiles: updatedFiles);
719- }
720- // Frontend Server reported compile errors. Fail if they weren't
721- // expected, and do not run tests.
722- if (compilerOutput.errorCount > 0 ) {
723- hasCompileError = true ;
724- await controller.sendReject ();
725- // TODO(markzipan): Determine if 'contains' is good enough to determine
726- // compilation error correctness.
727- if (test.expectedError != null &&
728- compilerOutput.outputText.contains (test.expectedError! )) {
729- await reportTestOutcome (
730- test.name,
731- 'Expected error found during compilation: '
732- '${test .expectedError }' ,
733- true );
734- } else {
735- await reportTestOutcome (
736- test.name,
737- 'Test failed with compile error: ${compilerOutput .outputText }' ,
738- false );
739- }
740- } else {
741- controller.sendAccept ();
742- }
743-
744- // Stop processing further generations if compilation failed.
745- if (hasCompileError) return false ;
746-
747- _debugPrint (
748- 'Frontend Server successfully compiled outputs to: '
749- '$outputDillPath ' ,
750- label: test.name);
751- _debugPrint ('Emitting JS code to ${outputDirectory .path }.' ,
752- label: test.name);
753- // Update the memory filesystem with the newly-created JS files.
754- _print ('Loading generation $generation files into the memory filesystem.' ,
755- label: test.name);
756- final codeFile = File ('$outputDillPath .sources' );
757- final manifestFile = File ('$outputDillPath .json' );
758- final sourcemapFile = File ('$outputDillPath .map' );
759- filesystem! .update (codeFile, manifestFile, sourcemapFile,
760- generation: '$generation ' );
761-
762- // Write JS files and sourcemaps to their respective generation.
763- _print ('Writing generation $generation assets.' , label: test.name);
764- _debugPrint ('Writing JS assets to ${outputDirectory .path }' ,
765- label: test.name);
766- filesystem! .writeToDisk (outputDirectory.uri, generation: '$generation ' );
767- return true ;
768- }
692+ HotReloadFrontendServerController controller);
769693
770694 // TODO(nshahan): Refactor into runtime specific implementations.
771695 Future <bool > runTest (
@@ -965,7 +889,96 @@ class HotReloadSuiteRunner {
965889 }
966890}
967891
968- class D8SuiteRunner extends HotReloadSuiteRunner {
892+ /// Hot reload test suite runner for DDC specific behavior that is agnostic to
893+ /// the environment where the compiled code is eventually run.
894+ abstract class DdcSuiteRunner extends HotReloadSuiteRunner {
895+ DdcSuiteRunner (super .options);
896+
897+ @override
898+ Future <bool > compileGeneration (
899+ HotReloadTest test,
900+ int generation,
901+ Directory outputDirectory,
902+ List <String > updatedFiles,
903+ HotReloadFrontendServerController controller) async {
904+ var hasCompileError = false ;
905+ // The first generation calls `compile`, but subsequent ones call
906+ // `recompile`.
907+ // Likewise, use the incremental output file for `recompile` calls.
908+ // TODO(nshahan): Sending compile/recompile instructions is likely
909+ // the same across backends and should be shared code.
910+ String outputDillPath;
911+ _print ('Compiling generation $generation with the Frontend Server.' ,
912+ label: test.name);
913+ CompilerOutput compilerOutput;
914+ if (generation == 0 ) {
915+ _debugPrint (
916+ 'Compiling snapshot entrypoint: $snapshotEntrypointWithScheme ' ,
917+ label: test.name);
918+ outputDillPath = outputDillUri.toFilePath ();
919+ compilerOutput =
920+ await controller.sendCompile (snapshotEntrypointWithScheme);
921+ } else {
922+ _debugPrint (
923+ 'Recompiling snapshot entrypoint: $snapshotEntrypointWithScheme ' ,
924+ label: test.name);
925+ outputDillPath = outputIncrementalDillUri.toFilePath ();
926+ // TODO(markzipan): Add logic to reject bad compiles.
927+ compilerOutput = await controller.sendRecompile (
928+ snapshotEntrypointWithScheme,
929+ invalidatedFiles: updatedFiles);
930+ }
931+ // Frontend Server reported compile errors. Fail if they weren't
932+ // expected, and do not run tests.
933+ if (compilerOutput.errorCount > 0 ) {
934+ hasCompileError = true ;
935+ await controller.sendReject ();
936+ // TODO(markzipan): Determine if 'contains' is good enough to determine
937+ // compilation error correctness.
938+ if (test.expectedError != null &&
939+ compilerOutput.outputText.contains (test.expectedError! )) {
940+ await reportTestOutcome (
941+ test.name,
942+ 'Expected error found during compilation: '
943+ '${test .expectedError }' ,
944+ true );
945+ } else {
946+ await reportTestOutcome (
947+ test.name,
948+ 'Test failed with compile error: ${compilerOutput .outputText }' ,
949+ false );
950+ }
951+ } else {
952+ controller.sendAccept ();
953+ }
954+ // Stop processing further generations if compilation failed.
955+ if (hasCompileError) return false ;
956+ _debugPrint (
957+ 'Frontend Server successfully compiled outputs to: '
958+ '$outputDillPath ' ,
959+ label: test.name);
960+ _debugPrint ('Emitting JS code to ${outputDirectory .path }.' ,
961+ label: test.name);
962+ // Update the memory filesystem with the newly-created JS files.
963+ _print ('Loading generation $generation files into the memory filesystem.' ,
964+ label: test.name);
965+ final codeFile = File ('$outputDillPath .sources' );
966+ final manifestFile = File ('$outputDillPath .json' );
967+ final sourcemapFile = File ('$outputDillPath .map' );
968+ filesystem! .update (codeFile, manifestFile, sourcemapFile,
969+ generation: '$generation ' );
970+ // Write JS files and sourcemaps to their respective generation.
971+ _print ('Writing generation $generation assets.' , label: test.name);
972+ _debugPrint ('Writing JS assets to ${outputDirectory .path }' ,
973+ label: test.name);
974+ filesystem! .writeToDisk (outputDirectory.uri, generation: '$generation ' );
975+ return true ;
976+ }
977+ }
978+
979+ /// Hot reload test suite runner for behavior specific to DDC compiled code
980+ /// running in D8.
981+ class D8SuiteRunner extends DdcSuiteRunner {
969982 final ddc_helpers.D8Configuration config =
970983 ddc_helpers.D8Configuration (sdkRoot);
971984 late Uri bootstrapJsUri;
@@ -1022,7 +1035,9 @@ class D8SuiteRunner extends HotReloadSuiteRunner {
10221035 }
10231036}
10241037
1025- class ChromeSuiteRunner extends HotReloadSuiteRunner {
1038+ /// Hot reload test suite runner for behavior specific to DDC compiled code
1039+ /// running in Chrome.
1040+ class ChromeSuiteRunner extends DdcSuiteRunner {
10261041 final ddc_helpers.ChromeConfiguration config =
10271042 ddc_helpers.ChromeConfiguration (sdkRoot);
10281043 late Uri bootstrapJsUri;
0 commit comments