Update build-all test for null-safe template (#3773)

Flutter master now creates NNBD code when running 'flutter create', so
the generated pubspec for build_all needs to use a compatible SDK
version. This updates from 2.0.0 to 2.12.0.

Also includes a test for this, which involved setting up tests for the
file, and doing some refactoring to make the command testable. As a
result, this fixes https://github.com/flutter/flutter/issues/61049
(although more test backfill is needed).
This commit is contained in:
stuartmorgan
2021-03-30 13:34:20 -07:00
committed by GitHub
parent b98ea9175b
commit b8b7ef5cd5
3 changed files with 131 additions and 28 deletions

View File

@ -12,11 +12,21 @@ import 'package:pubspec_parse/pubspec_parse.dart';
import 'common.dart';
// TODO(cyanglaz): Add tests for this command.
// https://github.com/flutter/flutter/issues/61049
class CreateAllPluginsAppCommand extends PluginCommand {
CreateAllPluginsAppCommand(Directory packagesDir, FileSystem fileSystem)
: super(packagesDir, fileSystem);
CreateAllPluginsAppCommand(
Directory packagesDir,
FileSystem fileSystem, {
this.pluginsRoot,
}) : super(packagesDir, fileSystem) {
pluginsRoot ??= fileSystem.currentDirectory;
appDirectory = pluginsRoot.childDirectory('all_plugins');
}
/// The root directory of the plugin repository.
Directory pluginsRoot;
/// The location of the synthesized app project.
Directory appDirectory;
@override
String get description =>
@ -27,7 +37,7 @@ class CreateAllPluginsAppCommand extends PluginCommand {
@override
Future<Null> run() async {
final int exitCode = await _createPlugin();
final int exitCode = await _createApp();
if (exitCode != 0) {
throw ToolExit(exitCode);
}
@ -39,7 +49,7 @@ class CreateAllPluginsAppCommand extends PluginCommand {
]);
}
Future<int> _createPlugin() async {
Future<int> _createApp() async {
final io.ProcessResult result = io.Process.runSync(
'flutter',
<String>[
@ -47,7 +57,7 @@ class CreateAllPluginsAppCommand extends PluginCommand {
'--template=app',
'--project-name=all_plugins',
'--android-language=java',
'./all_plugins',
appDirectory.path,
],
);
@ -57,12 +67,10 @@ class CreateAllPluginsAppCommand extends PluginCommand {
}
Future<void> _updateAppGradle() async {
final File gradleFile = fileSystem.file(p.join(
'all_plugins',
'android',
'app',
'build.gradle',
));
final File gradleFile = appDirectory
.childDirectory('android')
.childDirectory('app')
.childFile('build.gradle');
if (!gradleFile.existsSync()) {
throw ToolExit(64);
}
@ -86,14 +94,12 @@ class CreateAllPluginsAppCommand extends PluginCommand {
}
Future<void> _updateManifest() async {
final File manifestFile = fileSystem.file(p.join(
'all_plugins',
'android',
'app',
'src',
'main',
'AndroidManifest.xml',
));
final File manifestFile = appDirectory
.childDirectory('android')
.childDirectory('app')
.childDirectory('src')
.childDirectory('main')
.childFile('AndroidManifest.xml');
if (!manifestFile.existsSync()) {
throw ToolExit(64);
}
@ -124,7 +130,7 @@ class CreateAllPluginsAppCommand extends PluginCommand {
version: Version.parse('1.0.0+1'),
environment: <String, VersionConstraint>{
'sdk': VersionConstraint.compatibleWith(
Version.parse('2.0.0'),
Version.parse('2.12.0'),
),
},
dependencies: <String, Dependency>{
@ -135,8 +141,7 @@ class CreateAllPluginsAppCommand extends PluginCommand {
},
dependencyOverrides: pluginDeps,
);
final File pubspecFile =
fileSystem.file(p.join('all_plugins', 'pubspec.yaml'));
final File pubspecFile = appDirectory.childFile('pubspec.yaml');
pubspecFile.writeAsStringSync(_pubspecToString(pubspec));
}