Unverified Commit 530324d2 authored by Jesús S Guerrero's avatar Jesús S Guerrero Committed by GitHub

Build command dependency injection (#114383)

* update flutter build command

* update tests

* fix analyze suggestions
parent 9797d5f1
...@@ -165,7 +165,14 @@ List<FlutterCommand> generateCommands({ ...@@ -165,7 +165,14 @@ List<FlutterCommand> generateCommands({
processInfo: globals.processInfo, processInfo: globals.processInfo,
fileSystem: globals.fs, fileSystem: globals.fs,
), ),
BuildCommand(verboseHelp: verboseHelp), BuildCommand(
fileSystem: globals.fs,
buildSystem: globals.buildSystem,
osUtils: globals.os,
verboseHelp: verboseHelp,
androidSdk: globals.androidSdk,
logger: globals.logger,
),
ChannelCommand(verboseHelp: verboseHelp), ChannelCommand(verboseHelp: verboseHelp),
CleanCommand(verbose: verbose), CleanCommand(verbose: verbose),
ConfigCommand(verboseHelp: verboseHelp), ConfigCommand(verboseHelp: verboseHelp),
......
...@@ -4,11 +4,15 @@ ...@@ -4,11 +4,15 @@
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../android/android_sdk.dart';
import '../base/file_system.dart';
import '../base/logger.dart';
import '../base/os.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../build_system/build_system.dart';
import '../commands/build_linux.dart'; import '../commands/build_linux.dart';
import '../commands/build_macos.dart'; import '../commands/build_macos.dart';
import '../commands/build_windows.dart'; import '../commands/build_windows.dart';
import '../globals.dart' as globals;
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import 'build_aar.dart'; import 'build_aar.dart';
import 'build_apk.dart'; import 'build_apk.dart';
...@@ -20,28 +24,49 @@ import 'build_macos_framework.dart'; ...@@ -20,28 +24,49 @@ import 'build_macos_framework.dart';
import 'build_web.dart'; import 'build_web.dart';
class BuildCommand extends FlutterCommand { class BuildCommand extends FlutterCommand {
BuildCommand({ bool verboseHelp = false }) { BuildCommand({
_addSubcommand(BuildAarCommand(verboseHelp: verboseHelp)); required FileSystem fileSystem,
_addSubcommand(BuildApkCommand(verboseHelp: verboseHelp)); required BuildSystem buildSystem,
_addSubcommand(BuildAppBundleCommand(verboseHelp: verboseHelp)); required OperatingSystemUtils osUtils,
_addSubcommand(BuildIOSCommand(verboseHelp: verboseHelp)); required Logger logger,
required AndroidSdk? androidSdk,
bool verboseHelp = false,
}){
_addSubcommand(
BuildAarCommand(
fileSystem: fileSystem,
androidSdk: androidSdk,
logger: logger,
verboseHelp: verboseHelp,
)
);
_addSubcommand(BuildApkCommand(logger: logger, verboseHelp: verboseHelp));
_addSubcommand(BuildAppBundleCommand(logger: logger, verboseHelp: verboseHelp));
_addSubcommand(BuildIOSCommand(logger: logger, verboseHelp: verboseHelp));
_addSubcommand(BuildIOSFrameworkCommand( _addSubcommand(BuildIOSFrameworkCommand(
buildSystem: globals.buildSystem, logger: logger,
buildSystem: buildSystem,
verboseHelp: verboseHelp, verboseHelp: verboseHelp,
)); ));
_addSubcommand(BuildMacOSFrameworkCommand( _addSubcommand(BuildMacOSFrameworkCommand(
buildSystem: globals.buildSystem, logger: logger,
buildSystem: buildSystem,
verboseHelp: verboseHelp, verboseHelp: verboseHelp,
)); ));
_addSubcommand(BuildIOSArchiveCommand(verboseHelp: verboseHelp)); _addSubcommand(BuildIOSArchiveCommand(logger: logger, verboseHelp: verboseHelp));
_addSubcommand(BuildBundleCommand(verboseHelp: verboseHelp)); _addSubcommand(BuildBundleCommand(logger: logger, verboseHelp: verboseHelp));
_addSubcommand(BuildWebCommand(verboseHelp: verboseHelp)); _addSubcommand(BuildWebCommand(
_addSubcommand(BuildMacosCommand(verboseHelp: verboseHelp)); fileSystem: fileSystem,
logger: logger,
verboseHelp: verboseHelp,
));
_addSubcommand(BuildMacosCommand(logger: logger, verboseHelp: verboseHelp));
_addSubcommand(BuildLinuxCommand( _addSubcommand(BuildLinuxCommand(
operatingSystemUtils: globals.os, logger: logger,
operatingSystemUtils: osUtils,
verboseHelp: verboseHelp verboseHelp: verboseHelp
)); ));
_addSubcommand(BuildWindowsCommand(verboseHelp: verboseHelp)); _addSubcommand(BuildWindowsCommand(logger: logger, verboseHelp: verboseHelp));
} }
void _addSubcommand(BuildSubCommand command) { void _addSubcommand(BuildSubCommand command) {
...@@ -64,11 +89,16 @@ class BuildCommand extends FlutterCommand { ...@@ -64,11 +89,16 @@ class BuildCommand extends FlutterCommand {
} }
abstract class BuildSubCommand extends FlutterCommand { abstract class BuildSubCommand extends FlutterCommand {
BuildSubCommand({required bool verboseHelp}) { BuildSubCommand({
required Logger logger,
required bool verboseHelp
}): _logger = logger {
requiresPubspecYaml(); requiresPubspecYaml();
usesFatalWarningsOption(verboseHelp: verboseHelp); usesFatalWarningsOption(verboseHelp: verboseHelp);
} }
final Logger _logger;
@override @override
bool get reportNullSafety => true; bool get reportNullSafety => true;
...@@ -80,21 +110,21 @@ abstract class BuildSubCommand extends FlutterCommand { ...@@ -80,21 +110,21 @@ abstract class BuildSubCommand extends FlutterCommand {
/// This is similar to the run message in run_hot.dart /// This is similar to the run message in run_hot.dart
@protected @protected
void displayNullSafetyMode(BuildInfo buildInfo) { void displayNullSafetyMode(BuildInfo buildInfo) {
globals.printStatus(''); _logger.printStatus('');
if (buildInfo.nullSafetyMode == NullSafetyMode.sound) { if (buildInfo.nullSafetyMode == NullSafetyMode.sound) {
globals.printStatus( _logger.printStatus(
'💪 Building with sound null safety 💪', '💪 Building with sound null safety 💪',
emphasis: true, emphasis: true,
); );
} else { } else {
globals.printStatus( _logger.printStatus(
'Building without sound null safety ⚠️', 'Building without sound null safety ⚠️',
emphasis: true, emphasis: true,
); );
globals.printStatus( _logger.printStatus(
'Dart 3 will only support sound null safety, see https://dart.dev/null-safety', 'Dart 3 will only support sound null safety, see https://dart.dev/null-safety',
); );
} }
globals.printStatus(''); _logger.printStatus('');
} }
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import '../android/android_builder.dart'; import '../android/android_builder.dart';
import '../android/android_sdk.dart';
import '../android/gradle_utils.dart'; import '../android/gradle_utils.dart';
import '../base/common.dart'; import '../base/common.dart';
...@@ -10,14 +11,20 @@ import '../base/file_system.dart'; ...@@ -10,14 +11,20 @@ import '../base/file_system.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../cache.dart'; import '../cache.dart';
import '../globals.dart' as globals;
import '../project.dart'; import '../project.dart';
import '../reporting/reporting.dart'; import '../reporting/reporting.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult; import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart'; import 'build.dart';
class BuildAarCommand extends BuildSubCommand { class BuildAarCommand extends BuildSubCommand {
BuildAarCommand({ required bool verboseHelp }) : super(verboseHelp: verboseHelp) { BuildAarCommand({
required super.logger,
required AndroidSdk? androidSdk,
required FileSystem fileSystem,
required bool verboseHelp,
}): _androidSdk = androidSdk,
_fileSystem = fileSystem,
super(verboseHelp: verboseHelp) {
argParser argParser
..addFlag( ..addFlag(
'debug', 'debug',
...@@ -55,6 +62,8 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -55,6 +62,8 @@ class BuildAarCommand extends BuildSubCommand {
help: 'The target platform for which the project is compiled.', help: 'The target platform for which the project is compiled.',
); );
} }
final AndroidSdk? _androidSdk;
final FileSystem _fileSystem;
@override @override
final String name = 'aar'; final String name = 'aar';
...@@ -100,7 +109,7 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -100,7 +109,7 @@ class BuildAarCommand extends BuildSubCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
if (globals.androidSdk == null) { if (_androidSdk == null) {
exitWithNoSdkMessage(); exitWithNoSdkMessage();
} }
final Set<AndroidBuildInfo> androidBuildInfo = <AndroidBuildInfo>{}; final Set<AndroidBuildInfo> androidBuildInfo = <AndroidBuildInfo>{};
...@@ -115,7 +124,7 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -115,7 +124,7 @@ class BuildAarCommand extends BuildSubCommand {
? buildNumberArg ? buildNumberArg
: '1.0'; : '1.0';
final File targetFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart')); final File targetFile = _fileSystem.file(_fileSystem.path.join('lib', 'main.dart'));
for (final String buildMode in const <String>['debug', 'profile', 'release']) { for (final String buildMode in const <String>['debug', 'profile', 'release']) {
if (boolArgDeprecated(buildMode)) { if (boolArgDeprecated(buildMode)) {
androidBuildInfo.add( androidBuildInfo.add(
...@@ -151,10 +160,10 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -151,10 +160,10 @@ class BuildAarCommand extends BuildSubCommand {
if (remainingArguments.isEmpty) { if (remainingArguments.isEmpty) {
return FlutterProject.current(); return FlutterProject.current();
} }
final File mainFile = globals.fs.file(remainingArguments.first); final File mainFile = _fileSystem.file(remainingArguments.first);
final String path; final String path;
if (!mainFile.existsSync()) { if (!mainFile.existsSync()) {
final Directory pathProject = globals.fs.directory(remainingArguments.first); final Directory pathProject = _fileSystem.directory(remainingArguments.first);
if (!pathProject.existsSync()) { if (!pathProject.existsSync()) {
throwToolExit('${remainingArguments.first} does not exist'); throwToolExit('${remainingArguments.first} does not exist');
} }
...@@ -162,10 +171,10 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -162,10 +171,10 @@ class BuildAarCommand extends BuildSubCommand {
} else { } else {
path = mainFile.parent.path; path = mainFile.parent.path;
} }
final String? projectRoot = findProjectRoot(globals.fs, path); final String? projectRoot = findProjectRoot(_fileSystem, path);
if (projectRoot == null) { if (projectRoot == null) {
throwToolExit('${mainFile.parent.path} is not a valid flutter project'); throwToolExit('${mainFile.parent.path} is not a valid flutter project');
} }
return FlutterProject.fromDirectory(globals.fs.directory(projectRoot)); return FlutterProject.fromDirectory(_fileSystem.directory(projectRoot));
} }
} }
...@@ -14,7 +14,9 @@ import '../runner/flutter_command.dart' show FlutterCommandResult; ...@@ -14,7 +14,9 @@ import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart'; import 'build.dart';
class BuildApkCommand extends BuildSubCommand { class BuildApkCommand extends BuildSubCommand {
BuildApkCommand({bool verboseHelp = false}) : super(verboseHelp: verboseHelp) { BuildApkCommand({
required super.logger, bool verboseHelp = false
}) : super(verboseHelp: verboseHelp) {
addTreeShakeIconsFlag(); addTreeShakeIconsFlag();
usesTargetOption(); usesTargetOption();
addBuildModeFlags(verboseHelp: verboseHelp); addBuildModeFlags(verboseHelp: verboseHelp);
......
...@@ -18,6 +18,7 @@ import 'build.dart'; ...@@ -18,6 +18,7 @@ import 'build.dart';
class BuildAppBundleCommand extends BuildSubCommand { class BuildAppBundleCommand extends BuildSubCommand {
BuildAppBundleCommand({ BuildAppBundleCommand({
required super.logger,
bool verboseHelp = false, bool verboseHelp = false,
}) : super(verboseHelp: verboseHelp) { }) : super(verboseHelp: verboseHelp) {
addTreeShakeIconsFlag(); addTreeShakeIconsFlag();
......
...@@ -15,6 +15,7 @@ import 'build.dart'; ...@@ -15,6 +15,7 @@ import 'build.dart';
class BuildBundleCommand extends BuildSubCommand { class BuildBundleCommand extends BuildSubCommand {
BuildBundleCommand({ BuildBundleCommand({
required super.logger,
bool verboseHelp = false, bool verboseHelp = false,
BundleBuilder? bundleBuilder, BundleBuilder? bundleBuilder,
}) : _bundleBuilder = bundleBuilder ?? BundleBuilder(), super(verboseHelp: verboseHelp) { }) : _bundleBuilder = bundleBuilder ?? BundleBuilder(), super(verboseHelp: verboseHelp) {
......
...@@ -22,7 +22,7 @@ import 'build.dart'; ...@@ -22,7 +22,7 @@ import 'build.dart';
/// Builds an .app for an iOS app to be used for local testing on an iOS device /// Builds an .app for an iOS app to be used for local testing on an iOS device
/// or simulator. Can only be run on a macOS host. /// or simulator. Can only be run on a macOS host.
class BuildIOSCommand extends _BuildIOSSubCommand { class BuildIOSCommand extends _BuildIOSSubCommand {
BuildIOSCommand({ required super.verboseHelp }) { BuildIOSCommand({ required super.logger, required super.verboseHelp }) {
argParser argParser
..addFlag('config-only', ..addFlag('config-only',
help: 'Update the project configuration without performing a build. ' help: 'Update the project configuration without performing a build. '
...@@ -59,7 +59,7 @@ class BuildIOSCommand extends _BuildIOSSubCommand { ...@@ -59,7 +59,7 @@ class BuildIOSCommand extends _BuildIOSSubCommand {
/// ///
/// Can only be run on a macOS host. /// Can only be run on a macOS host.
class BuildIOSArchiveCommand extends _BuildIOSSubCommand { class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
BuildIOSArchiveCommand({required super.verboseHelp}) { BuildIOSArchiveCommand({required super.logger, required super.verboseHelp}) {
argParser.addOption( argParser.addOption(
'export-method', 'export-method',
defaultsTo: 'app-store', defaultsTo: 'app-store',
...@@ -293,6 +293,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { ...@@ -293,6 +293,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
abstract class _BuildIOSSubCommand extends BuildSubCommand { abstract class _BuildIOSSubCommand extends BuildSubCommand {
_BuildIOSSubCommand({ _BuildIOSSubCommand({
required super.logger,
required bool verboseHelp required bool verboseHelp
}) : super(verboseHelp: verboseHelp) { }) : super(verboseHelp: verboseHelp) {
addTreeShakeIconsFlag(); addTreeShakeIconsFlag();
......
...@@ -33,6 +33,7 @@ abstract class BuildFrameworkCommand extends BuildSubCommand { ...@@ -33,6 +33,7 @@ abstract class BuildFrameworkCommand extends BuildSubCommand {
required bool verboseHelp, required bool verboseHelp,
Cache? cache, Cache? cache,
Platform? platform, Platform? platform,
required super.logger,
}) : _injectedFlutterVersion = flutterVersion, }) : _injectedFlutterVersion = flutterVersion,
_buildSystem = buildSystem, _buildSystem = buildSystem,
_injectedCache = cache, _injectedCache = cache,
...@@ -176,6 +177,7 @@ abstract class BuildFrameworkCommand extends BuildSubCommand { ...@@ -176,6 +177,7 @@ abstract class BuildFrameworkCommand extends BuildSubCommand {
/// managers. /// managers.
class BuildIOSFrameworkCommand extends BuildFrameworkCommand { class BuildIOSFrameworkCommand extends BuildFrameworkCommand {
BuildIOSFrameworkCommand({ BuildIOSFrameworkCommand({
required super.logger,
super.flutterVersion, super.flutterVersion,
required super.buildSystem, required super.buildSystem,
required bool verboseHelp, required bool verboseHelp,
......
...@@ -17,6 +17,7 @@ import 'build.dart'; ...@@ -17,6 +17,7 @@ import 'build.dart';
/// A command to build a linux desktop target through a build shell script. /// A command to build a linux desktop target through a build shell script.
class BuildLinuxCommand extends BuildSubCommand { class BuildLinuxCommand extends BuildSubCommand {
BuildLinuxCommand({ BuildLinuxCommand({
required super.logger,
required OperatingSystemUtils operatingSystemUtils, required OperatingSystemUtils operatingSystemUtils,
bool verboseHelp = false, bool verboseHelp = false,
}) : _operatingSystemUtils = operatingSystemUtils, }) : _operatingSystemUtils = operatingSystemUtils,
......
...@@ -16,6 +16,7 @@ import 'build.dart'; ...@@ -16,6 +16,7 @@ import 'build.dart';
/// A command to build a macOS desktop target through a build shell script. /// A command to build a macOS desktop target through a build shell script.
class BuildMacosCommand extends BuildSubCommand { class BuildMacosCommand extends BuildSubCommand {
BuildMacosCommand({ BuildMacosCommand({
required super.logger,
required bool verboseHelp, required bool verboseHelp,
}) : super(verboseHelp: verboseHelp) { }) : super(verboseHelp: verboseHelp) {
addCommonDesktopBuildOptions(verboseHelp: verboseHelp); addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
......
...@@ -29,6 +29,7 @@ class BuildMacOSFrameworkCommand extends BuildFrameworkCommand { ...@@ -29,6 +29,7 @@ class BuildMacOSFrameworkCommand extends BuildFrameworkCommand {
super.flutterVersion, super.flutterVersion,
required super.buildSystem, required super.buildSystem,
required super.verboseHelp, required super.verboseHelp,
required super.logger,
super.cache, super.cache,
super.platform, super.platform,
}); });
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
// found in the LICENSE file. // found in the LICENSE file.
import '../base/common.dart'; import '../base/common.dart';
import '../base/file_system.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../build_system/targets/web.dart'; import '../build_system/targets/web.dart';
import '../features.dart'; import '../features.dart';
import '../globals.dart' as globals;
import '../project.dart'; import '../project.dart';
import '../runner/flutter_command.dart' import '../runner/flutter_command.dart'
show DevelopmentArtifact, FlutterCommandResult; show DevelopmentArtifact, FlutterCommandResult;
...@@ -15,8 +15,10 @@ import 'build.dart'; ...@@ -15,8 +15,10 @@ import 'build.dart';
class BuildWebCommand extends BuildSubCommand { class BuildWebCommand extends BuildSubCommand {
BuildWebCommand({ BuildWebCommand({
required super.logger,
required FileSystem fileSystem,
required bool verboseHelp, required bool verboseHelp,
}) : super(verboseHelp: verboseHelp) { }) : _fileSystem = fileSystem, super(verboseHelp: verboseHelp) {
addTreeShakeIconsFlag(enabledByDefault: false); addTreeShakeIconsFlag(enabledByDefault: false);
usesTargetOption(); usesTargetOption();
usesOutputDir(); usesOutputDir();
...@@ -70,6 +72,8 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -70,6 +72,8 @@ class BuildWebCommand extends BuildSubCommand {
); );
} }
final FileSystem _fileSystem;
@override @override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => Future<Set<DevelopmentArtifact>> get requiredArtifacts async =>
const <DevelopmentArtifact>{ const <DevelopmentArtifact>{
...@@ -103,7 +107,7 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -103,7 +107,7 @@ class BuildWebCommand extends BuildSubCommand {
if (!flutterProject.web.existsSync()) { if (!flutterProject.web.existsSync()) {
throwToolExit('Missing index.html.'); throwToolExit('Missing index.html.');
} }
if (!globals.fs.currentDirectory if (!_fileSystem.currentDirectory
.childDirectory('web') .childDirectory('web')
.childFile('index.html') .childFile('index.html')
.readAsStringSync() .readAsStringSync()
......
...@@ -19,6 +19,7 @@ import 'build.dart'; ...@@ -19,6 +19,7 @@ import 'build.dart';
/// A command to build a windows desktop target through a build shell script. /// A command to build a windows desktop target through a build shell script.
class BuildWindowsCommand extends BuildSubCommand { class BuildWindowsCommand extends BuildSubCommand {
BuildWindowsCommand({ BuildWindowsCommand({
required super.logger,
bool verboseHelp = false, bool verboseHelp = false,
}) : super(verboseHelp: verboseHelp) { }) : super(verboseHelp: verboseHelp) {
addCommonDesktopBuildOptions(verboseHelp: verboseHelp); addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/build_system/build_system.dart';
...@@ -66,6 +67,7 @@ void main() { ...@@ -66,6 +67,7 @@ void main() {
final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(frameworkVersion: frameworkVersion); final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(frameworkVersion: frameworkVersion);
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand( final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -95,6 +97,7 @@ void main() { ...@@ -95,6 +97,7 @@ void main() {
); );
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand( final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -121,6 +124,7 @@ void main() { ...@@ -121,6 +124,7 @@ void main() {
); );
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand( final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -162,6 +166,7 @@ void main() { ...@@ -162,6 +166,7 @@ void main() {
); );
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand( final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -196,6 +201,7 @@ void main() { ...@@ -196,6 +201,7 @@ void main() {
testUsingContext('contains license and version', () async { testUsingContext('contains license and version', () async {
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand( final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -216,6 +222,7 @@ void main() { ...@@ -216,6 +222,7 @@ void main() {
testUsingContext('debug URL', () async { testUsingContext('debug URL', () async {
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand( final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -234,6 +241,7 @@ void main() { ...@@ -234,6 +241,7 @@ void main() {
testUsingContext('profile URL', () async { testUsingContext('profile URL', () async {
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand( final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -252,6 +260,7 @@ void main() { ...@@ -252,6 +260,7 @@ void main() {
testUsingContext('release URL', () async { testUsingContext('release URL', () async {
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand( final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -295,6 +304,7 @@ void main() { ...@@ -295,6 +304,7 @@ void main() {
final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(frameworkVersion: frameworkVersion); final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(frameworkVersion: frameworkVersion);
final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand( final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -324,6 +334,7 @@ void main() { ...@@ -324,6 +334,7 @@ void main() {
); );
final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand( final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -350,6 +361,7 @@ void main() { ...@@ -350,6 +361,7 @@ void main() {
); );
final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand( final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -391,6 +403,7 @@ void main() { ...@@ -391,6 +403,7 @@ void main() {
); );
final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand( final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -425,6 +438,7 @@ void main() { ...@@ -425,6 +438,7 @@ void main() {
testUsingContext('contains license and version', () async { testUsingContext('contains license and version', () async {
final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand( final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -445,6 +459,7 @@ void main() { ...@@ -445,6 +459,7 @@ void main() {
testUsingContext('debug URL', () async { testUsingContext('debug URL', () async {
final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand( final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -463,6 +478,7 @@ void main() { ...@@ -463,6 +478,7 @@ void main() {
testUsingContext('profile URL', () async { testUsingContext('profile URL', () async {
final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand( final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
...@@ -481,6 +497,7 @@ void main() { ...@@ -481,6 +497,7 @@ void main() {
testUsingContext('release URL', () async { testUsingContext('release URL', () async {
final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand( final BuildMacOSFrameworkCommand command = BuildMacOSFrameworkCommand(
logger: BufferLogger.test(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)), buildSystem: TestBuildSystem.all(BuildResult(success: true)),
platform: fakePlatform, platform: fakePlatform,
flutterVersion: fakeFlutterVersion, flutterVersion: fakeFlutterVersion,
......
...@@ -11,6 +11,7 @@ import 'package:flutter_tools/src/base/file_system.dart'; ...@@ -11,6 +11,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build.dart'; import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/commands/build_macos.dart'; import 'package:flutter_tools/src/commands/build_macos.dart';
...@@ -23,6 +24,7 @@ import '../../src/common.dart'; ...@@ -23,6 +24,7 @@ import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/fake_process_manager.dart'; import '../../src/fake_process_manager.dart';
import '../../src/fakes.dart'; import '../../src/fakes.dart';
import '../../src/test_build_system.dart';
import '../../src/test_flutter_command_runner.dart'; import '../../src/test_flutter_command_runner.dart';
class FakeXcodeProjectInterpreterWithProfile extends FakeXcodeProjectInterpreter { class FakeXcodeProjectInterpreterWithProfile extends FakeXcodeProjectInterpreter {
...@@ -136,7 +138,13 @@ STDERR STUFF ...@@ -136,7 +138,13 @@ STDERR STUFF
} }
testUsingContext('macOS build fails when there is no macos project', () async { testUsingContext('macOS build fails when there is no macos project', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createCoreMockProjectFiles(); createCoreMockProjectFiles();
expect(createTestCommandRunner(command).run( expect(createTestCommandRunner(command).run(
...@@ -152,7 +160,13 @@ STDERR STUFF ...@@ -152,7 +160,13 @@ STDERR STUFF
}); });
testUsingContext('macOS build fails on non-macOS platform', () async { testUsingContext('macOS build fails on non-macOS platform', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
fileSystem.file('pubspec.yaml').createSync(); fileSystem.file('pubspec.yaml').createSync();
fileSystem.file(fileSystem.path.join('lib', 'main.dart')) fileSystem.file(fileSystem.path.join('lib', 'main.dart'))
.createSync(recursive: true); .createSync(recursive: true);
...@@ -168,7 +182,13 @@ STDERR STUFF ...@@ -168,7 +182,13 @@ STDERR STUFF
}); });
testUsingContext('macOS build fails when feature is disabled', () async { testUsingContext('macOS build fails when feature is disabled', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
fileSystem.file('pubspec.yaml').createSync(); fileSystem.file('pubspec.yaml').createSync();
fileSystem.file(fileSystem.path.join('lib', 'main.dart')) fileSystem.file(fileSystem.path.join('lib', 'main.dart'))
.createSync(recursive: true); .createSync(recursive: true);
...@@ -184,7 +204,13 @@ STDERR STUFF ...@@ -184,7 +204,13 @@ STDERR STUFF
}); });
testUsingContext('macOS build forwards error stdout to status logger error', () async { testUsingContext('macOS build forwards error stdout to status logger error', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles(); createMinimalMockProjectFiles();
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
...@@ -208,7 +234,13 @@ STDERR STUFF ...@@ -208,7 +234,13 @@ STDERR STUFF
}); });
testUsingContext('macOS build invokes xcode build (debug)', () async { testUsingContext('macOS build invokes xcode build (debug)', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles(); createMinimalMockProjectFiles();
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
...@@ -224,7 +256,13 @@ STDERR STUFF ...@@ -224,7 +256,13 @@ STDERR STUFF
}); });
testUsingContext('macOS build invokes xcode build (debug) with verbosity', () async { testUsingContext('macOS build invokes xcode build (debug) with verbosity', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles(); createMinimalMockProjectFiles();
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
...@@ -241,7 +279,13 @@ STDERR STUFF ...@@ -241,7 +279,13 @@ STDERR STUFF
testUsingContext('macOS build invokes xcode build (profile)', () async { testUsingContext('macOS build invokes xcode build (profile)', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles(); createMinimalMockProjectFiles();
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
...@@ -258,7 +302,13 @@ STDERR STUFF ...@@ -258,7 +302,13 @@ STDERR STUFF
}); });
testUsingContext('macOS build invokes xcode build (release)', () async { testUsingContext('macOS build invokes xcode build (release)', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles(); createMinimalMockProjectFiles();
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
...@@ -274,7 +324,13 @@ STDERR STUFF ...@@ -274,7 +324,13 @@ STDERR STUFF
}); });
testUsingContext('macOS build supports standard desktop build options', () async { testUsingContext('macOS build supports standard desktop build options', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles(); createMinimalMockProjectFiles();
fileSystem.file('lib/other.dart') fileSystem.file('lib/other.dart')
.createSync(recursive: true); .createSync(recursive: true);
...@@ -359,7 +415,13 @@ STDERR STUFF ...@@ -359,7 +415,13 @@ STDERR STUFF
), ),
]); ]);
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: fileSystem,
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
const <String>['build', 'macos', '--debug', '--no-pub'] const <String>['build', 'macos', '--debug', '--no-pub']
...@@ -375,7 +437,13 @@ STDERR STUFF ...@@ -375,7 +437,13 @@ STDERR STUFF
}); });
testUsingContext('macOS build supports build-name and build-number', () async { testUsingContext('macOS build supports build-name and build-number', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles(); createMinimalMockProjectFiles();
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
...@@ -404,9 +472,15 @@ STDERR STUFF ...@@ -404,9 +472,15 @@ STDERR STUFF
}); });
testUsingContext('Refuses to build for macOS when feature is disabled', () { testUsingContext('Refuses to build for macOS when feature is disabled', () {
final CommandRunner<void> runner = createTestCommandRunner(BuildCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
));
final bool supported = BuildMacosCommand(verboseHelp: false).supported; final bool supported = BuildMacosCommand(logger: BufferLogger.test(), verboseHelp: false).supported;
expect(() => runner.run(<String>['build', 'macos', '--no-pub']), expect(() => runner.run(<String>['build', 'macos', '--no-pub']),
supported ? throwsToolExit() : throwsA(isA<UsageException>())); supported ? throwsToolExit() : throwsA(isA<UsageException>()));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -414,21 +488,27 @@ STDERR STUFF ...@@ -414,21 +488,27 @@ STDERR STUFF
}); });
testUsingContext('hidden when not enabled on macOS host', () { testUsingContext('hidden when not enabled on macOS host', () {
expect(BuildMacosCommand(verboseHelp: false).hidden, true); expect(BuildMacosCommand(logger: BufferLogger.test(), verboseHelp: false).hidden, true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(), FeatureFlags: () => TestFeatureFlags(),
Platform: () => macosPlatform, Platform: () => macosPlatform,
}); });
testUsingContext('Not hidden when enabled and on macOS host', () { testUsingContext('Not hidden when enabled and on macOS host', () {
expect(BuildMacosCommand(verboseHelp: false).hidden, false); expect(BuildMacosCommand(logger: BufferLogger.test(), verboseHelp: false).hidden, false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true), FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
Platform: () => macosPlatform, Platform: () => macosPlatform,
}); });
testUsingContext('Performs code size analysis and sends analytics', () async { testUsingContext('Performs code size analysis and sends analytics', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles(); createMinimalMockProjectFiles();
fileSystem.file('build/macos/Build/Products/Release/Runner.app/App') fileSystem.file('build/macos/Build/Products/Release/Runner.app/App')
......
...@@ -5,12 +5,16 @@ ...@@ -5,12 +5,16 @@
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build.dart'; import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart'; import 'package:flutter_tools/src/runner/flutter_command.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/test_build_system.dart';
import '../../src/test_flutter_command_runner.dart'; import '../../src/test_flutter_command_runner.dart';
void main() { void main() {
...@@ -36,7 +40,13 @@ void main() { ...@@ -36,7 +40,13 @@ void main() {
}); });
testUsingContext("doesn't fail if --fatal-warnings specified and no warnings occur", () async { testUsingContext("doesn't fail if --fatal-warnings specified and no warnings occur", () async {
command = FakeBuildCommand(); command = FakeBuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
try { try {
await createTestCommandRunner(command).run(<String>[ await createTestCommandRunner(command).run(<String>[
'build', 'build',
...@@ -52,7 +62,13 @@ void main() { ...@@ -52,7 +62,13 @@ void main() {
}); });
testUsingContext("doesn't fail if --fatal-warnings not specified", () async { testUsingContext("doesn't fail if --fatal-warnings not specified", () async {
command = FakeBuildCommand(); command = FakeBuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
testLogger.printWarning('Warning: Mild annoyance Will Robinson!'); testLogger.printWarning('Warning: Mild annoyance Will Robinson!');
try { try {
await createTestCommandRunner(command).run(<String>[ await createTestCommandRunner(command).run(<String>[
...@@ -68,7 +84,13 @@ void main() { ...@@ -68,7 +84,13 @@ void main() {
}); });
testUsingContext('fails if --fatal-warnings specified and warnings emitted', () async { testUsingContext('fails if --fatal-warnings specified and warnings emitted', () async {
command = FakeBuildCommand(); command = FakeBuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
testLogger.printWarning('Warning: Mild annoyance Will Robinson!'); testLogger.printWarning('Warning: Mild annoyance Will Robinson!');
await expectLater(createTestCommandRunner(command).run(<String>[ await expectLater(createTestCommandRunner(command).run(<String>[
'build', 'build',
...@@ -81,7 +103,13 @@ void main() { ...@@ -81,7 +103,13 @@ void main() {
}); });
testUsingContext('fails if --fatal-warnings specified and errors emitted', () async { testUsingContext('fails if --fatal-warnings specified and errors emitted', () async {
command = FakeBuildCommand(); command = FakeBuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
testLogger.printError('Error: Danger Will Robinson!'); testLogger.printError('Error: Danger Will Robinson!');
await expectLater(createTestCommandRunner(command).run(<String>[ await expectLater(createTestCommandRunner(command).run(<String>[
'build', 'build',
...@@ -115,8 +143,15 @@ class FakeBuildInfoCommand extends FlutterCommand { ...@@ -115,8 +143,15 @@ class FakeBuildInfoCommand extends FlutterCommand {
} }
class FakeBuildCommand extends BuildCommand { class FakeBuildCommand extends BuildCommand {
FakeBuildCommand({bool verboseHelp = false}) : super(verboseHelp: verboseHelp) { FakeBuildCommand({
addSubcommand(FakeBuildSubcommand(verboseHelp: verboseHelp)); required super.fileSystem,
required super.buildSystem,
required super.osUtils,
required Logger logger,
required super.androidSdk,
bool verboseHelp = false,
}) : super(logger: logger, verboseHelp: verboseHelp,) {
addSubcommand(FakeBuildSubcommand(logger: logger, verboseHelp: verboseHelp));
} }
@override @override
...@@ -132,7 +167,7 @@ class FakeBuildCommand extends BuildCommand { ...@@ -132,7 +167,7 @@ class FakeBuildCommand extends BuildCommand {
} }
class FakeBuildSubcommand extends BuildSubCommand { class FakeBuildSubcommand extends BuildSubCommand {
FakeBuildSubcommand({required super.verboseHelp}); FakeBuildSubcommand({required super.logger, required super.verboseHelp});
@override @override
String get description => ''; String get description => '';
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/build_system/build_system.dart';
...@@ -45,7 +46,13 @@ void main() { ...@@ -45,7 +46,13 @@ void main() {
testUsingContext('Refuses to build for web when missing index.html', () async { testUsingContext('Refuses to build for web when missing index.html', () async {
fileSystem.file(fileSystem.path.join('web', 'index.html')).deleteSync(); fileSystem.file(fileSystem.path.join('web', 'index.html')).deleteSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
));
expect( expect(
() => runner.run(<String>['build', 'web', '--no-pub']), () => runner.run(<String>['build', 'web', '--no-pub']),
...@@ -59,19 +66,30 @@ void main() { ...@@ -59,19 +66,30 @@ void main() {
}); });
testUsingContext('Refuses to build a debug build for web', () async { testUsingContext('Refuses to build a debug build for web', () async {
final CommandRunner<void> runner = createTestCommandRunner(BuildCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: fileSystem,
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
));
expect(() => runner.run(<String>['build', 'web', '--debug', '--no-pub']), expect(() => runner.run(<String>['build', 'web', '--debug', '--no-pub']),
throwsA(isA<UsageException>())); throwsA(isA<UsageException>()));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => fakePlatform, Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true), FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Refuses to build for web when feature is disabled', () async { testUsingContext('Refuses to build for web when feature is disabled', () async {
final CommandRunner<void> runner = createTestCommandRunner(BuildCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
));
expect( expect(
() => runner.run(<String>['build', 'web', '--no-pub']), () => runner.run(<String>['build', 'web', '--no-pub']),
...@@ -85,7 +103,13 @@ void main() { ...@@ -85,7 +103,13 @@ void main() {
}); });
testUsingContext('Setup for a web build with default output directory', () async { testUsingContext('Setup for a web build with default output directory', () async {
final BuildCommand buildCommand = BuildCommand(); final BuildCommand buildCommand = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: fileSystem,
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
final CommandRunner<void> runner = createTestCommandRunner(buildCommand); final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem); setupFileSystemForEndToEndTest(fileSystem);
await runner.run(<String>['build', 'web', '--no-pub', '--dart-define=foo=a', '--dart2js-optimization=O3']); await runner.run(<String>['build', 'web', '--no-pub', '--dart-define=foo=a', '--dart2js-optimization=O3']);
...@@ -118,7 +142,13 @@ void main() { ...@@ -118,7 +142,13 @@ void main() {
testUsingContext('Setup for a web build with a user specified output directory', testUsingContext('Setup for a web build with a user specified output directory',
() async { () async {
final BuildCommand buildCommand = BuildCommand(); final BuildCommand buildCommand = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: fileSystem,
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
final CommandRunner<void> runner = createTestCommandRunner(buildCommand); final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem); setupFileSystemForEndToEndTest(fileSystem);
...@@ -159,7 +189,7 @@ void main() { ...@@ -159,7 +189,7 @@ void main() {
}); });
testUsingContext('hidden if feature flag is not enabled', () async { testUsingContext('hidden if feature flag is not enabled', () async {
expect(BuildWebCommand(verboseHelp: false).hidden, true); expect(BuildWebCommand(fileSystem: fileSystem, logger: BufferLogger.test(), verboseHelp: false).hidden, true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => fakePlatform, Platform: () => fakePlatform,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -168,7 +198,7 @@ void main() { ...@@ -168,7 +198,7 @@ void main() {
}); });
testUsingContext('not hidden if feature flag is enabled', () async { testUsingContext('not hidden if feature flag is enabled', () async {
expect(BuildWebCommand(verboseHelp: false).hidden, false); expect(BuildWebCommand(fileSystem: fileSystem, logger: BufferLogger.test(), verboseHelp: false).hidden, false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => fakePlatform, Platform: () => fakePlatform,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -177,7 +207,7 @@ void main() { ...@@ -177,7 +207,7 @@ void main() {
}); });
testUsingContext('Defaults to web renderer auto mode when no option is specified', () async { testUsingContext('Defaults to web renderer auto mode when no option is specified', () async {
final TestWebBuildCommand buildCommand = TestWebBuildCommand(); final TestWebBuildCommand buildCommand = TestWebBuildCommand(fileSystem: fileSystem);
final CommandRunner<void> runner = createTestCommandRunner(buildCommand); final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem); setupFileSystemForEndToEndTest(fileSystem);
await runner.run(<String>['build', 'web', '--no-pub']); await runner.run(<String>['build', 'web', '--no-pub']);
...@@ -193,7 +223,7 @@ void main() { ...@@ -193,7 +223,7 @@ void main() {
}); });
testUsingContext('Web build supports build-name and build-number', () async { testUsingContext('Web build supports build-name and build-number', () async {
final TestWebBuildCommand buildCommand = TestWebBuildCommand(); final TestWebBuildCommand buildCommand = TestWebBuildCommand(fileSystem: fileSystem);
final CommandRunner<void> runner = createTestCommandRunner(buildCommand); final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem); setupFileSystemForEndToEndTest(fileSystem);
...@@ -269,8 +299,11 @@ class UrlLauncherPlugin {} ...@@ -269,8 +299,11 @@ class UrlLauncherPlugin {}
} }
class TestWebBuildCommand extends FlutterCommand { class TestWebBuildCommand extends FlutterCommand {
TestWebBuildCommand({ bool verboseHelp = false }) : TestWebBuildCommand({ required FileSystem fileSystem, bool verboseHelp = false }) :
webCommand = BuildWebCommand(verboseHelp: verboseHelp) { webCommand = BuildWebCommand(
fileSystem: fileSystem,
logger: BufferLogger.test(),
verboseHelp: verboseHelp) {
addSubcommand(webCommand); addSubcommand(webCommand);
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart'; import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_windows.dart'; import 'package:flutter_tools/src/commands/build_windows.dart';
...@@ -116,7 +117,7 @@ void main() { ...@@ -116,7 +117,7 @@ void main() {
} }
testUsingContext('Windows build fails when there is no cmake path', () async { testUsingContext('Windows build fails when there is no cmake path', () async {
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = FakeVisualStudio(cmakePath: null); ..visualStudioOverride = FakeVisualStudio(cmakePath: null);
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -132,7 +133,7 @@ void main() { ...@@ -132,7 +133,7 @@ void main() {
testUsingContext('Windows build fails when there is no windows project', () async { testUsingContext('Windows build fails when there is no windows project', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockCoreProjectFiles(); setUpMockCoreProjectFiles();
...@@ -150,7 +151,7 @@ void main() { ...@@ -150,7 +151,7 @@ void main() {
testUsingContext('Windows build fails on non windows platform', () async { testUsingContext('Windows build fails on non windows platform', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -166,7 +167,7 @@ void main() { ...@@ -166,7 +167,7 @@ void main() {
testUsingContext('Windows build fails when feature is disabled', () async { testUsingContext('Windows build fails when feature is disabled', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -182,7 +183,7 @@ void main() { ...@@ -182,7 +183,7 @@ void main() {
testUsingContext('Windows build does not spew stdout to status logger', () async { testUsingContext('Windows build does not spew stdout to status logger', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -207,7 +208,7 @@ void main() { ...@@ -207,7 +208,7 @@ void main() {
testUsingContext('Windows build extracts errors from stdout', () async { testUsingContext('Windows build extracts errors from stdout', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -265,7 +266,7 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier ...@@ -265,7 +266,7 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier
testUsingContext('Windows verbose build sets VERBOSE_SCRIPT_LOGGING', () async { testUsingContext('Windows verbose build sets VERBOSE_SCRIPT_LOGGING', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -291,7 +292,7 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier ...@@ -291,7 +292,7 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier
testUsingContext('Windows build works around CMake generation bug', () async { testUsingContext('Windows build works around CMake generation bug', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(displayVersion: '17.1.0'); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(displayVersion: '17.1.0');
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -427,7 +428,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -427,7 +428,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
testUsingContext('Windows build invokes build and writes generated files', () async { testUsingContext('Windows build invokes build and writes generated files', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -497,7 +498,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -497,7 +498,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
testUsingContext('Windows profile build passes Profile configuration', () async { testUsingContext('Windows profile build passes Profile configuration', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -520,7 +521,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -520,7 +521,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
const String generator = 'A different generator'; const String generator = 'A different generator';
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio( final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(
cmakeGenerator: generator); cmakeGenerator: generator);
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -541,7 +542,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -541,7 +542,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
testUsingContext("Windows build uses pubspec's version", () async { testUsingContext("Windows build uses pubspec's version", () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -587,7 +588,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -587,7 +588,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
testUsingContext('Windows build uses build-name and build-number', () async { testUsingContext('Windows build uses build-name and build-number', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -631,7 +632,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -631,7 +632,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
testUsingContext('Windows build build-name overrides pubspec', () async { testUsingContext('Windows build build-name overrides pubspec', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -678,7 +679,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -678,7 +679,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
testUsingContext('Windows build build-number overrides pubspec', () async { testUsingContext('Windows build build-number overrides pubspec', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -725,7 +726,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -725,7 +726,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
testUsingContext('Windows build build-name and build-number override pubspec', () async { testUsingContext('Windows build build-name and build-number override pubspec', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -773,7 +774,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -773,7 +774,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
testUsingContext('Windows build warns on non-numeric build-number', () async { testUsingContext('Windows build warns on non-numeric build-number', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -823,7 +824,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -823,7 +824,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
testUsingContext('Windows build warns on complex build-number', () async { testUsingContext('Windows build warns on complex build-number', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -872,14 +873,14 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -872,14 +873,14 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
}); });
testUsingContext('hidden when not enabled on Windows host', () { testUsingContext('hidden when not enabled on Windows host', () {
expect(BuildWindowsCommand().hidden, true); expect(BuildWindowsCommand(logger: BufferLogger.test()).hidden, true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(), FeatureFlags: () => TestFeatureFlags(),
Platform: () => windowsPlatform, Platform: () => windowsPlatform,
}); });
testUsingContext('Not hidden when enabled and on Windows host', () { testUsingContext('Not hidden when enabled and on Windows host', () {
expect(BuildWindowsCommand().hidden, false); expect(BuildWindowsCommand(logger: BufferLogger.test()).hidden, false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true), FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
Platform: () => windowsPlatform, Platform: () => windowsPlatform,
...@@ -887,7 +888,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -887,7 +888,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
testUsingContext('Performs code size analysis and sends analytics', () async { testUsingContext('Performs code size analysis and sends analytics', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -939,7 +940,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -939,7 +940,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
// is resolved on the VS side, we can allow these paths again // is resolved on the VS side, we can allow these paths again
testUsingContext('Test bad path characters', () async { testUsingContext('Test bad path characters', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand() final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
fileSystem.currentDirectory = fileSystem.directory("test_'path") fileSystem.currentDirectory = fileSystem.directory("test_'path")
..createSync(); ..createSync();
......
...@@ -7,6 +7,7 @@ import 'package:flutter_tools/src/android/android_builder.dart'; ...@@ -7,6 +7,7 @@ import 'package:flutter_tools/src/android/android_builder.dart';
import 'package:flutter_tools/src/android/android_sdk.dart'; import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/android/android_studio.dart'; import 'package:flutter_tools/src/android/android_studio.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_aar.dart'; import 'package:flutter_tools/src/commands/build_aar.dart';
...@@ -27,7 +28,12 @@ void main() { ...@@ -27,7 +28,12 @@ void main() {
Cache.disableLocking(); Cache.disableLocking();
Future<BuildAarCommand> runCommandIn(String target, { List<String>? arguments }) async { Future<BuildAarCommand> runCommandIn(String target, { List<String>? arguments }) async {
final BuildAarCommand command = BuildAarCommand(verboseHelp: false); final BuildAarCommand command = BuildAarCommand(
androidSdk: FakeAndroidSdk(),
fileSystem: globals.fs,
logger: BufferLogger.test(),
verboseHelp: false,
);
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>[ await runner.run(<String>[
'aar', 'aar',
...@@ -217,6 +223,7 @@ void main() { ...@@ -217,6 +223,7 @@ void main() {
await expectLater(() async { await expectLater(() async {
await runBuildAarCommand( await runBuildAarCommand(
projectPath, projectPath,
null,
arguments: <String>['--no-pub'], arguments: <String>['--no-pub'],
); );
}, throwsToolExit( }, throwsToolExit(
...@@ -224,7 +231,6 @@ void main() { ...@@ -224,7 +231,6 @@ void main() {
)); ));
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
AndroidSdk: () => null,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir), FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
...@@ -235,6 +241,7 @@ void main() { ...@@ -235,6 +241,7 @@ void main() {
await expectLater(() async { await expectLater(() async {
await runBuildAarCommand( await runBuildAarCommand(
'missing_project', 'missing_project',
mockAndroidSdk,
arguments: <String>['--no-pub'], arguments: <String>['--no-pub'],
); );
}, throwsToolExit( }, throwsToolExit(
...@@ -278,7 +285,7 @@ void main() { ...@@ -278,7 +285,7 @@ void main() {
exitCode: 1, exitCode: 1,
)); ));
await expectLater(() => runBuildAarCommand(projectPath, arguments: <String>[ await expectLater(() => runBuildAarCommand(projectPath, mockAndroidSdk, arguments: <String>[
'--no-debug', '--no-debug',
'--no-profile', '--no-profile',
'--extra-front-end-options=foo', '--extra-front-end-options=foo',
...@@ -287,7 +294,6 @@ void main() { ...@@ -287,7 +294,6 @@ void main() {
expect(processManager, hasNoRemainingExpectations); expect(processManager, hasNoRemainingExpectations);
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir), FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => processManager, ProcessManager: () => processManager,
FeatureFlags: () => TestFeatureFlags(isIOSEnabled: false), FeatureFlags: () => TestFeatureFlags(isIOSEnabled: false),
...@@ -297,10 +303,15 @@ void main() { ...@@ -297,10 +303,15 @@ void main() {
} }
Future<BuildAarCommand> runBuildAarCommand( Future<BuildAarCommand> runBuildAarCommand(
String target, { String target, AndroidSdk? androidSdk, {
List<String>? arguments, List<String>? arguments,
}) async { }) async {
final BuildAarCommand command = BuildAarCommand(verboseHelp: false); final BuildAarCommand command = BuildAarCommand(
androidSdk: androidSdk,
fileSystem: globals.fs,
logger: BufferLogger.test(),
verboseHelp: false,
);
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>[ await runner.run(<String>[
'aar', 'aar',
......
...@@ -7,6 +7,7 @@ import 'package:flutter_tools/src/android/android_builder.dart'; ...@@ -7,6 +7,7 @@ import 'package:flutter_tools/src/android/android_builder.dart';
import 'package:flutter_tools/src/android/android_sdk.dart'; import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/android/android_studio.dart'; import 'package:flutter_tools/src/android/android_studio.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_apk.dart'; import 'package:flutter_tools/src/commands/build_apk.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
...@@ -429,7 +430,7 @@ Future<BuildApkCommand> runBuildApkCommand( ...@@ -429,7 +430,7 @@ Future<BuildApkCommand> runBuildApkCommand(
String target, { String target, {
List<String>? arguments, List<String>? arguments,
}) async { }) async {
final BuildApkCommand command = BuildApkCommand(); final BuildApkCommand command = BuildApkCommand(logger: BufferLogger.test());
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>[ await runner.run(<String>[
'apk', 'apk',
......
...@@ -6,6 +6,7 @@ import 'package:args/command_runner.dart'; ...@@ -6,6 +6,7 @@ import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/android/android_builder.dart'; import 'package:flutter_tools/src/android/android_builder.dart';
import 'package:flutter_tools/src/android/android_sdk.dart'; import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_appbundle.dart'; import 'package:flutter_tools/src/commands/build_appbundle.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
...@@ -213,7 +214,7 @@ Future<BuildAppBundleCommand> runBuildAppBundleCommand( ...@@ -213,7 +214,7 @@ Future<BuildAppBundleCommand> runBuildAppBundleCommand(
String target, { String target, {
List<String>? arguments, List<String>? arguments,
}) async { }) async {
final BuildAppBundleCommand command = BuildAppBundleCommand(); final BuildAppBundleCommand command = BuildAppBundleCommand(logger: BufferLogger.test());
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>[ await runner.run(<String>[
'appbundle', 'appbundle',
......
...@@ -6,6 +6,7 @@ import 'package:args/command_runner.dart'; ...@@ -6,6 +6,7 @@ import 'package:args/command_runner.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/bundle.dart'; import 'package:flutter_tools/src/bundle.dart';
...@@ -46,7 +47,10 @@ void main() { ...@@ -46,7 +47,10 @@ void main() {
} }
Future<BuildBundleCommand> runCommandIn(String projectPath, { List<String>? arguments }) async { Future<BuildBundleCommand> runCommandIn(String projectPath, { List<String>? arguments }) async {
final BuildBundleCommand command = BuildBundleCommand(bundleBuilder: fakeBundleBuilder); final BuildBundleCommand command = BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
);
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -88,7 +92,10 @@ void main() { ...@@ -88,7 +92,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(recursive: true); globals.fs.file('pubspec.yaml').createSync(recursive: true);
globals.fs.file('.packages').createSync(recursive: true); globals.fs.file('.packages').createSync(recursive: true);
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder())); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
expect(() => runner.run(<String>[ expect(() => runner.run(<String>[
'bundle', 'bundle',
...@@ -105,7 +112,10 @@ void main() { ...@@ -105,7 +112,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder())); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
expect(() => runner.run(<String>[ expect(() => runner.run(<String>[
'bundle', 'bundle',
...@@ -122,7 +132,10 @@ void main() { ...@@ -122,7 +132,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder())); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
expect(() => runner.run(<String>[ expect(() => runner.run(<String>[
'bundle', 'bundle',
...@@ -139,7 +152,10 @@ void main() { ...@@ -139,7 +152,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder())); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
expect(() => runner.run(<String>[ expect(() => runner.run(<String>[
'bundle', 'bundle',
...@@ -156,7 +172,10 @@ void main() { ...@@ -156,7 +172,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder())); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -173,7 +192,10 @@ void main() { ...@@ -173,7 +192,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder())); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -190,7 +212,10 @@ void main() { ...@@ -190,7 +212,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder())); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -207,7 +232,10 @@ void main() { ...@@ -207,7 +232,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -237,7 +265,10 @@ void main() { ...@@ -237,7 +265,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -268,7 +299,10 @@ void main() { ...@@ -268,7 +299,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -298,7 +332,10 @@ void main() { ...@@ -298,7 +332,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -329,7 +366,10 @@ void main() { ...@@ -329,7 +366,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -360,7 +400,10 @@ void main() { ...@@ -360,7 +400,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -391,7 +434,10 @@ void main() { ...@@ -391,7 +434,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -430,7 +476,10 @@ void main() { ...@@ -430,7 +476,10 @@ void main() {
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -479,7 +528,10 @@ void main() { ...@@ -479,7 +528,10 @@ void main() {
} }
''' '''
); );
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -509,7 +561,10 @@ void main() { ...@@ -509,7 +561,10 @@ void main() {
} }
''' '''
); );
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()); final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
logger: BufferLogger.test(),
bundleBuilder: fakeBundleBuilder,
));
expect(() => runner.run(<String>[ expect(() => runner.run(<String>[
'bundle', 'bundle',
......
...@@ -9,8 +9,10 @@ import 'package:flutter_tools/src/android/android_workflow.dart'; ...@@ -9,8 +9,10 @@ import 'package:flutter_tools/src/android/android_workflow.dart';
import 'package:flutter_tools/src/base/config.dart'; import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/time.dart'; import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build.dart'; import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/commands/config.dart'; import 'package:flutter_tools/src/commands/config.dart';
...@@ -28,6 +30,7 @@ import 'package:usage/usage_io.dart'; ...@@ -28,6 +30,7 @@ import 'package:usage/usage_io.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
import '../src/fakes.dart'; import '../src/fakes.dart';
import '../src/test_build_system.dart';
import '../src/test_flutter_command_runner.dart'; import '../src/test_flutter_command_runner.dart';
void main() { void main() {
...@@ -213,7 +216,13 @@ void main() { ...@@ -213,7 +216,13 @@ void main() {
}); });
testUsingContext('compound command usage path', () async { testUsingContext('compound command usage path', () async {
final BuildCommand buildCommand = BuildCommand(); final BuildCommand buildCommand = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
final FlutterCommand buildApkCommand = buildCommand.subcommands['apk']! as FlutterCommand; final FlutterCommand buildApkCommand = buildCommand.subcommands['apk']! as FlutterCommand;
expect(await buildApkCommand.usagePath, 'build/apk'); expect(await buildApkCommand.usagePath, 'build/apk');
......
...@@ -31,6 +31,7 @@ import 'package:test/fake.dart'; ...@@ -31,6 +31,7 @@ import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/fakes.dart'; import '../../src/fakes.dart';
import '../../src/test_build_system.dart';
class FakeTerminal extends Fake implements AnsiTerminal { class FakeTerminal extends Fake implements AnsiTerminal {
FakeTerminal({this.stdinHasTerminal = true}); FakeTerminal({this.stdinHasTerminal = true});
...@@ -50,16 +51,22 @@ void main() { ...@@ -50,16 +51,22 @@ void main() {
final Platform platform = FakePlatform(); final Platform platform = FakePlatform();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final List<FlutterCommand> commands = <FlutterCommand>[ final List<FlutterCommand> commands = <FlutterCommand>[
BuildWindowsCommand(), BuildWindowsCommand(logger: BufferLogger.test()),
BuildLinuxCommand(operatingSystemUtils: FakeOperatingSystemUtils()), BuildLinuxCommand(logger: BufferLogger.test(), operatingSystemUtils: FakeOperatingSystemUtils()),
BuildMacosCommand(verboseHelp: false), BuildMacosCommand(logger: BufferLogger.test(), verboseHelp: false),
BuildWebCommand(verboseHelp: false), BuildWebCommand(fileSystem: fileSystem, logger: BufferLogger.test(), verboseHelp: false),
BuildApkCommand(), BuildApkCommand(logger: BufferLogger.test()),
BuildIOSCommand(verboseHelp: false), BuildIOSCommand(logger: BufferLogger.test(), verboseHelp: false),
BuildIOSArchiveCommand(verboseHelp: false), BuildIOSArchiveCommand(logger: BufferLogger.test(), verboseHelp: false),
BuildAppBundleCommand(), BuildAppBundleCommand(logger: BufferLogger.test()),
BuildAarCommand(verboseHelp: false), BuildAarCommand(
logger: BufferLogger.test(),
androidSdk: FakeAndroidSdk(),
fileSystem: fileSystem,
verboseHelp: false,
),
BuildIOSFrameworkCommand( BuildIOSFrameworkCommand(
logger: BufferLogger.test(),
verboseHelp: false, verboseHelp: false,
buildSystem: FlutterBuildSystem( buildSystem: FlutterBuildSystem(
fileSystem: fileSystem, fileSystem: fileSystem,
...@@ -104,18 +111,25 @@ void main() { ...@@ -104,18 +111,25 @@ void main() {
treeShakeIcons: false, treeShakeIcons: false,
); );
FakeBuildSubCommand().test(unsound); final BufferLogger logger = BufferLogger.test();
expect(testLogger.statusText, FakeBuildSubCommand(logger).test(unsound);
expect(logger.statusText,
contains('Building without sound null safety ⚠️')); contains('Building without sound null safety ⚠️'));
testLogger.clear(); logger.clear();
FakeBuildSubCommand().test(sound); FakeBuildSubCommand(logger).test(sound);
expect(testLogger.statusText, expect(logger.statusText,
contains('💪 Building with sound null safety 💪')); contains('💪 Building with sound null safety 💪'));
}); });
testUsingContext('Include only supported sub commands', () { testUsingContext('Include only supported sub commands', () {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
for (final Command<void> x in command.subcommands.values) { for (final Command<void> x in command.subcommands.values) {
expect((x as BuildSubCommand).supported, isTrue); expect((x as BuildSubCommand).supported, isTrue);
} }
...@@ -123,7 +137,7 @@ void main() { ...@@ -123,7 +137,7 @@ void main() {
} }
class FakeBuildSubCommand extends BuildSubCommand { class FakeBuildSubCommand extends BuildSubCommand {
FakeBuildSubCommand() : super(verboseHelp: false); FakeBuildSubCommand(Logger logger) : super(logger: logger, verboseHelp: false);
@override @override
String get description => throw UnimplementedError(); String get description => throw UnimplementedError();
......
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build.dart'; import 'package:flutter_tools/src/commands/build.dart';
import '../../../src/context.dart'; // legacy import '../../../src/context.dart'; // legacy
import '../../../src/fakes.dart';
import '../../../src/test_build_system.dart'; import '../../../src/test_build_system.dart';
import '../../../src/test_flutter_command_runner.dart'; // legacy import '../../../src/test_flutter_command_runner.dart'; // legacy
...@@ -44,7 +46,13 @@ void main() { ...@@ -44,7 +46,13 @@ void main() {
expect(gitignore.existsSync(), isFalse); expect(gitignore.existsSync(), isFalse);
expect(registrant.existsSync(), isFalse); expect(registrant.existsSync(), isFalse);
await createTestCommandRunner(BuildCommand()) await createTestCommandRunner(BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: buildSystem,
fileSystem: fileSystem,
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
))
.run(<String>['build', 'web', '--no-pub']); .run(<String>['build', 'web', '--no-pub']);
final Directory buildDir = fileSystem.directory(fileSystem.path.join('build', 'web')); final Directory buildDir = fileSystem.directory(fileSystem.path.join('build', 'web'));
...@@ -61,7 +69,13 @@ void main() { ...@@ -61,7 +69,13 @@ void main() {
final String contentsBeforeBuild = gitignore.readAsStringSync(); final String contentsBeforeBuild = gitignore.readAsStringSync();
expect(contentsBeforeBuild, isNot(contains('lib/generated_plugin_registrant.dart'))); expect(contentsBeforeBuild, isNot(contains('lib/generated_plugin_registrant.dart')));
await createTestCommandRunner(BuildCommand()) await createTestCommandRunner(BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: buildSystem,
fileSystem: fileSystem,
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
))
.run(<String>['build', 'web', '--no-pub']); .run(<String>['build', 'web', '--no-pub']);
expect(gitignore.readAsStringSync(), contentsBeforeBuild); expect(gitignore.readAsStringSync(), contentsBeforeBuild);
...@@ -77,7 +91,13 @@ void main() { ...@@ -77,7 +91,13 @@ void main() {
expect(gitignore.existsSync(), isTrue); expect(gitignore.existsSync(), isTrue);
expect(gitignore.readAsStringSync(), contains('lib/generated_plugin_registrant.dart')); expect(gitignore.readAsStringSync(), contains('lib/generated_plugin_registrant.dart'));
await createTestCommandRunner(BuildCommand()) await createTestCommandRunner(BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: buildSystem,
fileSystem: fileSystem,
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
))
.run(<String>['build', 'web', '--no-pub']); .run(<String>['build', 'web', '--no-pub']);
expect(gitignore.readAsStringSync(), isNot(contains('lib/generated_plugin_registrant.dart'))); expect(gitignore.readAsStringSync(), isNot(contains('lib/generated_plugin_registrant.dart')));
...@@ -92,7 +112,13 @@ void main() { ...@@ -92,7 +112,13 @@ void main() {
expect(registrant.existsSync(), isTrue); expect(registrant.existsSync(), isTrue);
await createTestCommandRunner(BuildCommand()) await createTestCommandRunner(BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: buildSystem,
fileSystem: fileSystem,
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
))
.run(<String>['build', 'web', '--no-pub']); .run(<String>['build', 'web', '--no-pub']);
expect(registrant.existsSync(), isFalse); expect(registrant.existsSync(), isFalse);
...@@ -109,7 +135,13 @@ void main() { ...@@ -109,7 +135,13 @@ void main() {
expect(registrant.existsSync(), isTrue); expect(registrant.existsSync(), isTrue);
expect(gitignore.readAsStringSync(), contains('lib/generated_plugin_registrant.dart')); expect(gitignore.readAsStringSync(), contains('lib/generated_plugin_registrant.dart'));
await createTestCommandRunner(BuildCommand()) await createTestCommandRunner(BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: buildSystem,
fileSystem: fileSystem,
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
))
.run(<String>['build', 'web', '--no-pub']); .run(<String>['build', 'web', '--no-pub']);
expect(registrant.existsSync(), isFalse); expect(registrant.existsSync(), isFalse);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:io' as io show IOSink, ProcessSignal, Stdout, StdoutException; import 'dart:io' as io show IOSink, ProcessSignal, Stdout, StdoutException;
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/base/bot_detector.dart'; import 'package:flutter_tools/src/base/bot_detector.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
...@@ -572,3 +573,14 @@ class FakeFlutterProjectFactory implements FlutterProjectFactory { ...@@ -572,3 +573,14 @@ class FakeFlutterProjectFactory implements FlutterProjectFactory {
@override @override
Map<String, FlutterProject> get projects => throw UnimplementedError(); Map<String, FlutterProject> get projects => throw UnimplementedError();
} }
class FakeAndroidSdk extends Fake implements AndroidSdk {
@override
late bool platformToolsAvailable;
@override
late bool licensesAvailable;
@override
AndroidSdkVersion? latestVersion;
}
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