Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
fc35508a
Unverified
Commit
fc35508a
authored
Mar 02, 2021
by
Jonah Williams
Committed by
GitHub
Mar 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove mock from logger tests (#77064)
parent
8050bd61
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
71 deletions
+41
-71
logger_test.dart
...es/flutter_tools/test/general.shard/base/logger_test.dart
+41
-71
No files found.
packages/flutter_tools/test/general.shard/base/logger_test.dart
View file @
fc35508a
...
...
@@ -13,8 +13,9 @@ import 'package:flutter_tools/src/base/platform.dart';
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:flutter_tools/src/commands/daemon.dart'
;
import
'package:matcher/matcher.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:fake_async/fake_async.dart'
;
import
'package:meta/meta.dart'
;
import
'package:test/fake.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
...
...
@@ -26,8 +27,6 @@ final String bold = RegExp.escape(AnsiTerminal.bold);
final
String
resetBold
=
RegExp
.
escape
(
AnsiTerminal
.
resetBold
);
final
String
resetColor
=
RegExp
.
escape
(
AnsiTerminal
.
resetColor
);
class
MockStdout
extends
Mock
implements
Stdout
{}
void
main
(
)
{
testWithoutContext
(
'correct logger instance is created'
,
()
{
final
LoggerFactory
loggerFactory
=
LoggerFactory
(
...
...
@@ -291,23 +290,9 @@ void main() {
});
testWithoutContext
(
'Logger does not throw when stdio write throws synchronously'
,
()
async
{
final
MockStdout
stdout
=
MockStdout
(
);
final
MockStdout
stderr
=
MockStdout
(
);
final
FakeStdout
stdout
=
FakeStdout
(
syncError:
true
);
final
FakeStdout
stderr
=
FakeStdout
(
syncError:
true
);
final
Stdio
stdio
=
Stdio
.
test
(
stdout:
stdout
,
stderr:
stderr
);
bool
stdoutThrew
=
false
;
bool
stderrThrew
=
false
;
final
Completer
<
void
>
stdoutError
=
Completer
<
void
>();
final
Completer
<
void
>
stderrError
=
Completer
<
void
>();
when
(
stdout
.
write
(
any
)).
thenAnswer
((
_
)
{
stdoutThrew
=
true
;
throw
'Error'
;
});
when
(
stderr
.
write
(
any
)).
thenAnswer
((
_
)
{
stderrThrew
=
true
;
throw
'Error'
;
});
when
(
stdout
.
done
).
thenAnswer
((
_
)
=>
stdoutError
.
future
);
when
(
stderr
.
done
).
thenAnswer
((
_
)
=>
stderrError
.
future
);
final
Logger
logger
=
StdoutLogger
(
terminal:
AnsiTerminal
(
stdio:
stdio
,
...
...
@@ -316,38 +301,15 @@ void main() {
stdio:
stdio
,
outputPreferences:
OutputPreferences
.
test
(),
);
logger
.
printStatus
(
'message'
);
logger
.
printError
(
'error message'
);
expect
(
stdoutThrew
,
true
);
expect
(
stderrThrew
,
true
);
});
testWithoutContext
(
'Logger does not throw when stdio write throws asynchronously'
,
()
async
{
final
MockStdout
stdout
=
MockStdout
(
);
final
MockStdout
stderr
=
MockStdout
(
);
final
FakeStdout
stdout
=
FakeStdout
(
syncError:
false
);
final
FakeStdout
stderr
=
FakeStdout
(
syncError:
false
);
final
Stdio
stdio
=
Stdio
.
test
(
stdout:
stdout
,
stderr:
stderr
);
final
Completer
<
void
>
stdoutError
=
Completer
<
void
>();
final
Completer
<
void
>
stderrError
=
Completer
<
void
>();
bool
stdoutThrew
=
false
;
bool
stderrThrew
=
false
;
final
Completer
<
void
>
stdoutCompleter
=
Completer
<
void
>();
final
Completer
<
void
>
stderrCompleter
=
Completer
<
void
>();
when
(
stdout
.
write
(
any
)).
thenAnswer
((
_
)
{
Zone
.
current
.
runUnaryGuarded
<
void
>((
_
)
{
stdoutThrew
=
true
;
stdoutCompleter
.
complete
();
throw
'Error'
;
},
null
);
});
when
(
stderr
.
write
(
any
)).
thenAnswer
((
_
)
{
Zone
.
current
.
runUnaryGuarded
<
void
>((
_
)
{
stderrThrew
=
true
;
stderrCompleter
.
complete
();
throw
'Error'
;
},
null
);
});
when
(
stdout
.
done
).
thenAnswer
((
_
)
=>
stdoutError
.
future
);
when
(
stderr
.
done
).
thenAnswer
((
_
)
=>
stderrError
.
future
);
final
Logger
logger
=
StdoutLogger
(
terminal:
AnsiTerminal
(
stdio:
stdio
,
...
...
@@ -358,34 +320,15 @@ void main() {
);
logger
.
printStatus
(
'message'
);
logger
.
printError
(
'error message'
);
await
stdoutCompleter
.
future
;
await
stderrCompleter
.
future
;
expect
(
stdoutThrew
,
true
);
expect
(
stderrThrew
,
true
);
await
stdout
.
done
;
await
stderr
.
done
;
});
testWithoutContext
(
'Logger does not throw when stdio completes done with an error'
,
()
async
{
final
MockStdout
stdout
=
MockStdout
(
);
final
MockStdout
stderr
=
MockStdout
(
);
final
FakeStdout
stdout
=
FakeStdout
(
syncError:
false
,
completeWithError:
true
);
final
FakeStdout
stderr
=
FakeStdout
(
syncError:
false
,
completeWithError:
true
);
final
Stdio
stdio
=
Stdio
.
test
(
stdout:
stdout
,
stderr:
stderr
);
final
Completer
<
void
>
stdoutError
=
Completer
<
void
>();
final
Completer
<
void
>
stderrError
=
Completer
<
void
>();
final
Completer
<
void
>
stdoutCompleter
=
Completer
<
void
>();
final
Completer
<
void
>
stderrCompleter
=
Completer
<
void
>();
when
(
stdout
.
write
(
any
)).
thenAnswer
((
_
)
{
Zone
.
current
.
runUnaryGuarded
<
void
>((
_
)
{
stdoutError
.
completeError
(
Exception
(
'Some pipe error'
));
stdoutCompleter
.
complete
();
},
null
);
});
when
(
stderr
.
write
(
any
)).
thenAnswer
((
_
)
{
Zone
.
current
.
runUnaryGuarded
<
void
>((
_
)
{
stderrError
.
completeError
(
Exception
(
'Some pipe error'
));
stderrCompleter
.
complete
();
},
null
);
});
when
(
stdout
.
done
).
thenAnswer
((
_
)
=>
stdoutError
.
future
);
when
(
stderr
.
done
).
thenAnswer
((
_
)
=>
stderrError
.
future
);
final
Logger
logger
=
StdoutLogger
(
terminal:
AnsiTerminal
(
stdio:
stdio
,
...
...
@@ -396,8 +339,9 @@ void main() {
);
logger
.
printStatus
(
'message'
);
logger
.
printError
(
'error message'
);
await
stdoutCompleter
.
future
;
await
stderrCompleter
.
future
;
expect
(()
async
=>
await
stdout
.
done
,
throwsA
(
isA
<
Exception
>()));
expect
(()
async
=>
await
stderr
.
done
,
throwsA
(
isA
<
Exception
>()));
});
group
(
'Spinners'
,
()
{
...
...
@@ -1175,3 +1119,29 @@ Matcher _matchesInvocation(Invocation expected) {
/// to [FakeLogger].
Matcher
_throwsInvocationFor
(
dynamic
Function
()
fakeCall
)
=>
throwsA
(
_matchesInvocation
(
_invocationFor
(
fakeCall
)));
class
FakeStdout
extends
Fake
implements
Stdout
{
FakeStdout
({
@required
this
.
syncError
,
this
.
completeWithError
=
false
});
final
bool
syncError
;
final
bool
completeWithError
;
final
Completer
<
void
>
_completer
=
Completer
<
void
>();
@override
void
write
(
Object
object
)
{
if
(
syncError
)
{
throw
'Error!'
;
}
Zone
.
current
.
runUnaryGuarded
<
void
>((
_
)
{
if
(
completeWithError
)
{
_completer
.
completeError
(
Exception
(
'Some pipe error'
));
}
else
{
_completer
.
complete
();
throw
'Error!'
;
}
},
null
);
}
@override
Future
<
void
>
get
done
=>
_completer
.
future
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment