From 6eaaf1650e671f9bbc6f34fba003cc5729f365b2 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 9 Jul 2020 18:04:37 -0700 Subject: [PATCH] [flutter_tools] switch order of injection (#61191) Inject loggers in the right order, test WIP. Otherwise verbose machine would not get the AppRunLogger --- packages/flutter_tools/lib/executable.dart | 21 ++++++---- .../command_output_test.dart | 39 ++++++++++++++----- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/packages/flutter_tools/lib/executable.dart b/packages/flutter_tools/lib/executable.dart index c58ca5bbd4..b0eb4adb37 100644 --- a/packages/flutter_tools/lib/executable.dart +++ b/packages/flutter_tools/lib/executable.dart @@ -145,6 +145,20 @@ Future main(List args) async { outputPreferences: globals.outputPreferences, ), )) + else if (runMachine && !verbose) + Logger: () => AppRunLogger(parent: StdoutLogger( + timeoutConfiguration: timeoutConfiguration, + stdio: globals.stdio, + terminal: globals.terminal, + outputPreferences: globals.outputPreferences, + )) + else if (runMachine && verbose) + Logger: () => AppRunLogger(parent: VerboseLogger(StdoutLogger( + timeoutConfiguration: timeoutConfiguration, + stdio: globals.stdio, + terminal: globals.terminal, + outputPreferences: globals.outputPreferences, + ))) else if (verbose && !muteCommandLogging) Logger: () => VerboseLogger(StdoutLogger( timeoutConfiguration: timeoutConfiguration, @@ -152,12 +166,5 @@ Future main(List args) async { terminal: globals.terminal, outputPreferences: globals.outputPreferences, )) - else if (runMachine) - Logger: () => AppRunLogger(parent: StdoutLogger( - timeoutConfiguration: timeoutConfiguration, - stdio: globals.stdio, - terminal: globals.terminal, - outputPreferences: globals.outputPreferences, - )) }); } diff --git a/packages/flutter_tools/test/integration.shard/command_output_test.dart b/packages/flutter_tools/test/integration.shard/command_output_test.dart index f93e91de0b..0b79d94630 100644 --- a/packages/flutter_tools/test/integration.shard/command_output_test.dart +++ b/packages/flutter_tools/test/integration.shard/command_output_test.dart @@ -2,11 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/globals.dart' as globals; import 'package:process/process.dart'; import '../src/common.dart'; +import 'test_utils.dart'; void main() { test('All development tools and deprecated commands are hidden and help text is not verbose', () async { @@ -54,15 +56,34 @@ void main() { }); test('flutter run --machine uses AppRunLogger', () async { - final String flutterBin = globals.fs.path.join(getFlutterRoot(), 'bin', 'flutter'); - final ProcessResult result = await const LocalProcessManager().run([ - flutterBin, - 'run', - '--machine', - '-v', - ]); + final Directory directory = createResolvedTempDirectorySync('flutter_run_test.') + .createTempSync('_flutter_run_test.') + ..createSync(recursive: true); - expect(result.stdout, isNotEmpty); + try { + directory + .childFile('pubspec.yaml') + .writeAsStringSync('name: foo'); + directory + .childFile('.packages') + .writeAsStringSync('\n'); + directory + .childDirectory('lib') + .childFile('main.dart') + .createSync(recursive: true); + final String flutterBin = globals.fs.path.join(getFlutterRoot(), 'bin', 'flutter'); + final ProcessResult result = await const LocalProcessManager().run([ + flutterBin, + 'run', + '--show-test-device', // ensure command can fail to run and hit injection of correct logger. + '--machine', + '-v', + '--no-resident', + ], workingDirectory: directory.path); + expect(result.stderr, isNot(contains('Oops; flutter has exited unexpectedly:'))); + } finally { + directory.deleteSync(recursive: true); + } }); test('flutter attach --machine uses AppRunLogger', () async { @@ -74,7 +95,7 @@ void main() { '-v', ]); - expect(result.stdout, isNotEmpty); + expect(result.stderr, contains('Target file')); // Target file not found, but different paths on Windows and Linux/macOS. }); test('flutter build aot is deprecated', () async {