Unverified Commit 1ab38789 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] support --enable-experiment in flutter test (#55564)

Support --enable-experiment in flutter test (for flutter_tester). Required minor change for null safety.
parent 07c451fe
......@@ -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_test'), 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(
path.join(flutterRoot, 'dev', 'tracing_tests'),
options: <String>['--enable-vmservice'],
......
......@@ -3,3 +3,4 @@
analyzer:
exclude:
- lib/main.dart
- test/test_test.dart
// 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),
icudtlPath: globals.fs.path.absolute(argResults[_kOptionIcudtl] as String),
coverageDirectory: coverageDirectory,
dartExperiments: <String>[],
);
if (collector != null) {
......
......@@ -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(
......
......@@ -184,6 +184,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
Directory coverageDirectory,
bool web = false,
String randomSeed,
@override List<String> dartExperiments,
}) async {
lastEnableObservatoryValue = enableObservatory;
return exitCode;
......
......@@ -17,15 +17,29 @@ import '../src/context.dart';
void main() {
group('FlutterPlatform', () {
testUsingContext('ensureConfiguration throws an error if an explicitObservatoryPort is specified and more than one test file', () async {
final FlutterPlatform flutterPlatform = FlutterPlatform(buildMode: BuildMode.debug, shellPath: '/', explicitObservatoryPort: 1234);
testUsingContext('ensureConfiguration throws an error if an '
'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());
expect(() => flutterPlatform.loadChannel('test2.dart', MockSuitePlatform()), throwsToolExit());
});
testUsingContext('ensureConfiguration throws an error if a precompiled entrypoint is specified and more that one test file', () {
final FlutterPlatform flutterPlatform = FlutterPlatform(buildMode: BuildMode.debug, shellPath: '/', precompiledDillPath: 'example.dill');
testUsingContext('ensureConfiguration throws an error if a precompiled '
'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());
expect(() => flutterPlatform.loadChannel('test2.dart', MockSuitePlatform()), throwsToolExit());
});
......@@ -99,6 +113,7 @@ void main() {
shellPath: 'abc',
enableObservatory: false,
startPaused: true,
dartExperiments: <String>[],
), throwsAssertionError);
expect(() => installHook(
......@@ -107,6 +122,7 @@ void main() {
enableObservatory: false,
startPaused: false,
observatoryPort: 123,
dartExperiments: <String>[],
), throwsAssertionError);
FlutterPlatform capturedPlatform;
......@@ -127,6 +143,7 @@ void main() {
observatoryPort: 200,
serverType: InternetAddressType.IPv6,
icudtlPath: 'ghi',
dartExperiments: <String>[],
platformPluginRegistration: (FlutterPlatform platform) {
capturedPlatform = platform;
});
......@@ -175,6 +192,7 @@ class TestFlutterPlatform extends FlutterPlatform {
startPaused: false,
enableObservatory: false,
buildTestAssets: false,
dartExperiments: <String>[],
);
@override
......
......@@ -96,7 +96,7 @@ class FakeTestCompiler extends TestCompiler {
bool trackWidgetCreation,
FlutterProject flutterProject,
this.residentCompiler,
) : super(buildMode, trackWidgetCreation, flutterProject);
) : super(buildMode, trackWidgetCreation, flutterProject, <String>[]);
final MockResidentCompiler residentCompiler;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment