Unverified Commit 8c8bb222 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

BufferLogger should log stacktrace (#113240)

parent e1f3cff2
......@@ -790,8 +790,14 @@ class BufferLogger extends Logger {
bool? wrap,
}) {
hadErrorOutput = true;
final StringBuffer errorMessage = StringBuffer();
errorMessage.write(message);
if (stackTrace != null) {
errorMessage.writeln();
errorMessage.write(stackTrace);
}
_error.writeln(terminal.color(
wrapText(message,
wrapText(errorMessage.toString(),
indent: indent,
hangingIndent: hangingIndent,
shouldWrap: wrap ?? _outputPreferences.wrapText,
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'package:fake_async/fake_async.dart';
import 'package:flutter_tools/executable.dart';
......@@ -246,12 +247,15 @@ void main() {
verboseLogger.printStatus('Hey Hey Hey Hey');
verboseLogger.printTrace('Oooh, I do I do I do');
verboseLogger.printError('Helpless!');
final StackTrace stackTrace = StackTrace.current;
verboseLogger.printError('Helpless!', stackTrace: stackTrace);
expect(mockLogger.statusText, matches(r'^\[ (?: {0,2}\+[0-9]{1,4} ms| )\] Hey Hey Hey Hey\n'
r'\[ (?: {0,2}\+[0-9]{1,4} ms| )\] Oooh, I do I do I do\n$'));
expect(mockLogger.traceText, '');
expect(mockLogger.errorText, matches( r'^\[ (?: {0,2}\+[0-9]{1,4} ms| )\] Helpless!\n$'));
expect(mockLogger.errorText, matches( r'^\[ (?: {0,2}\+[0-9]{1,4} ms| )\] Helpless!\n'));
final String lastLine = LineSplitter.split(stackTrace.toString()).toList().last;
expect(mockLogger.errorText, endsWith('$lastLine\n\n'));
});
testWithoutContext('ANSI colored errors', () async {
......@@ -1239,6 +1243,21 @@ void main() {
expect(logger.statusText, 'AAA\nBBB\n');
});
testWithoutContext('BufferLogger prints status, trace, error', () async {
final BufferLogger mockLogger = BufferLogger.test(
outputPreferences: OutputPreferences.test(),
);
mockLogger.printStatus('Hey Hey Hey Hey');
mockLogger.printTrace('Oooh, I do I do I do');
final StackTrace stackTrace = StackTrace.current;
mockLogger.printError('Helpless!', stackTrace: stackTrace);
expect(mockLogger.statusText, 'Hey Hey Hey Hey\n');
expect(mockLogger.traceText, 'Oooh, I do I do I do\n');
expect(mockLogger.errorText, 'Helpless!\n$stackTrace\n');
});
});
}
......
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