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
bfe16a86
Unverified
Commit
bfe16a86
authored
May 10, 2021
by
Jonah Williams
Committed by
GitHub
May 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove even more mocks (#81618)
parent
67aaa0e7
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
260 additions
and
446 deletions
+260
-446
process_test.dart
...s/flutter_tools/test/general.shard/base/process_test.dart
+65
-145
icon_tree_shaker_test.dart
...ral.shard/build_system/targets/icon_tree_shaker_test.dart
+42
-77
ios_device_start_prebuilt_test.dart
...est/general.shard/ios/ios_device_start_prebuilt_test.dart
+13
-9
xcodeproj_test.dart
.../flutter_tools/test/general.shard/ios/xcodeproj_test.dart
+0
-38
resident_web_runner_cold_test.dart
...ols/test/general.shard/resident_web_runner_cold_test.dart
+137
-89
fake_devices.dart
packages/flutter_tools/test/src/fake_devices.dart
+3
-0
mocks.dart
packages/flutter_tools/test/src/mocks.dart
+0
-88
No files found.
packages/flutter_tools/test/general.shard/base/process_test.dart
View file @
bfe16a86
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart
View file @
bfe16a86
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/ios/ios_device_start_prebuilt_test.dart
View file @
bfe16a86
...
...
@@ -20,7 +20,7 @@ import 'package:flutter_tools/src/ios/devices.dart';
import
'package:flutter_tools/src/ios/ios_deploy.dart'
;
import
'package:flutter_tools/src/ios/iproxy.dart'
;
import
'package:flutter_tools/src/ios/mac.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../../src/common.dart'
;
import
'../../src/fake_devices.dart'
;
...
...
@@ -86,12 +86,10 @@ stdout: '(lldb) run\nsuccess',
);
void
main
(
)
{
// TODO(jonahwilliams): This test doesn't really belong here but
// I don't have a better place for it for now.
testWithoutContext
(
'disposing device disposes the portForwarder and logReader'
,
()
async
{
final
IOSDevice
device
=
setUpIOSDevice
();
final
DevicePortForwarder
devicePortForwarder
=
Mock
DevicePortForwarder
();
final
DeviceLogReader
deviceLogReader
=
Mock
DeviceLogReader
();
final
FakeDevicePortForwarder
devicePortForwarder
=
Fake
DevicePortForwarder
();
final
FakeDeviceLogReader
deviceLogReader
=
Fake
DeviceLogReader
();
final
IOSApp
iosApp
=
PrebuiltIOSApp
(
projectBundleId:
'app'
,
bundleName:
'Runner'
,
...
...
@@ -101,8 +99,8 @@ void main() {
device
.
setLogReader
(
iosApp
,
deviceLogReader
);
await
device
.
dispose
();
verify
(
deviceLogReader
.
dispose
()).
called
(
1
);
verify
(
devicePortForwarder
.
dispose
()).
called
(
1
);
expect
(
deviceLogReader
.
disposed
,
true
);
expect
(
devicePortForwarder
.
disposed
,
true
);
});
testWithoutContext
(
'IOSDevice.startApp attaches in debug mode via log reading on iOS 13+'
,
()
async
{
...
...
@@ -384,5 +382,11 @@ IOSDevice setUpIOSDevice({
);
}
class
MockDevicePortForwarder
extends
Mock
implements
DevicePortForwarder
{}
class
MockDeviceLogReader
extends
Mock
implements
DeviceLogReader
{}
class
FakeDevicePortForwarder
extends
Fake
implements
DevicePortForwarder
{
bool
disposed
=
false
;
@override
Future
<
void
>
dispose
()
async
{
disposed
=
true
;
}
}
packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart
View file @
bfe16a86
...
...
@@ -16,55 +16,17 @@ import 'package:flutter_tools/src/ios/xcode_build_settings.dart';
import
'package:flutter_tools/src/ios/xcodeproj.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/mocks.dart'
as
mocks
;
const
String
xcodebuild
=
'/usr/bin/xcodebuild'
;
void
main
(
)
{
group
(
'MockProcessManager'
,
()
{
mocks
.
MockProcessManager
processManager
;
XcodeProjectInterpreter
xcodeProjectInterpreter
;
FakePlatform
platform
;
BufferLogger
logger
;
setUp
(()
{
processManager
=
mocks
.
MockProcessManager
();
platform
=
FakePlatform
(
operatingSystem:
'macos'
);
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
.
file
(
xcodebuild
).
createSync
(
recursive:
true
);
logger
=
BufferLogger
.
test
();
xcodeProjectInterpreter
=
XcodeProjectInterpreter
(
logger:
logger
,
fileSystem:
fileSystem
,
platform:
platform
,
processManager:
processManager
,
usage:
null
,
);
});
testUsingContext
(
'xcodebuild build settings flakes'
,
()
async
{
const
Duration
delay
=
Duration
(
seconds:
1
);
processManager
.
processFactory
=
mocks
.
flakyProcessFactory
(
flakes:
1
,
delay:
delay
+
const
Duration
(
seconds:
1
),
);
platform
.
environment
=
const
<
String
,
String
>{};
when
(
processManager
.
runSync
(<
String
>[
'which'
,
'sysctl'
]))
.
thenReturn
(
ProcessResult
(
0
,
0
,
''
,
''
));
when
(
processManager
.
runSync
(<
String
>[
'sysctl'
,
'hw.optional.arm64'
]))
.
thenReturn
(
ProcessResult
(
0
,
1
,
''
,
''
));
expect
(
await
xcodeProjectInterpreter
.
getBuildSettings
(
''
,
buildContext:
const
XcodeProjectBuildContext
(
scheme:
'Runner'
),
timeout:
delay
),
const
<
String
,
String
>{});
// build settings times out and is killed once, then succeeds.
verify
(
processManager
.
killPid
(
any
)).
called
(
1
);
// The verbose logs should tell us something timed out.
expect
(
logger
.
traceText
,
contains
(
'timed out'
));
});
});
...
...
packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart
View file @
bfe16a86
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/src/fake_devices.dart
View file @
bfe16a86
...
...
@@ -184,6 +184,8 @@ class FakeDeviceLogReader extends DeviceLogReader {
StreamController
<
String
>
_cachedLinesController
;
bool
disposed
=
false
;
final
List
<
String
>
_lineQueue
=
<
String
>[];
StreamController
<
String
>
get
_linesController
{
_cachedLinesController
??=
StreamController
<
String
>
...
...
@@ -209,5 +211,6 @@ class FakeDeviceLogReader extends DeviceLogReader {
Future
<
void
>
dispose
()
async
{
_lineQueue
.
clear
();
await
_linesController
.
close
();
disposed
=
true
;
}
}
packages/flutter_tools/test/src/mocks.dart
deleted
100644 → 0
View file @
67aaa0e7
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'dart:async'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'fakes.dart'
;
/// A strategy for creating Process objects from a list of commands.
typedef
_ProcessFactory
=
Process
Function
(
List
<
String
>
command
);
/// A ProcessManager that starts Processes by delegating to a ProcessFactory.
class
MockProcessManager
extends
Mock
implements
ProcessManager
{
_ProcessFactory
processFactory
=
_defaulProcessFactory
;
bool
canRunSucceeds
=
true
;
bool
runSucceeds
=
true
;
List
<
String
>
commands
;
static
Process
_defaulProcessFactory
(
List
<
String
>
commands
)
=>
FakeProcess
();
@override
bool
canRun
(
dynamic
command
,
{
String
workingDirectory
})
=>
canRunSucceeds
;
@override
Future
<
Process
>
start
(
List
<
dynamic
>
command
,
{
String
workingDirectory
,
Map
<
String
,
String
>
environment
,
bool
includeParentEnvironment
=
true
,
bool
runInShell
=
false
,
ProcessStartMode
mode
=
ProcessStartMode
.
normal
,
})
{
final
List
<
String
>
commands
=
command
.
cast
<
String
>();
if
(!
runSucceeds
)
{
final
String
executable
=
commands
[
0
];
final
List
<
String
>
arguments
=
commands
.
length
>
1
?
commands
.
sublist
(
1
)
:
<
String
>[];
throw
ProcessException
(
executable
,
arguments
);
}
this
.
commands
=
commands
;
return
Future
<
Process
>.
value
(
processFactory
(
commands
));
}
}
/// A function that generates a process factory that gives processes that fail
/// a given number of times before succeeding. The returned processes will
/// fail after a delay if one is supplied.
_ProcessFactory
flakyProcessFactory
(
{
int
flakes
,
bool
Function
(
List
<
String
>
command
)
filter
,
Duration
delay
,
Stream
<
List
<
int
>>
Function
()
stdout
,
Stream
<
List
<
int
>>
Function
()
stderr
,
})
{
int
flakesLeft
=
flakes
;
stdout
??=
()
=>
const
Stream
<
List
<
int
>>.
empty
();
stderr
??=
()
=>
const
Stream
<
List
<
int
>>.
empty
();
return
(
List
<
String
>
command
)
{
if
(
filter
!=
null
&&
!
filter
(
command
))
{
return
FakeProcess
();
}
if
(
flakesLeft
==
0
)
{
return
FakeProcess
(
exitCode:
Future
<
int
>.
value
(
0
),
stdout:
stdout
(),
stderr:
stderr
(),
);
}
flakesLeft
=
flakesLeft
-
1
;
Future
<
int
>
exitFuture
;
if
(
delay
==
null
)
{
exitFuture
=
Future
<
int
>.
value
(-
9
);
}
else
{
exitFuture
=
Future
<
int
>.
delayed
(
delay
,
()
=>
Future
<
int
>.
value
(-
9
));
}
return
FakeProcess
(
exitCode:
exitFuture
,
stdout:
stdout
(),
stderr:
stderr
(),
);
};
}
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