Unverified Commit 417449e2 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Deflake flutter tool logger test (#43800)

parent e0094eee
...@@ -359,12 +359,12 @@ class BufferLogger extends Logger { ...@@ -359,12 +359,12 @@ class BufferLogger extends Logger {
class VerboseLogger extends Logger { class VerboseLogger extends Logger {
VerboseLogger(this.parent) : assert(terminal != null) { VerboseLogger(this.parent) : assert(terminal != null) {
stopwatch.start(); _stopwatch.start();
} }
final Logger parent; final Logger parent;
Stopwatch stopwatch = Stopwatch(); final Stopwatch _stopwatch = context.get<Stopwatch>() ?? Stopwatch();
@override @override
bool get isVerbose => true; bool get isVerbose => true;
...@@ -438,8 +438,8 @@ class VerboseLogger extends Logger { ...@@ -438,8 +438,8 @@ class VerboseLogger extends Logger {
return; return;
} }
final int millis = stopwatch.elapsedMilliseconds; final int millis = _stopwatch.elapsedMilliseconds;
stopwatch.reset(); _stopwatch.reset();
String prefix; String prefix;
const int prefixWidth = 8; const int prefixWidth = 8;
......
...@@ -24,6 +24,11 @@ void main() { ...@@ -24,6 +24,11 @@ void main() {
final String resetColor = RegExp.escape(AnsiTerminal.resetColor); final String resetColor = RegExp.escape(AnsiTerminal.resetColor);
group('AppContext', () { group('AppContext', () {
FakeStopwatch fakeStopWatch;
setUp(() {
fakeStopWatch = FakeStopwatch();
});
testUsingContext('error', () async { testUsingContext('error', () async {
final BufferLogger mockLogger = BufferLogger(); final BufferLogger mockLogger = BufferLogger();
final VerboseLogger verboseLogger = VerboseLogger(mockLogger); final VerboseLogger verboseLogger = VerboseLogger(mockLogger);
...@@ -39,6 +44,7 @@ void main() { ...@@ -39,6 +44,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(showColor: false), OutputPreferences: () => OutputPreferences(showColor: false),
Platform: _kNoAnsiPlatform, Platform: _kNoAnsiPlatform,
Stopwatch: () => fakeStopWatch,
}); });
testUsingContext('ANSI colored errors', () async { testUsingContext('ANSI colored errors', () async {
...@@ -60,6 +66,7 @@ void main() { ...@@ -60,6 +66,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(showColor: true), OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () => FakePlatform()..stdoutSupportsAnsi = true, Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
Stopwatch: () => fakeStopWatch,
}); });
}); });
......
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