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
547ed88a
Unverified
Commit
547ed88a
authored
Jan 28, 2021
by
Jenn Magder
Committed by
GitHub
Jan 28, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Swap MockStdio to FakeStdio in tests (#74838)
parent
f04616f7
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
43 additions
and
53 deletions
+43
-53
run_test.dart
.../flutter_tools/test/commands.shard/hermetic/run_test.dart
+1
-1
symbolize_test.dart
...er_tools/test/commands.shard/hermetic/symbolize_test.dart
+3
-3
analytics_test.dart
...ages/flutter_tools/test/general.shard/analytics_test.dart
+5
-5
android_workflow_test.dart
...ols/test/general.shard/android/android_workflow_test.dart
+4
-3
artifact_updater_test.dart
...utter_tools/test/general.shard/artifact_updater_test.dart
+2
-2
bot_detector_test.dart
...tter_tools/test/general.shard/base/bot_detector_test.dart
+0
-14
command_help_test.dart
...tter_tools/test/general.shard/base/command_help_test.dart
+2
-2
net_test.dart
packages/flutter_tools/test/general.shard/base/net_test.dart
+2
-2
process_test.dart
...s/flutter_tools/test/general.shard/base/process_test.dart
+3
-3
icon_tree_shaker_test.dart
...ral.shard/build_system/targets/icon_tree_shaker_test.dart
+2
-1
flutter_command_runner_test.dart
...est/general.shard/runner/flutter_command_runner_test.dart
+1
-17
fakes.dart
packages/flutter_tools/test/src/fakes.dart
+18
-0
No files found.
packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
View file @
547ed88a
...
...
@@ -227,7 +227,7 @@ void main() {
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
DeviceManager:
()
=>
mockDeviceManager
,
Stdio:
()
=>
MockStdio
(
),
Stdio:
()
=>
FakeStdio
(
hasFakeTerminal:
true
),
});
testUsingContext
(
'shows unsupported devices when no supported devices are found'
,
()
async
{
...
...
packages/flutter_tools/test/commands.shard/hermetic/symbolize_test.dart
View file @
547ed88a
...
...
@@ -17,12 +17,12 @@ import 'package:mockito/mockito.dart';
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/
mock
s.dart'
;
import
'../../src/
fake
s.dart'
;
void
main
(
)
{
MemoryFileSystem
fileSystem
;
Mock
Stdio
stdio
;
Fake
Stdio
stdio
;
SymbolizeCommand
command
;
MockDwarfSymbolizationService
mockDwarfSymbolizationService
;
...
...
@@ -32,7 +32,7 @@ void main() {
setUp
(()
{
fileSystem
=
MemoryFileSystem
.
test
();
stdio
=
Mock
Stdio
();
stdio
=
Fake
Stdio
();
mockDwarfSymbolizationService
=
MockDwarfSymbolizationService
();
command
=
SymbolizeCommand
(
stdio:
stdio
,
...
...
packages/flutter_tools/test/general.shard/analytics_test.dart
View file @
547ed88a
...
...
@@ -26,7 +26,7 @@ import 'package:usage/usage_io.dart';
import
'../src/common.dart'
;
import
'../src/context.dart'
;
import
'../src/
mock
s.dart'
;
import
'../src/
fake
s.dart'
;
void
main
(
)
{
setUpAll
(()
{
...
...
@@ -152,7 +152,7 @@ void main() {
group
(
'analytics with mocks'
,
()
{
MemoryFileSystem
memoryFileSystem
;
MockStdio
mock
Stdio
;
FakeStdio
fake
Stdio
;
Usage
mockUsage
;
SystemClock
mockClock
;
Doctor
mockDoctor
;
...
...
@@ -160,7 +160,7 @@ void main() {
setUp
(()
{
memoryFileSystem
=
MemoryFileSystem
.
test
();
mockStdio
=
Mock
Stdio
();
fakeStdio
=
Fake
Stdio
();
mockUsage
=
MockUsage
();
mockClock
=
MockClock
();
mockDoctor
=
MockDoctor
();
...
...
@@ -266,7 +266,7 @@ void main() {
'FLUTTER_ANALYTICS_LOG_FILE'
:
'analytics.log'
,
},
),
Stdio:
()
=>
mock
Stdio
,
Stdio:
()
=>
fake
Stdio
,
});
testUsingContext
(
'event sends localtime'
,
()
async
{
...
...
@@ -296,7 +296,7 @@ void main() {
'FLUTTER_ANALYTICS_LOG_FILE'
:
'analytics.log'
,
},
),
Stdio:
()
=>
mock
Stdio
,
Stdio:
()
=>
fake
Stdio
,
});
});
...
...
packages/flutter_tools/test/general.shard/android/android_workflow_test.dart
View file @
547ed88a
...
...
@@ -18,7 +18,8 @@ import 'package:mockito/mockito.dart';
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/mocks.dart'
show
MockAndroidSdk
,
MockProcess
,
MockProcessManager
,
MockStdio
;
import
'../../src/fakes.dart'
;
import
'../../src/mocks.dart'
show
MockAndroidSdk
,
MockProcess
,
MockProcessManager
;
import
'../../src/testbed.dart'
;
class
MockAndroidSdkVersion
extends
Mock
implements
AndroidSdkVersion
{}
...
...
@@ -29,7 +30,7 @@ void main() {
Logger
logger
;
MemoryFileSystem
fileSystem
;
MockProcessManager
processManager
;
Mock
Stdio
stdio
;
Fake
Stdio
stdio
;
setUp
(()
{
sdk
=
MockAndroidSdk
();
...
...
@@ -37,7 +38,7 @@ void main() {
fileSystem
.
directory
(
'/home/me'
).
createSync
(
recursive:
true
);
logger
=
BufferLogger
.
test
();
processManager
=
MockProcessManager
();
stdio
=
Mock
Stdio
();
stdio
=
Fake
Stdio
();
});
MockProcess
Function
(
List
<
String
>)
processMetaFactory
(
List
<
String
>
stdout
)
{
...
...
packages/flutter_tools/test/general.shard/artifact_updater_test.dart
View file @
547ed88a
...
...
@@ -18,7 +18,7 @@ import 'package:flutter_tools/src/cache.dart';
import
'package:mockito/mockito.dart'
;
import
'../src/common.dart'
;
import
'../src/
mock
s.dart'
;
import
'../src/
fake
s.dart'
;
final
Platform
testPlatform
=
FakePlatform
(
environment:
const
<
String
,
String
>{});
...
...
@@ -171,7 +171,7 @@ void main() {
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
Logger
logger
=
StdoutLogger
(
terminal:
Terminal
.
test
(
supportsColor:
true
),
stdio:
Mock
Stdio
(),
stdio:
Fake
Stdio
(),
outputPreferences:
OutputPreferences
.
test
(),
);
final
ArtifactUpdater
artifactUpdater
=
ArtifactUpdater
(
...
...
packages/flutter_tools/test/general.shard/base/bot_detector_test.dart
View file @
547ed88a
...
...
@@ -16,12 +16,10 @@ import 'package:mockito/mockito.dart';
import
'package:fake_async/fake_async.dart'
;
import
'../../src/common.dart'
;
import
'../../src/mocks.dart'
;
void
main
(
)
{
group
(
'BotDetector'
,
()
{
FakePlatform
fakePlatform
;
MockStdio
mockStdio
;
MockHttpClient
mockHttpClient
;
MockHttpClientRequest
mockHttpClientRequest
;
MockHttpHeaders
mockHttpHeaders
;
...
...
@@ -30,7 +28,6 @@ void main() {
setUp
(()
{
fakePlatform
=
FakePlatform
()..
environment
=
<
String
,
String
>{};
mockStdio
=
MockStdio
();
mockHttpClient
=
MockHttpClient
();
mockHttpClientRequest
=
MockHttpClientRequest
();
mockHttpHeaders
=
MockHttpHeaders
();
...
...
@@ -62,17 +59,6 @@ void main() {
expect
(
persistentToolState
.
isRunningOnBot
,
isFalse
);
});
testWithoutContext
(
'returns false with and without a terminal attached'
,
()
async
{
when
(
mockHttpClient
.
getUrl
(
any
)).
thenAnswer
((
_
)
{
throw
const
SocketException
(
'HTTP connection timed out'
);
});
mockStdio
.
stdout
.
hasTerminal
=
true
;
expect
(
await
botDetector
.
isRunningOnBot
,
isFalse
);
mockStdio
.
stdout
.
hasTerminal
=
false
;
expect
(
await
botDetector
.
isRunningOnBot
,
isFalse
);
expect
(
persistentToolState
.
isRunningOnBot
,
isFalse
);
});
testWithoutContext
(
'can test analytics outputs on bots when outputting to a file'
,
()
async
{
fakePlatform
.
environment
[
'TRAVIS'
]
=
'true'
;
fakePlatform
.
environment
[
'FLUTTER_ANALYTICS_LOG_FILE'
]
=
'/some/file'
;
...
...
packages/flutter_tools/test/general.shard/base/command_help_test.dart
View file @
547ed88a
...
...
@@ -11,7 +11,7 @@ import 'package:flutter_tools/src/base/terminal.dart' show AnsiTerminal, OutputP
import
'package:meta/meta.dart'
;
import
'../../src/common.dart'
;
import
'../../src/
mocks.dart'
show
MockStdio
;
import
'../../src/
fakes.dart'
;
CommandHelp
_createCommandHelp
(
{
@required
bool
ansi
,
...
...
@@ -23,7 +23,7 @@ CommandHelp _createCommandHelp({
return
CommandHelp
(
logger:
BufferLogger
.
test
(),
terminal:
AnsiTerminal
(
stdio:
Mock
Stdio
(),
stdio:
Fake
Stdio
(),
platform:
platform
,
),
platform:
platform
,
...
...
packages/flutter_tools/test/general.shard/base/net_test.dart
View file @
547ed88a
...
...
@@ -18,7 +18,7 @@ import 'package:flutter_tools/src/base/terminal.dart';
import
'package:fake_async/fake_async.dart'
;
import
'../../src/common.dart'
;
import
'../../src/
mocks.dart'
show
MockStdio
;
import
'../../src/
fakes.dart'
;
void
main
(
)
{
BufferLogger
testLogger
;
...
...
@@ -26,7 +26,7 @@ void main() {
setUp
(()
{
testLogger
=
BufferLogger
(
terminal:
AnsiTerminal
(
stdio:
Mock
Stdio
(),
stdio:
Fake
Stdio
(),
platform:
FakePlatform
(
stdoutSupportsAnsi:
false
),
),
outputPreferences:
OutputPreferences
.
test
(),
...
...
packages/flutter_tools/test/general.shard/base/process_test.dart
View file @
547ed88a
...
...
@@ -15,9 +15,9 @@ import 'package:mockito/mockito.dart';
import
'package:fake_async/fake_async.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/fakes.dart'
;
import
'../../src/mocks.dart'
show
MockProcess
,
MockProcessManager
,
MockStdio
,
flakyProcessFactory
;
void
main
(
)
{
...
...
@@ -90,7 +90,7 @@ void main() {
mockProcessManager
=
MockProcessManager
();
mockLogger
=
BufferLogger
(
terminal:
AnsiTerminal
(
stdio:
Mock
Stdio
(),
stdio:
Fake
Stdio
(),
platform:
FakePlatform
(
stdoutSupportsAnsi:
false
),
),
outputPreferences:
OutputPreferences
(
wrapText:
true
,
wrapColumn:
40
),
...
...
@@ -280,7 +280,7 @@ void main() {
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]);
testLogger
=
BufferLogger
(
terminal:
AnsiTerminal
(
stdio:
Mock
Stdio
(),
stdio:
Fake
Stdio
(),
platform:
FakePlatform
(
stdinSupportsAnsi:
false
),
),
outputPreferences:
OutputPreferences
(
wrapText:
true
,
wrapColumn:
40
),
...
...
packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart
View file @
547ed88a
...
...
@@ -22,6 +22,7 @@ import 'package:mockito/mockito.dart';
import
'../../../src/common.dart'
;
import
'../../../src/context.dart'
;
import
'../../../src/fakes.dart'
;
import
'../../../src/mocks.dart'
as
mocks
;
final
Platform
kNoAnsiPlatform
=
FakePlatform
(
stdoutSupportsAnsi:
false
);
...
...
@@ -90,7 +91,7 @@ void main() {
fileSystem
=
MemoryFileSystem
.
test
();
logger
=
BufferLogger
(
terminal:
AnsiTerminal
(
stdio:
mocks
.
Mock
Stdio
(),
stdio:
Fake
Stdio
(),
platform:
kNoAnsiPlatform
,
),
outputPreferences:
OutputPreferences
.
test
(
showColor:
false
),
...
...
packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart
View file @
547ed88a
...
...
@@ -20,6 +20,7 @@ import 'package:process/process.dart';
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/fakes.dart'
;
import
'utils.dart'
;
const
String
_kFlutterRoot
=
'/flutter/flutter'
;
...
...
@@ -253,20 +254,3 @@ class FakeFlutterCommand extends FlutterCommand {
@override
String
get
name
=>
'fake'
;
}
class
FakeStdio
extends
Stdio
{
FakeStdio
({
this
.
hasFakeTerminal
});
final
bool
hasFakeTerminal
;
@override
bool
get
hasTerminal
=>
hasFakeTerminal
;
@override
int
get
terminalColumns
=>
hasFakeTerminal
?
80
:
null
;
@override
int
get
terminalLines
=>
hasFakeTerminal
?
24
:
null
;
@override
bool
get
supportsAnsiEscapes
=>
hasFakeTerminal
;
}
packages/flutter_tools/test/src/fakes.dart
View file @
547ed88a
...
...
@@ -7,6 +7,7 @@
import
'dart:async'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
...
...
@@ -65,3 +66,20 @@ class FakeDyldEnvironmentArtifact extends ArtifactSet {
Future
<
void
>
update
(
ArtifactUpdater
artifactUpdater
,
Logger
logger
,
FileSystem
fileSystem
,
OperatingSystemUtils
operatingSystemUtils
)
async
{
}
}
class
FakeStdio
extends
Stdio
{
FakeStdio
({
this
.
hasFakeTerminal
});
final
bool
hasFakeTerminal
;
@override
bool
get
hasTerminal
=>
hasFakeTerminal
;
@override
int
get
terminalColumns
=>
hasFakeTerminal
?
80
:
null
;
@override
int
get
terminalLines
=>
hasFakeTerminal
?
24
:
null
;
@override
bool
get
supportsAnsiEscapes
=>
hasFakeTerminal
;
}
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