From 09a4f23467915e60916f8860ee5684698bd62a85 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Thu, 10 Nov 2022 20:00:19 +0000 Subject: [PATCH] Prevent tests from producing dill files alongside the test file (#115075) Fixes https://github.com/Dart-Code/Dart-Code/issues/4243. --- .../lib/src/test/flutter_platform.dart | 22 ++++++++++++------- .../expression_evaluation_test.dart | 12 ++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index 9a3d89d988..1603f34a73 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart @@ -458,14 +458,16 @@ class FlutterPlatform extends PlatformPlugin { controllerSinkClosed = true; })); - // When start paused is specified, it means that the user is likely - // running this with a debugger attached. Initialize the resident - // compiler in this case. - if (debuggingOptions.startPaused) { - compiler ??= TestCompiler(debuggingOptions.buildInfo, flutterProject, precompiledDillPath: precompiledDillPath, testTimeRecorder: testTimeRecorder); - final Uri testUri = globals.fs.file(testPath).uri; - // Trigger a compilation to initialize the resident compiler. - unawaited(compiler!.compile(testUri)); + void initializeExpressionCompiler(String path) { + // When start paused is specified, it means that the user is likely + // running this with a debugger attached. Initialize the resident + // compiler in this case. + if (debuggingOptions.startPaused) { + compiler ??= TestCompiler(debuggingOptions.buildInfo, flutterProject, precompiledDillPath: precompiledDillPath, testTimeRecorder: testTimeRecorder); + final Uri uri = globals.fs.file(path).uri; + // Trigger a compilation to initialize the resident compiler. + unawaited(compiler!.compile(uri)); + } } // If a kernel file is given, then use that to launch the test. @@ -474,6 +476,7 @@ class FlutterPlatform extends PlatformPlugin { String? mainDart; if (precompiledDillPath != null) { mainDart = precompiledDillPath; + initializeExpressionCompiler(testPath); } else if (precompiledDillFiles != null) { mainDart = precompiledDillFiles![testPath]; } else { @@ -489,6 +492,9 @@ class FlutterPlatform extends PlatformPlugin { testHarnessChannel.sink.addError('Compilation failed for testPath=$testPath'); return null; } + } else { + // For integration tests, we may still need to set up expression compilation service. + initializeExpressionCompiler(mainDart); } } diff --git a/packages/flutter_tools/test/integration.shard/expression_evaluation_test.dart b/packages/flutter_tools/test/integration.shard/expression_evaluation_test.dart index 6da4b413e5..4676de1fac 100644 --- a/packages/flutter_tools/test/integration.shard/expression_evaluation_test.dart +++ b/packages/flutter_tools/test/integration.shard/expression_evaluation_test.dart @@ -116,6 +116,12 @@ void batch2() { ); await flutter.waitForPause(); await evaluateTrivialExpressions(flutter); + + // Ensure we did not leave a dill file alongside the test. + // https://github.com/Dart-Code/Dart-Code/issues/4243. + final String dillFilename = '${project.testFilePath}.dill'; + expect(fileSystem.file(dillFilename).existsSync(), isFalse); + await cleanProject(); }); @@ -168,6 +174,12 @@ void batch3() { ); await flutter.waitForPause(); await evaluateTrivialExpressions(flutter); + + // Ensure we did not leave a dill file alongside the test. + // https://github.com/Dart-Code/Dart-Code/issues/4243. + final String dillFilename = '${project.testFilePath}.dill'; + expect(fileSystem.file(dillFilename).existsSync(), isFalse); + await cleanProject(); });