[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:
parent
07c451fea9
commit
1ab3878996
@ -480,6 +480,9 @@ Future<void> _runFrameworkTests() async {
|
|||||||
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_localizations'), tableData: bigqueryApi?.tabledata);
|
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_localizations'), tableData: bigqueryApi?.tabledata);
|
||||||
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'), tableData: bigqueryApi?.tabledata);
|
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'), tableData: bigqueryApi?.tabledata);
|
||||||
await _runFlutterTest(path.join(flutterRoot, 'packages', 'fuchsia_remote_debug_protocol'), tableData: bigqueryApi?.tabledata);
|
await _runFlutterTest(path.join(flutterRoot, 'packages', 'fuchsia_remote_debug_protocol'), tableData: bigqueryApi?.tabledata);
|
||||||
|
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'non_nullable'),
|
||||||
|
options: <String>['--enable-experiment=non-nullable'],
|
||||||
|
);
|
||||||
await _runFlutterTest(
|
await _runFlutterTest(
|
||||||
path.join(flutterRoot, 'dev', 'tracing_tests'),
|
path.join(flutterRoot, 'dev', 'tracing_tests'),
|
||||||
options: <String>['--enable-vmservice'],
|
options: <String>['--enable-vmservice'],
|
||||||
|
@ -3,3 +3,4 @@
|
|||||||
analyzer:
|
analyzer:
|
||||||
exclude:
|
exclude:
|
||||||
- lib/main.dart
|
- lib/main.dart
|
||||||
|
- test/test_test.dart
|
||||||
|
14
dev/integration_tests/non_nullable/test/test_test.dart
Normal file
14
dev/integration_tests/non_nullable/test/test_test.dart
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
// @dart=2.9
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
String? x;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('trivial', (WidgetTester tester) async {
|
||||||
|
expect(true, true);
|
||||||
|
});
|
||||||
|
}
|
@ -155,6 +155,7 @@ Future<void> run(List<String> args) async {
|
|||||||
concurrency: math.max(1, globals.platform.numberOfProcessors - 2),
|
concurrency: math.max(1, globals.platform.numberOfProcessors - 2),
|
||||||
icudtlPath: globals.fs.path.absolute(argResults[_kOptionIcudtl] as String),
|
icudtlPath: globals.fs.path.absolute(argResults[_kOptionIcudtl] as String),
|
||||||
coverageDirectory: coverageDirectory,
|
coverageDirectory: coverageDirectory,
|
||||||
|
dartExperiments: <String>[],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (collector != null) {
|
if (collector != null) {
|
||||||
|
@ -129,6 +129,7 @@ class TestCommand extends FlutterCommand {
|
|||||||
'The vmservice will be enabled no matter what in those cases.'
|
'The vmservice will be enabled no matter what in those cases.'
|
||||||
);
|
);
|
||||||
usesTrackWidgetCreation(verboseHelp: verboseHelp);
|
usesTrackWidgetCreation(verboseHelp: verboseHelp);
|
||||||
|
addEnableExperimentation(hide: !verboseHelp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The interface for starting and configuring the tester.
|
/// The interface for starting and configuring the tester.
|
||||||
@ -171,6 +172,7 @@ class TestCommand extends FlutterCommand {
|
|||||||
final String tags = stringArg('tags');
|
final String tags = stringArg('tags');
|
||||||
final String excludeTags = stringArg('exclude-tags');
|
final String excludeTags = stringArg('exclude-tags');
|
||||||
final FlutterProject flutterProject = FlutterProject.current();
|
final FlutterProject flutterProject = FlutterProject.current();
|
||||||
|
final List<String> dartExperiments = stringsArg(FlutterOptions.kEnableExperiment);
|
||||||
|
|
||||||
if (buildTestAssets && flutterProject.manifest.assets.isNotEmpty) {
|
if (buildTestAssets && flutterProject.manifest.assets.isNotEmpty) {
|
||||||
await _buildTestAsset();
|
await _buildTestAsset();
|
||||||
@ -276,6 +278,7 @@ class TestCommand extends FlutterCommand {
|
|||||||
flutterProject: flutterProject,
|
flutterProject: flutterProject,
|
||||||
web: stringArg('platform') == 'chrome',
|
web: stringArg('platform') == 'chrome',
|
||||||
randomSeed: stringArg('test-randomize-ordering-seed'),
|
randomSeed: stringArg('test-randomize-ordering-seed'),
|
||||||
|
dartExperiments: dartExperiments,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (collector != null) {
|
if (collector != null) {
|
||||||
|
@ -87,6 +87,7 @@ FlutterPlatform installHook({
|
|||||||
FlutterProject flutterProject,
|
FlutterProject flutterProject,
|
||||||
String icudtlPath,
|
String icudtlPath,
|
||||||
PlatformPluginRegistration platformPluginRegistration,
|
PlatformPluginRegistration platformPluginRegistration,
|
||||||
|
@required List<String> dartExperiments,
|
||||||
}) {
|
}) {
|
||||||
assert(testWrapper != null);
|
assert(testWrapper != null);
|
||||||
assert(enableObservatory || (!startPaused && observatoryPort == null));
|
assert(enableObservatory || (!startPaused && observatoryPort == null));
|
||||||
@ -119,6 +120,7 @@ FlutterPlatform installHook({
|
|||||||
projectRootDirectory: projectRootDirectory,
|
projectRootDirectory: projectRootDirectory,
|
||||||
flutterProject: flutterProject,
|
flutterProject: flutterProject,
|
||||||
icudtlPath: icudtlPath,
|
icudtlPath: icudtlPath,
|
||||||
|
dartExperiments: dartExperiments,
|
||||||
);
|
);
|
||||||
platformPluginRegistration(platform);
|
platformPluginRegistration(platform);
|
||||||
return platform;
|
return platform;
|
||||||
@ -144,6 +146,7 @@ String generateTestBootstrap({
|
|||||||
@required InternetAddress host,
|
@required InternetAddress host,
|
||||||
File testConfigFile,
|
File testConfigFile,
|
||||||
bool updateGoldens = false,
|
bool updateGoldens = false,
|
||||||
|
@required bool nullSafety,
|
||||||
}) {
|
}) {
|
||||||
assert(testUrl != null);
|
assert(testUrl != null);
|
||||||
assert(host != null);
|
assert(host != null);
|
||||||
@ -173,11 +176,15 @@ import '$testUrl' as test;
|
|||||||
import '${Uri.file(testConfigFile.path)}' as test_config;
|
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('''
|
buffer.write('''
|
||||||
|
|
||||||
/// Returns a serialized test suite.
|
/// Returns a serialized test suite.
|
||||||
StreamChannel<dynamic> serializeSuite(Function getMain(),
|
StreamChannel<dynamic> serializeSuite(Function getMain(),
|
||||||
{bool hidePrints = true, Future<dynamic> beforeLoad()}) {
|
{bool hidePrints = true, $beforeLoadTypedef beforeLoad}) {
|
||||||
return RemoteListener.start(getMain,
|
return RemoteListener.start(getMain,
|
||||||
hidePrints: hidePrints, beforeLoad: beforeLoad);
|
hidePrints: hidePrints, beforeLoad: beforeLoad);
|
||||||
}
|
}
|
||||||
@ -259,6 +266,7 @@ class FlutterPlatform extends PlatformPlugin {
|
|||||||
this.projectRootDirectory,
|
this.projectRootDirectory,
|
||||||
this.flutterProject,
|
this.flutterProject,
|
||||||
this.icudtlPath,
|
this.icudtlPath,
|
||||||
|
@required this.dartExperiments,
|
||||||
}) : assert(shellPath != null);
|
}) : assert(shellPath != null);
|
||||||
|
|
||||||
final String shellPath;
|
final String shellPath;
|
||||||
@ -279,6 +287,7 @@ class FlutterPlatform extends PlatformPlugin {
|
|||||||
final Uri projectRootDirectory;
|
final Uri projectRootDirectory;
|
||||||
final FlutterProject flutterProject;
|
final FlutterProject flutterProject;
|
||||||
final String icudtlPath;
|
final String icudtlPath;
|
||||||
|
final List<String> dartExperiments;
|
||||||
|
|
||||||
Directory fontsDirectory;
|
Directory fontsDirectory;
|
||||||
|
|
||||||
@ -447,7 +456,7 @@ class FlutterPlatform extends PlatformPlugin {
|
|||||||
|
|
||||||
if (precompiledDillPath == null && precompiledDillFiles == null) {
|
if (precompiledDillPath == null && precompiledDillFiles == null) {
|
||||||
// Lazily instantiate compiler so it is built only if it is actually used.
|
// 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);
|
mainDart = await compiler.compile(globals.fs.file(mainDart).uri);
|
||||||
|
|
||||||
if (mainDart == null) {
|
if (mainDart == null) {
|
||||||
@ -739,6 +748,7 @@ class FlutterPlatform extends PlatformPlugin {
|
|||||||
testConfigFile: findTestConfigFile(globals.fs.file(testUrl)),
|
testConfigFile: findTestConfigFile(globals.fs.file(testUrl)),
|
||||||
host: host,
|
host: host,
|
||||||
updateGoldens: updateGoldens,
|
updateGoldens: updateGoldens,
|
||||||
|
nullSafety: dartExperiments.contains('non-nullable'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class FlutterWebPlatform extends PlatformPlugin {
|
|||||||
|
|
||||||
_testGoldenComparator = TestGoldenComparator(
|
_testGoldenComparator = TestGoldenComparator(
|
||||||
shellPath,
|
shellPath,
|
||||||
() => TestCompiler(BuildMode.debug, false, flutterProject),
|
() => TestCompiler(BuildMode.debug, false, flutterProject, <String>[]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ abstract class FlutterTestRunner {
|
|||||||
Directory coverageDirectory,
|
Directory coverageDirectory,
|
||||||
bool web = false,
|
bool web = false,
|
||||||
String randomSeed,
|
String randomSeed,
|
||||||
|
@required List<String> dartExperiments,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +85,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
|||||||
Directory coverageDirectory,
|
Directory coverageDirectory,
|
||||||
bool web = false,
|
bool web = false,
|
||||||
String randomSeed,
|
String randomSeed,
|
||||||
|
@required List<String> dartExperiments,
|
||||||
}) async {
|
}) async {
|
||||||
// Configure package:test to use the Flutter engine for child processes.
|
// Configure package:test to use the Flutter engine for child processes.
|
||||||
final String shellPath = globals.artifacts.getArtifactPath(Artifact.flutterTester);
|
final String shellPath = globals.artifacts.getArtifactPath(Artifact.flutterTester);
|
||||||
@ -175,6 +177,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
|||||||
projectRootDirectory: globals.fs.currentDirectory.uri,
|
projectRootDirectory: globals.fs.currentDirectory.uri,
|
||||||
flutterProject: flutterProject,
|
flutterProject: flutterProject,
|
||||||
icudtlPath: icudtlPath,
|
icudtlPath: icudtlPath,
|
||||||
|
dartExperiments: dartExperiments,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Make the global packages path absolute.
|
// Make the global packages path absolute.
|
||||||
|
@ -42,6 +42,7 @@ class TestCompiler {
|
|||||||
this.buildMode,
|
this.buildMode,
|
||||||
this.trackWidgetCreation,
|
this.trackWidgetCreation,
|
||||||
this.flutterProject,
|
this.flutterProject,
|
||||||
|
this.dartExperiments,
|
||||||
) : testFilePath = getKernelPathForTransformerOptions(
|
) : testFilePath = getKernelPathForTransformerOptions(
|
||||||
globals.fs.path.join(flutterProject.directory.path, getBuildDirectory(), 'testfile.dill'),
|
globals.fs.path.join(flutterProject.directory.path, getBuildDirectory(), 'testfile.dill'),
|
||||||
trackWidgetCreation: trackWidgetCreation,
|
trackWidgetCreation: trackWidgetCreation,
|
||||||
@ -65,6 +66,7 @@ class TestCompiler {
|
|||||||
final BuildMode buildMode;
|
final BuildMode buildMode;
|
||||||
final bool trackWidgetCreation;
|
final bool trackWidgetCreation;
|
||||||
final String testFilePath;
|
final String testFilePath;
|
||||||
|
final List<String> dartExperiments;
|
||||||
|
|
||||||
|
|
||||||
ResidentCompiler compiler;
|
ResidentCompiler compiler;
|
||||||
@ -104,6 +106,7 @@ class TestCompiler {
|
|||||||
unsafePackageSerialization: false,
|
unsafePackageSerialization: false,
|
||||||
dartDefines: const <String>[],
|
dartDefines: const <String>[],
|
||||||
packagesPath: globalPackagesPath,
|
packagesPath: globalPackagesPath,
|
||||||
|
experimentalFlags: dartExperiments,
|
||||||
);
|
);
|
||||||
if (flutterProject.hasBuilders) {
|
if (flutterProject.hasBuilders) {
|
||||||
return CodeGeneratingResidentCompiler.create(
|
return CodeGeneratingResidentCompiler.create(
|
||||||
|
@ -184,6 +184,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
|
|||||||
Directory coverageDirectory,
|
Directory coverageDirectory,
|
||||||
bool web = false,
|
bool web = false,
|
||||||
String randomSeed,
|
String randomSeed,
|
||||||
|
@override List<String> dartExperiments,
|
||||||
}) async {
|
}) async {
|
||||||
lastEnableObservatoryValue = enableObservatory;
|
lastEnableObservatoryValue = enableObservatory;
|
||||||
return exitCode;
|
return exitCode;
|
||||||
|
@ -17,15 +17,29 @@ import '../src/context.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('FlutterPlatform', () {
|
group('FlutterPlatform', () {
|
||||||
testUsingContext('ensureConfiguration throws an error if an explicitObservatoryPort is specified and more than one test file', () async {
|
testUsingContext('ensureConfiguration throws an error if an '
|
||||||
final FlutterPlatform flutterPlatform = FlutterPlatform(buildMode: BuildMode.debug, shellPath: '/', explicitObservatoryPort: 1234);
|
'explicitObservatoryPort is specified and more than one test file', () async {
|
||||||
|
final FlutterPlatform flutterPlatform = FlutterPlatform(
|
||||||
|
buildMode: BuildMode.debug,
|
||||||
|
shellPath: '/',
|
||||||
|
explicitObservatoryPort: 1234,
|
||||||
|
dartExperiments: <String>[],
|
||||||
|
);
|
||||||
flutterPlatform.loadChannel('test1.dart', MockSuitePlatform());
|
flutterPlatform.loadChannel('test1.dart', MockSuitePlatform());
|
||||||
|
|
||||||
expect(() => flutterPlatform.loadChannel('test2.dart', MockSuitePlatform()), throwsToolExit());
|
expect(() => flutterPlatform.loadChannel('test2.dart', MockSuitePlatform()), throwsToolExit());
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('ensureConfiguration throws an error if a precompiled entrypoint is specified and more that one test file', () {
|
testUsingContext('ensureConfiguration throws an error if a precompiled '
|
||||||
final FlutterPlatform flutterPlatform = FlutterPlatform(buildMode: BuildMode.debug, shellPath: '/', precompiledDillPath: 'example.dill');
|
'entrypoint is specified and more that one test file', () {
|
||||||
|
final FlutterPlatform flutterPlatform = FlutterPlatform(
|
||||||
|
buildMode: BuildMode.debug,
|
||||||
|
shellPath: '/',
|
||||||
|
precompiledDillPath: 'example.dill',
|
||||||
|
dartExperiments: <String>[],
|
||||||
|
);
|
||||||
flutterPlatform.loadChannel('test1.dart', MockSuitePlatform());
|
flutterPlatform.loadChannel('test1.dart', MockSuitePlatform());
|
||||||
|
|
||||||
expect(() => flutterPlatform.loadChannel('test2.dart', MockSuitePlatform()), throwsToolExit());
|
expect(() => flutterPlatform.loadChannel('test2.dart', MockSuitePlatform()), throwsToolExit());
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -99,6 +113,7 @@ void main() {
|
|||||||
shellPath: 'abc',
|
shellPath: 'abc',
|
||||||
enableObservatory: false,
|
enableObservatory: false,
|
||||||
startPaused: true,
|
startPaused: true,
|
||||||
|
dartExperiments: <String>[],
|
||||||
), throwsAssertionError);
|
), throwsAssertionError);
|
||||||
|
|
||||||
expect(() => installHook(
|
expect(() => installHook(
|
||||||
@ -107,6 +122,7 @@ void main() {
|
|||||||
enableObservatory: false,
|
enableObservatory: false,
|
||||||
startPaused: false,
|
startPaused: false,
|
||||||
observatoryPort: 123,
|
observatoryPort: 123,
|
||||||
|
dartExperiments: <String>[],
|
||||||
), throwsAssertionError);
|
), throwsAssertionError);
|
||||||
|
|
||||||
FlutterPlatform capturedPlatform;
|
FlutterPlatform capturedPlatform;
|
||||||
@ -127,6 +143,7 @@ void main() {
|
|||||||
observatoryPort: 200,
|
observatoryPort: 200,
|
||||||
serverType: InternetAddressType.IPv6,
|
serverType: InternetAddressType.IPv6,
|
||||||
icudtlPath: 'ghi',
|
icudtlPath: 'ghi',
|
||||||
|
dartExperiments: <String>[],
|
||||||
platformPluginRegistration: (FlutterPlatform platform) {
|
platformPluginRegistration: (FlutterPlatform platform) {
|
||||||
capturedPlatform = platform;
|
capturedPlatform = platform;
|
||||||
});
|
});
|
||||||
@ -175,6 +192,7 @@ class TestFlutterPlatform extends FlutterPlatform {
|
|||||||
startPaused: false,
|
startPaused: false,
|
||||||
enableObservatory: false,
|
enableObservatory: false,
|
||||||
buildTestAssets: false,
|
buildTestAssets: false,
|
||||||
|
dartExperiments: <String>[],
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -96,7 +96,7 @@ class FakeTestCompiler extends TestCompiler {
|
|||||||
bool trackWidgetCreation,
|
bool trackWidgetCreation,
|
||||||
FlutterProject flutterProject,
|
FlutterProject flutterProject,
|
||||||
this.residentCompiler,
|
this.residentCompiler,
|
||||||
) : super(buildMode, trackWidgetCreation, flutterProject);
|
) : super(buildMode, trackWidgetCreation, flutterProject, <String>[]);
|
||||||
|
|
||||||
final MockResidentCompiler residentCompiler;
|
final MockResidentCompiler residentCompiler;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user