[flutter_tools] support --enable-experiment in flutter test (#55564)
Support --enable-experiment in flutter test (for flutter_tester). Required minor change for null safety.
This commit is contained in:
@@ -129,6 +129,7 @@ class TestCommand extends FlutterCommand {
|
||||
'The vmservice will be enabled no matter what in those cases.'
|
||||
);
|
||||
usesTrackWidgetCreation(verboseHelp: verboseHelp);
|
||||
addEnableExperimentation(hide: !verboseHelp);
|
||||
}
|
||||
|
||||
/// The interface for starting and configuring the tester.
|
||||
@@ -171,6 +172,7 @@ class TestCommand extends FlutterCommand {
|
||||
final String tags = stringArg('tags');
|
||||
final String excludeTags = stringArg('exclude-tags');
|
||||
final FlutterProject flutterProject = FlutterProject.current();
|
||||
final List<String> dartExperiments = stringsArg(FlutterOptions.kEnableExperiment);
|
||||
|
||||
if (buildTestAssets && flutterProject.manifest.assets.isNotEmpty) {
|
||||
await _buildTestAsset();
|
||||
@@ -276,6 +278,7 @@ class TestCommand extends FlutterCommand {
|
||||
flutterProject: flutterProject,
|
||||
web: stringArg('platform') == 'chrome',
|
||||
randomSeed: stringArg('test-randomize-ordering-seed'),
|
||||
dartExperiments: dartExperiments,
|
||||
);
|
||||
|
||||
if (collector != null) {
|
||||
|
||||
@@ -87,6 +87,7 @@ FlutterPlatform installHook({
|
||||
FlutterProject flutterProject,
|
||||
String icudtlPath,
|
||||
PlatformPluginRegistration platformPluginRegistration,
|
||||
@required List<String> dartExperiments,
|
||||
}) {
|
||||
assert(testWrapper != null);
|
||||
assert(enableObservatory || (!startPaused && observatoryPort == null));
|
||||
@@ -119,6 +120,7 @@ FlutterPlatform installHook({
|
||||
projectRootDirectory: projectRootDirectory,
|
||||
flutterProject: flutterProject,
|
||||
icudtlPath: icudtlPath,
|
||||
dartExperiments: dartExperiments,
|
||||
);
|
||||
platformPluginRegistration(platform);
|
||||
return platform;
|
||||
@@ -144,6 +146,7 @@ String generateTestBootstrap({
|
||||
@required InternetAddress host,
|
||||
File testConfigFile,
|
||||
bool updateGoldens = false,
|
||||
@required bool nullSafety,
|
||||
}) {
|
||||
assert(testUrl != null);
|
||||
assert(host != null);
|
||||
@@ -173,11 +176,15 @@ import '$testUrl' as test;
|
||||
import '${Uri.file(testConfigFile.path)}' as test_config;
|
||||
''');
|
||||
}
|
||||
// This type is sensitive to the non-nullable experiment.
|
||||
final String beforeLoadTypedef = nullSafety
|
||||
? 'Future<dynamic> Function()?'
|
||||
: 'Future<dynamic> Function()';
|
||||
buffer.write('''
|
||||
|
||||
/// Returns a serialized test suite.
|
||||
StreamChannel<dynamic> serializeSuite(Function getMain(),
|
||||
{bool hidePrints = true, Future<dynamic> beforeLoad()}) {
|
||||
{bool hidePrints = true, $beforeLoadTypedef beforeLoad}) {
|
||||
return RemoteListener.start(getMain,
|
||||
hidePrints: hidePrints, beforeLoad: beforeLoad);
|
||||
}
|
||||
@@ -259,6 +266,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
this.projectRootDirectory,
|
||||
this.flutterProject,
|
||||
this.icudtlPath,
|
||||
@required this.dartExperiments,
|
||||
}) : assert(shellPath != null);
|
||||
|
||||
final String shellPath;
|
||||
@@ -279,6 +287,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
final Uri projectRootDirectory;
|
||||
final FlutterProject flutterProject;
|
||||
final String icudtlPath;
|
||||
final List<String> dartExperiments;
|
||||
|
||||
Directory fontsDirectory;
|
||||
|
||||
@@ -447,7 +456,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
|
||||
if (precompiledDillPath == null && precompiledDillFiles == null) {
|
||||
// Lazily instantiate compiler so it is built only if it is actually used.
|
||||
compiler ??= TestCompiler(buildMode, trackWidgetCreation, flutterProject);
|
||||
compiler ??= TestCompiler(buildMode, trackWidgetCreation, flutterProject, dartExperiments);
|
||||
mainDart = await compiler.compile(globals.fs.file(mainDart).uri);
|
||||
|
||||
if (mainDart == null) {
|
||||
@@ -739,6 +748,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
testConfigFile: findTestConfigFile(globals.fs.file(testUrl)),
|
||||
host: host,
|
||||
updateGoldens: updateGoldens,
|
||||
nullSafety: dartExperiments.contains('non-nullable'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
|
||||
_testGoldenComparator = TestGoldenComparator(
|
||||
shellPath,
|
||||
() => TestCompiler(BuildMode.debug, false, flutterProject),
|
||||
() => TestCompiler(BuildMode.debug, false, flutterProject, <String>[]),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ abstract class FlutterTestRunner {
|
||||
Directory coverageDirectory,
|
||||
bool web = false,
|
||||
String randomSeed,
|
||||
@required List<String> dartExperiments,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -84,6 +85,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
||||
Directory coverageDirectory,
|
||||
bool web = false,
|
||||
String randomSeed,
|
||||
@required List<String> dartExperiments,
|
||||
}) async {
|
||||
// Configure package:test to use the Flutter engine for child processes.
|
||||
final String shellPath = globals.artifacts.getArtifactPath(Artifact.flutterTester);
|
||||
@@ -175,6 +177,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
||||
projectRootDirectory: globals.fs.currentDirectory.uri,
|
||||
flutterProject: flutterProject,
|
||||
icudtlPath: icudtlPath,
|
||||
dartExperiments: dartExperiments,
|
||||
);
|
||||
|
||||
// Make the global packages path absolute.
|
||||
|
||||
@@ -42,6 +42,7 @@ class TestCompiler {
|
||||
this.buildMode,
|
||||
this.trackWidgetCreation,
|
||||
this.flutterProject,
|
||||
this.dartExperiments,
|
||||
) : testFilePath = getKernelPathForTransformerOptions(
|
||||
globals.fs.path.join(flutterProject.directory.path, getBuildDirectory(), 'testfile.dill'),
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
@@ -65,6 +66,7 @@ class TestCompiler {
|
||||
final BuildMode buildMode;
|
||||
final bool trackWidgetCreation;
|
||||
final String testFilePath;
|
||||
final List<String> dartExperiments;
|
||||
|
||||
|
||||
ResidentCompiler compiler;
|
||||
@@ -104,6 +106,7 @@ class TestCompiler {
|
||||
unsafePackageSerialization: false,
|
||||
dartDefines: const <String>[],
|
||||
packagesPath: globalPackagesPath,
|
||||
experimentalFlags: dartExperiments,
|
||||
);
|
||||
if (flutterProject.hasBuilders) {
|
||||
return CodeGeneratingResidentCompiler.create(
|
||||
|
||||
Reference in New Issue
Block a user