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
88e6d46d
Unverified
Commit
88e6d46d
authored
Feb 10, 2021
by
Jenn Magder
Committed by
GitHub
Feb 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MockProcessManager -> FakeProcessManager (#75544)
parent
8df58eb6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
83 deletions
+78
-83
run_test.dart
.../flutter_tools/test/commands.shard/hermetic/run_test.dart
+4
-7
gradle_errors_test.dart
..._tools/test/general.shard/android/gradle_errors_test.dart
+22
-39
mac_test.dart
packages/flutter_tools/test/general.shard/ios/mac_test.dart
+32
-24
flutter_tester_test.dart
..._tools/test/general.shard/tester/flutter_tester_test.dart
+20
-13
No files found.
packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
View file @
88e6d46d
...
...
@@ -33,7 +33,6 @@ import 'package:vm_service/vm_service.dart';
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/fakes.dart'
;
import
'../../src/mocks.dart'
;
import
'../../src/testbed.dart'
;
void
main
(
)
{
...
...
@@ -145,7 +144,6 @@ void main() {
MemoryFileSystem
fs
;
Artifacts
artifacts
;
MockCache
mockCache
;
MockProcessManager
mockProcessManager
;
TestUsage
usage
;
Directory
tempDir
;
...
...
@@ -154,7 +152,6 @@ void main() {
mockCache
=
MockCache
();
usage
=
TestUsage
();
fs
=
MemoryFileSystem
.
test
();
mockProcessManager
=
MockProcessManager
();
tempDir
=
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_run_test.'
);
fs
.
currentDirectory
=
tempDir
;
...
...
@@ -201,7 +198,7 @@ void main() {
},
overrides:
<
Type
,
Generator
>{
DeviceManager:
()
=>
mockDeviceManager
,
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
mockProcessManager
,
ProcessManager:
()
=>
FakeProcessManager
.
any
()
,
});
testUsingContext
(
'fails when targeted device is not Android with --device-user'
,
()
async
{
...
...
@@ -289,7 +286,7 @@ void main() {
},
overrides:
<
Type
,
Generator
>{
DeviceManager:
()
=>
mockDeviceManager
,
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
mockProcessManager
,
ProcessManager:
()
=>
FakeProcessManager
.
any
()
,
});
testUsingContext
(
'updates cache before checking for devices'
,
()
async
{
...
...
@@ -333,7 +330,7 @@ void main() {
Cache:
()
=>
mockCache
,
DeviceManager:
()
=>
mockDeviceManager
,
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
mockProcessManager
,
ProcessManager:
()
=>
FakeProcessManager
.
any
()
,
});
testUsingContext
(
'passes device target platform to usage'
,
()
async
{
...
...
@@ -390,7 +387,7 @@ void main() {
Cache:
()
=>
mockCache
,
DeviceManager:
()
=>
mockDeviceManager
,
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
mockProcessManager
,
ProcessManager:
()
=>
FakeProcessManager
.
any
()
,
Usage:
()
=>
usage
,
});
});
...
...
packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
View file @
88e6d46d
...
...
@@ -10,17 +10,14 @@ import 'package:flutter_tools/src/android/gradle_errors.dart';
import
'package:flutter_tools/src/android/gradle_utils.dart'
;
import
'package:flutter_tools/src/base/context.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/mocks.dart'
;
void
main
(
)
{
group
(
'gradleErrors'
,
()
{
...
...
@@ -371,7 +368,7 @@ Command: /home/android/gradlew assembleRelease
expect(status, equals(GradleBuildStatus.exit));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () =>
MockProcessManager
(),
ProcessManager: () =>
FakeProcessManager.any
(),
Usage: () => testUsage,
});
...
...
@@ -406,7 +403,7 @@ Command: /home/android/gradlew assembleRelease
expect
(
status
,
equals
(
GradleBuildStatus
.
exit
));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
ProcessManager:
()
=>
MockProcessManager
(),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Usage:
()
=>
testUsage
,
});
...
...
@@ -434,7 +431,7 @@ Command: /home/android/gradlew assembleRelease
expect
(
status
,
equals
(
GradleBuildStatus
.
exit
));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
ProcessManager:
()
=>
MockProcessManager
(),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Usage:
()
=>
testUsage
,
});
...
...
@@ -468,7 +465,7 @@ Command: /home/android/gradlew assembleRelease
expect
(
status
,
equals
(
GradleBuildStatus
.
retryWithAarPlugins
));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
ProcessManager:
()
=>
MockProcessManager
(),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Usage:
()
=>
testUsage
,
});
});
...
...
@@ -529,10 +526,10 @@ Command: /home/android/gradlew assembleRelease
});
group
(
'flavor undefined'
,
()
{
MockProcessManager
mock
ProcessManager
;
FakeProcessManager
fake
ProcessManager
;
setUp
(()
{
mockProcessManager
=
MockProcessManager
(
);
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]
);
});
testWithoutContext
(
'pattern'
,
()
{
...
...
@@ -563,20 +560,14 @@ Command: /home/android/gradlew assembleRelease
});
testUsingContext
(
'handler - with flavor'
,
()
async
{
when
(
mockProcessManager
.
run
(
<
String
>[
'gradlew'
,
'app:tasks'
,
'--all'
,
'--console=auto'
,
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'gradlew'
,
'app:tasks'
,
'--all'
,
'--console=auto'
,
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
),
)).
thenAnswer
((
_
)
async
{
return
ProcessResult
(
1
,
0
,
'''
stdout:
'''
assembleRelease
assembleFlavor1
assembleFlavor1Release
...
...
@@ -587,9 +578,7 @@ assembleProfile
assembles
assembleFooTest
'''
,
''
,
);
});
));
await
flavorUndefinedHandler
.
handler
(
project:
FlutterProject
.
current
(),
...
...
@@ -610,35 +599,28 @@ assembleFooTest
'You must specify a --flavor option to select one of them.'
)
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
},
overrides:
<
Type
,
Generator
>{
GradleUtils:
()
=>
FakeGradleUtils
(),
Platform:
()
=>
fakePlatform
(
'android'
),
ProcessManager:
()
=>
mock
ProcessManager
,
ProcessManager:
()
=>
fake
ProcessManager
,
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
});
testUsingContext
(
'handler - without flavor'
,
()
async
{
when
(
mockProcessManager
.
run
(
<
String
>[
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'gradlew'
,
'app:tasks'
,
'--all'
,
'--console=auto'
,
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
),
)).
thenAnswer
((
_
)
async
{
return
ProcessResult
(
1
,
0
,
'''
stdout:
'''
assembleRelease
assembleDebug
assembleProfile
'''
,
''
,
);
});
));
await
flavorUndefinedHandler
.
handler
(
project:
FlutterProject
.
current
(),
...
...
@@ -658,10 +640,11 @@ assembleProfile
'You cannot use the --flavor option.'
)
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
},
overrides:
<
Type
,
Generator
>{
GradleUtils:
()
=>
FakeGradleUtils
(),
Platform:
()
=>
fakePlatform
(
'android'
),
ProcessManager:
()
=>
mock
ProcessManager
,
ProcessManager:
()
=>
fake
ProcessManager
,
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
});
});
...
...
packages/flutter_tools/test/general.shard/ios/mac_test.dart
View file @
88e6d46d
...
...
@@ -8,7 +8,6 @@ import 'package:file/file.dart';
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/artifacts.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
show
ProcessResult
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/base/process.dart'
;
...
...
@@ -18,7 +17,6 @@ import 'package:flutter_tools/src/ios/mac.dart';
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
...
...
@@ -29,7 +27,6 @@ final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
Platform:
_kNoColorTerminalPlatform
,
};
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
MockIosProject
extends
Mock
implements
IosProject
{}
void
main
(
)
{
...
...
@@ -52,25 +49,33 @@ void main() {
});
group
(
'screenshot'
,
()
{
MockProcessManager
mock
ProcessManager
;
FakeProcessManager
fake
ProcessManager
;
File
outputFile
;
setUp
(()
{
mockProcessManager
=
MockProcessManager
(
);
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]
);
outputFile
=
MemoryFileSystem
.
test
().
file
(
'image.png'
);
});
testWithoutContext
(
'error if idevicescreenshot is not installed'
,
()
async
{
// Let `idevicescreenshot` fail with exit code 1.
when
(
mockProcessManager
.
run
(<
String
>[
'Artifact.idevicescreenshot.TargetPlatform.ios'
,
outputFile
.
path
],
environment:
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
'Artifact.idevicescreenshot.TargetPlatform.ios'
},
workingDirectory:
null
,
)).
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
4
,
1
,
''
,
''
)));
fakeProcessManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
'Artifact.idevicescreenshot.TargetPlatform.ios'
,
outputFile
.
path
,
'--udid'
,
'1234'
,
],
environment:
const
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
'/path/to/libraries'
,
},
exitCode:
1
,
));
final
IMobileDevice
iMobileDevice
=
IMobileDevice
(
artifacts:
artifacts
,
cache:
cache
,
processManager:
mock
ProcessManager
,
processManager:
fake
ProcessManager
,
logger:
logger
,
);
...
...
@@ -79,16 +84,21 @@ void main() {
'1234'
,
IOSDeviceInterface
.
usb
,
),
throwsA
(
anything
));
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'idevicescreenshot captures and returns USB screenshot'
,
()
async
{
when
(
mockProcessManager
.
run
(
any
,
environment:
anyNamed
(
'environment'
),
workingDirectory:
null
)).
thenAnswer
(
(
Invocation
invocation
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
4
,
0
,
''
,
''
)));
fakeProcessManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
'Artifact.idevicescreenshot.TargetPlatform.ios'
,
outputFile
.
path
,
'--udid'
,
'1234'
,
],
environment:
const
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
'/path/to/libraries'
},
));
final
IMobileDevice
iMobileDevice
=
IMobileDevice
(
artifacts:
artifacts
,
cache:
cache
,
processManager:
mock
ProcessManager
,
processManager:
fake
ProcessManager
,
logger:
logger
,
);
...
...
@@ -97,20 +107,21 @@ void main() {
'1234'
,
IOSDeviceInterface
.
usb
,
);
verify
(
mockProcessManager
.
run
(<
String
>[
'Artifact.idevicescreenshot.TargetPlatform.ios'
,
outputFile
.
path
,
'--udid'
,
'1234'
],
environment:
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
'/path/to/libraries'
},
workingDirectory:
null
,
));
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'idevicescreenshot captures and returns network screenshot'
,
()
async
{
when
(
mockProcessManager
.
run
(
any
,
environment:
anyNamed
(
'environment'
),
workingDirectory:
null
)).
thenAnswer
(
(
Invocation
invocation
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
4
,
0
,
''
,
''
)));
fakeProcessManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
'Artifact.idevicescreenshot.TargetPlatform.ios'
,
outputFile
.
path
,
'--udid'
,
'1234'
,
'--network'
,
],
environment:
const
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
'/path/to/libraries'
},
));
final
IMobileDevice
iMobileDevice
=
IMobileDevice
(
artifacts:
artifacts
,
cache:
cache
,
processManager:
mock
ProcessManager
,
processManager:
fake
ProcessManager
,
logger:
logger
,
);
...
...
@@ -119,10 +130,7 @@ void main() {
'1234'
,
IOSDeviceInterface
.
network
,
);
verify
(
mockProcessManager
.
run
(<
String
>[
'Artifact.idevicescreenshot.TargetPlatform.ios'
,
outputFile
.
path
,
'--udid'
,
'1234'
,
'--network'
],
environment:
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
'/path/to/libraries'
},
workingDirectory:
null
,
));
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
});
});
...
...
packages/flutter_tools/test/general.shard/tester/flutter_tester_test.dart
View file @
88e6d46d
...
...
@@ -20,7 +20,6 @@ import 'package:process/process.dart';
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/mocks.dart'
;
void
main
(
)
{
MemoryFileSystem
fileSystem
;
...
...
@@ -79,23 +78,20 @@ void main() {
List
<
String
>
logLines
;
String
mainPath
;
MockProcessManager
mockProcessManager
;
MockProcess
mockProcess
;
FakeProcessManager
fakeProcessManager
;
MockBuildSystem
mockBuildSystem
;
final
Map
<
Type
,
Generator
>
startOverrides
=
<
Type
,
Generator
>{
Platform:
()
=>
FakePlatform
(
operatingSystem:
'linux'
),
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
mock
ProcessManager
,
ProcessManager:
()
=>
fake
ProcessManager
,
Artifacts:
()
=>
Artifacts
.
test
(),
BuildSystem:
()
=>
mockBuildSystem
,
};
setUp
(()
{
mockBuildSystem
=
MockBuildSystem
();
mockProcessManager
=
MockProcessManager
();
mockProcessManager
.
processFactory
=
(
List
<
String
>
commands
)
=>
mockProcess
;
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]);
when
(
mockBuildSystem
.
build
(
any
,
...
...
@@ -105,7 +101,7 @@ void main() {
});
device
=
FlutterTesterDevice
(
'flutter-tester'
,
fileSystem:
fileSystem
,
processManager:
mock
ProcessManager
,
processManager:
fake
ProcessManager
,
artifacts:
Artifacts
.
test
(),
buildDirectory:
'build'
,
logger:
BufferLogger
.
test
(),
...
...
@@ -149,17 +145,27 @@ void main() {
expect
(
jitReleaseResult
.
started
,
isFalse
);
});
testUsingContext
(
'performs a build and starts in debug mode'
,
()
async
{
final
FlutterTesterApp
app
=
FlutterTesterApp
.
fromCurrentDirectory
(
fileSystem
);
final
Uri
observatoryUri
=
Uri
.
parse
(
'http://127.0.0.1:6666/'
);
mockProcess
=
MockProcess
(
stdout:
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
final
String
assetsPath
=
fileSystem
.
path
.
join
(
'build'
,
'flutter_assets'
);
final
String
dillPath
=
fileSystem
.
path
.
join
(
'build'
,
'flutter-tester-app.dill'
);
fakeProcessManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
'Artifact.flutterTester'
,
'--run-forever'
,
'--non-interactive'
,
'--enable-dart-profiling'
,
'--packages=.packages'
,
'--flutter-assets-dir=
$assetsPath
'
,
dillPath
,
],
stdout:
'''
Observatory listening on
$observatoryUri
Hello!
'''
.
codeUnits
,
]));
'''
,
));
final
LaunchResult
result
=
await
device
.
startApp
(
app
,
mainPath:
mainPath
,
...
...
@@ -169,6 +175,7 @@ Hello!
expect
(
result
.
started
,
isTrue
);
expect
(
result
.
observatoryUri
,
observatoryUri
);
expect
(
logLines
.
last
,
'Hello!'
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
},
overrides:
startOverrides
);
});
}
...
...
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