Commit 3146e134 authored by Yegor's avatar Yegor Committed by GitHub

print less in flutter_tool tests (fixes #8641) (#8699)

parent d09591bf
...@@ -149,6 +149,16 @@ Future<int> run(List<String> args, List<FlutterCommand> subCommands, { ...@@ -149,6 +149,16 @@ Future<int> run(List<String> args, List<FlutterCommand> subCommands, {
}); });
} }
/// Writes the [string] to one of the standard output streams.
@visibleForTesting
typedef void WriteCallback([String string]);
/// Writes a line to STDERR.
///
/// Overwrite this in tests to avoid spurious test output.
@visibleForTesting
WriteCallback writelnStderr = stderr.writeln;
Future<int> _handleToolError( Future<int> _handleToolError(
dynamic error, dynamic error,
Chain chain, Chain chain,
...@@ -158,9 +168,9 @@ Future<int> _handleToolError( ...@@ -158,9 +168,9 @@ Future<int> _handleToolError(
String getFlutterVersion(), String getFlutterVersion(),
) async { ) async {
if (error is UsageException) { if (error is UsageException) {
stderr.writeln(error.message); writelnStderr(error.message);
stderr.writeln(); writelnStderr();
stderr.writeln( writelnStderr(
"Run 'flutter -h' (or 'flutter <command> -h') for available " "Run 'flutter -h' (or 'flutter <command> -h') for available "
"flutter commands and options." "flutter commands and options."
); );
...@@ -168,11 +178,11 @@ Future<int> _handleToolError( ...@@ -168,11 +178,11 @@ Future<int> _handleToolError(
return _exit(64); return _exit(64);
} else if (error is ToolExit) { } else if (error is ToolExit) {
if (error.message != null) if (error.message != null)
stderr.writeln(error.message); writelnStderr(error.message);
if (verbose) { if (verbose) {
stderr.writeln(); writelnStderr();
stderr.writeln(chain.terse.toString()); writelnStderr(chain.terse.toString());
stderr.writeln(); writelnStderr();
} }
return _exit(error.exitCode ?? 1); return _exit(error.exitCode ?? 1);
} else if (error is ProcessExit) { } else if (error is ProcessExit) {
...@@ -185,20 +195,20 @@ Future<int> _handleToolError( ...@@ -185,20 +195,20 @@ Future<int> _handleToolError(
} }
} else { } else {
// We've crashed; emit a log report. // We've crashed; emit a log report.
stderr.writeln(); writelnStderr();
if (!reportCrashes) { if (!reportCrashes) {
// Print the stack trace on the bots - don't write a crash report. // Print the stack trace on the bots - don't write a crash report.
stderr.writeln('$error'); writelnStderr('$error');
stderr.writeln(chain.terse.toString()); writelnStderr(chain.terse.toString());
return _exit(1); return _exit(1);
} else { } else {
flutterUsage.sendException(error, chain); flutterUsage.sendException(error, chain);
if (error is String) if (error is String)
stderr.writeln('Oops; flutter has exited unexpectedly: "$error".'); writelnStderr('Oops; flutter has exited unexpectedly: "$error".');
else else
stderr.writeln('Oops; flutter has exited unexpectedly.'); writelnStderr('Oops; flutter has exited unexpectedly.');
await CrashReportSender.instance.sendReport( await CrashReportSender.instance.sendReport(
error: error, error: error,
...@@ -207,13 +217,13 @@ Future<int> _handleToolError( ...@@ -207,13 +217,13 @@ Future<int> _handleToolError(
); );
try { try {
final File file = await _createLocalCrashReport(args, error, chain); final File file = await _createLocalCrashReport(args, error, chain);
stderr.writeln( writelnStderr(
'Crash report written to ${file.path};\n' 'Crash report written to ${file.path};\n'
'please let us know at https://github.com/flutter/flutter/issues.', 'please let us know at https://github.com/flutter/flutter/issues.',
); );
return _exit(1); return _exit(1);
} catch (error) { } catch (error) {
stderr.writeln( writelnStderr(
'Unable to generate crash report due to secondary error: $error\n' 'Unable to generate crash report due to secondary error: $error\n'
'please let us know at https://github.com/flutter/flutter/issues.', 'please let us know at https://github.com/flutter/flutter/issues.',
); );
......
...@@ -23,12 +23,14 @@ void main() { ...@@ -23,12 +23,14 @@ void main() {
group('crash reporting', () { group('crash reporting', () {
setUp(() async { setUp(() async {
tools.crashFileSystem = new MemoryFileSystem(); tools.crashFileSystem = new MemoryFileSystem();
tools.writelnStderr = ([_]) { };
setExitFunctionForTests((_) { }); setExitFunctionForTests((_) { });
enterTestingMode(); enterTestingMode();
}); });
tearDown(() { tearDown(() {
tools.crashFileSystem = const LocalFileSystem(); tools.crashFileSystem = const LocalFileSystem();
tools.writelnStderr = stderr.writeln;
restoreExitFunction(); restoreExitFunction();
exitTestingMode(); exitTestingMode();
}); });
......
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