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
becaf491
Unverified
Commit
becaf491
authored
Sep 30, 2020
by
Jenn Magder
Committed by
GitHub
Sep 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace MockCache with Cache.test() (#66946)
parent
f800a67e
Changes
17
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
341 additions
and
274 deletions
+341
-274
gradle_utils.dart
packages/flutter_tools/lib/src/android/gradle_utils.dart
+4
-2
cache.dart
packages/flutter_tools/lib/src/cache.dart
+36
-2
build_ios_framework_test.dart
...est/commands.shard/hermetic/build_ios_framework_test.dart
+26
-19
devices_test.dart
...tter_tools/test/commands.shard/hermetic/devices_test.dart
+2
-5
install_test.dart
...tter_tools/test/commands.shard/hermetic/install_test.dart
+3
-5
application_package_test.dart
...er_tools/test/general.shard/application_package_test.dart
+9
-9
cache_test.dart
packages/flutter_tools/test/general.shard/cache_test.dart
+84
-84
device_test.dart
packages/flutter_tools/test/general.shard/device_test.dart
+2
-4
fuchsia_device_test.dart
...tools/test/general.shard/fuchsia/fuchsia_device_test.dart
+3
-3
devices_test.dart
...es/flutter_tools/test/general.shard/ios/devices_test.dart
+11
-14
ios_deploy_test.dart
...flutter_tools/test/general.shard/ios/ios_deploy_test.dart
+29
-23
ios_device_install_test.dart
...tools/test/general.shard/ios/ios_device_install_test.dart
+51
-39
ios_device_start_nonprebuilt_test.dart
.../general.shard/ios/ios_device_start_nonprebuilt_test.dart
+22
-13
ios_device_start_prebuilt_test.dart
...est/general.shard/ios/ios_device_start_prebuilt_test.dart
+14
-16
mac_test.dart
packages/flutter_tools/test/general.shard/ios/mac_test.dart
+21
-26
xcode_test.dart
...es/flutter_tools/test/general.shard/macos/xcode_test.dart
+4
-10
fakes.dart
packages/flutter_tools/test/src/fakes.dart
+20
-0
No files found.
packages/flutter_tools/lib/src/android/gradle_utils.dart
View file @
becaf491
...
...
@@ -109,9 +109,11 @@ class GradleUtils {
},
);
// Add the `gradle-wrapper.properties` file if it doesn't exist.
final
File
propertiesFile
=
directory
.
childFile
(
globals
.
fs
.
path
.
join
(
'gradle'
,
'wrapper'
,
'gradle-wrapper.properties'
));
final
Directory
propertiesDirectory
=
directory
.
childDirectory
(
globals
.
fs
.
path
.
join
(
'gradle'
,
'wrapper'
));
final
File
propertiesFile
=
propertiesDirectory
.
childFile
(
'gradle-wrapper.properties'
);
if
(!
propertiesFile
.
existsSync
())
{
propertiesDirectory
.
createSync
(
recursive:
true
);
final
String
gradleVersion
=
getGradleVersionForAndroidPlugin
(
directory
);
propertiesFile
.
writeAsStringSync
(
'''
distributionBase=GRADLE_USER_HOME
...
...
packages/flutter_tools/lib/src/cache.dart
View file @
becaf491
...
...
@@ -3,8 +3,10 @@
// found in the LICENSE file.
import
'package:archive/archive.dart'
;
import
'package:file/memory.dart'
;
import
'package:meta/meta.dart'
;
import
'package:package_config/package_config.dart'
;
import
'package:process/process.dart'
;
import
'android/gradle_utils.dart'
;
import
'base/common.dart'
;
...
...
@@ -92,8 +94,8 @@ class Cache {
/// [rootOverride] is configurable for testing.
/// [artifacts] is configurable for testing.
Cache
({
Directory
rootOverride
,
List
<
ArtifactSet
>
artifacts
,
@protected
Directory
rootOverride
,
@protected
List
<
ArtifactSet
>
artifacts
,
// TODO(jonahwilliams): make required once migrated to context-free.
Logger
logger
,
FileSystem
fileSystem
,
...
...
@@ -143,6 +145,38 @@ class Cache {
}
}
/// Create a [Cache] for testing.
///
/// Defaults to a memory file system, fake platform,
/// buffer logger, and no accessible artifacts.
/// By default, the root cache directory path is "cache".
@visibleForTesting
factory
Cache
.
test
({
Directory
rootOverride
,
List
<
ArtifactSet
>
artifacts
,
Logger
logger
,
FileSystem
fileSystem
,
Platform
platform
,
ProcessManager
processManager
,
})
{
fileSystem
??=
rootOverride
?.
fileSystem
??
MemoryFileSystem
.
test
();
platform
??=
FakePlatform
(
environment:
<
String
,
String
>{});
logger
??=
BufferLogger
.
test
();
return
Cache
(
rootOverride:
rootOverride
??=
fileSystem
.
directory
(
'cache'
),
artifacts:
artifacts
??
<
ArtifactSet
>[],
logger:
logger
,
fileSystem:
fileSystem
,
platform:
platform
,
osUtils:
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
logger
,
platform:
platform
,
processManager:
processManager
,
),
);
}
final
Logger
_logger
;
final
Platform
_platform
;
final
FileSystem
_fileSystem
;
...
...
packages/flutter_tools/test/commands.shard/hermetic/build_ios_framework_test.dart
View file @
becaf491
...
...
@@ -23,7 +23,6 @@ void main() {
MemoryFileSystem
memoryFileSystem
;
MockFlutterVersion
mockFlutterVersion
;
MockGitTagVersion
mockGitTagVersion
;
MockCache
mockCache
;
Directory
outputDirectory
;
FakePlatform
fakePlatform
;
...
...
@@ -31,12 +30,17 @@ void main() {
Cache
.
disableLocking
();
});
const
String
storageBaseUrl
=
'https://fake.googleapis.com'
;
setUp
(()
{
memoryFileSystem
=
MemoryFileSystem
.
test
();
mockFlutterVersion
=
MockFlutterVersion
();
mockGitTagVersion
=
MockGitTagVersion
();
mockCache
=
MockCache
();
fakePlatform
=
FakePlatform
()..
operatingSystem
=
'macos'
;
fakePlatform
=
FakePlatform
(
operatingSystem:
'macos'
,
environment:
<
String
,
String
>{
'FLUTTER_STORAGE_BASE_URL'
:
storageBaseUrl
,
},
);
when
(
mockFlutterVersion
.
gitTagVersion
).
thenReturn
(
mockGitTagVersion
);
outputDirectory
=
globals
.
fs
.
systemTempDirectory
...
...
@@ -46,16 +50,20 @@ void main() {
});
group
(
'podspec'
,
()
{
const
String
storageBaseUrl
=
'https://fake.googleapis.com'
;
const
String
engineRevision
=
'0123456789abcdef'
;
File
licenseFil
e
;
Cache
cach
e
;
setUp
(()
{
final
Directory
rootOverride
=
memoryFileSystem
.
directory
(
'cache'
);
cache
=
Cache
.
test
(
rootOverride:
rootOverride
,
platform:
fakePlatform
,
fileSystem:
memoryFileSystem
,
);
rootOverride
.
childDirectory
(
'bin'
).
childDirectory
(
'internal'
).
childFile
(
'engine.version'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
engineRevision
);
when
(
mockFlutterVersion
.
gitTagVersion
).
thenReturn
(
mockGitTagVersion
);
when
(
mockCache
.
storageBaseUrl
).
thenReturn
(
storageBaseUrl
);
when
(
mockCache
.
engineRevision
).
thenReturn
(
engineRevision
);
licenseFile
=
memoryFileSystem
.
file
(
'LICENSE'
);
when
(
mockCache
.
getLicenseFile
()).
thenReturn
(
licenseFile
);
});
testUsingContext
(
'version unknown'
,
()
async
{
...
...
@@ -66,7 +74,7 @@ void main() {
buildSystem:
MockBuildSystem
(),
platform:
fakePlatform
,
flutterVersion:
mockFlutterVersion
,
cache:
mockC
ache
,
cache:
c
ache
,
verboseHelp:
false
,
);
...
...
@@ -91,7 +99,7 @@ void main() {
buildSystem:
MockBuildSystem
(),
platform:
fakePlatform
,
flutterVersion:
mockFlutterVersion
,
cache:
mockC
ache
,
cache:
c
ache
,
verboseHelp:
false
,
);
...
...
@@ -113,7 +121,7 @@ void main() {
buildSystem:
MockBuildSystem
(),
platform:
fakePlatform
,
flutterVersion:
mockFlutterVersion
,
cache:
mockC
ache
,
cache:
c
ache
,
verboseHelp:
false
,
);
...
...
@@ -136,7 +144,7 @@ void main() {
when
(
mockFlutterVersion
.
frameworkVersion
).
thenReturn
(
frameworkVersion
);
licenseFile
cache
.
getLicenseFile
()
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
licenseText
);
});
...
...
@@ -151,7 +159,7 @@ void main() {
buildSystem:
MockBuildSystem
(),
platform:
fakePlatform
,
flutterVersion:
mockFlutterVersion
,
cache:
mockC
ache
,
cache:
c
ache
,
verboseHelp:
false
,
);
command
.
produceFlutterPodspec
(
BuildMode
.
debug
,
outputDirectory
,
force:
true
);
...
...
@@ -174,7 +182,7 @@ void main() {
buildSystem:
MockBuildSystem
(),
platform:
fakePlatform
,
flutterVersion:
mockFlutterVersion
,
cache:
mockC
ache
,
cache:
c
ache
,
verboseHelp:
false
,
);
command
.
produceFlutterPodspec
(
BuildMode
.
debug
,
outputDirectory
);
...
...
@@ -194,7 +202,7 @@ void main() {
buildSystem:
MockBuildSystem
(),
platform:
fakePlatform
,
flutterVersion:
mockFlutterVersion
,
cache:
mockC
ache
,
cache:
c
ache
,
verboseHelp:
false
,
);
command
.
produceFlutterPodspec
(
BuildMode
.
debug
,
outputDirectory
);
...
...
@@ -212,7 +220,7 @@ void main() {
buildSystem:
MockBuildSystem
(),
platform:
fakePlatform
,
flutterVersion:
mockFlutterVersion
,
cache:
mockC
ache
,
cache:
c
ache
,
verboseHelp:
false
,
);
command
.
produceFlutterPodspec
(
BuildMode
.
profile
,
outputDirectory
);
...
...
@@ -230,7 +238,7 @@ void main() {
buildSystem:
MockBuildSystem
(),
platform:
fakePlatform
,
flutterVersion:
mockFlutterVersion
,
cache:
mockC
ache
,
cache:
c
ache
,
verboseHelp:
false
,
);
command
.
produceFlutterPodspec
(
BuildMode
.
release
,
outputDirectory
);
...
...
@@ -250,5 +258,4 @@ void main() {
class
MockFlutterVersion
extends
Mock
implements
FlutterVersion
{}
class
MockGitTagVersion
extends
Mock
implements
GitTagVersion
{}
class
MockCache
extends
Mock
implements
Cache
{}
class
MockBuildSystem
extends
Mock
implements
BuildSystem
{}
packages/flutter_tools/test/commands.shard/hermetic/devices_test.dart
View file @
becaf491
...
...
@@ -24,11 +24,10 @@ void main() {
Cache
.
disableLocking
();
});
Mock
Cache
cache
;
Cache
cache
;
setUp
(()
{
cache
=
MockCache
();
when
(
cache
.
dyLdLibEntry
).
thenReturn
(
const
MapEntry
<
String
,
String
>(
'foo'
,
'bar'
));
cache
=
Cache
.
test
();
});
testUsingContext
(
'returns 0 when called'
,
()
async
{
...
...
@@ -192,5 +191,3 @@ class NoDevicesManager extends DeviceManager {
@override
List
<
DeviceDiscovery
>
get
deviceDiscoverers
=>
<
DeviceDiscovery
>[];
}
class
MockCache
extends
Mock
implements
Cache
{}
packages/flutter_tools/test/commands.shard/hermetic/install_test.dart
View file @
becaf491
...
...
@@ -29,7 +29,7 @@ void main() {
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'install'
]);
},
overrides:
<
Type
,
Generator
>{
Cache:
()
=>
MockCache
(),
Cache:
()
=>
Cache
.
test
(),
});
testUsingContext
(
'returns 1 when targeted device is not Android with --device-user'
,
()
async
{
...
...
@@ -46,7 +46,7 @@ void main() {
expect
(()
async
=>
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'install'
,
'--device-user'
,
'10'
]),
throwsToolExit
(
message:
'--device-user is only supported for Android'
));
},
overrides:
<
Type
,
Generator
>{
Cache:
()
=>
MockCache
(),
Cache:
()
=>
Cache
.
test
(),
});
testUsingContext
(
'returns 0 when iOS is connected and ready for an install'
,
()
async
{
...
...
@@ -60,9 +60,7 @@ void main() {
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'install'
]);
},
overrides:
<
Type
,
Generator
>{
Cache:
()
=>
MockCache
(),
Cache:
()
=>
Cache
.
test
(),
});
});
}
class
MockCache
extends
Mock
implements
Cache
{}
packages/flutter_tools/test/general.shard/application_package_test.dart
View file @
becaf491
...
...
@@ -39,20 +39,22 @@ void main() {
AndroidSdk
sdk
;
ProcessManager
mockProcessManager
;
MemoryFileSystem
fs
;
Cache
mockC
ache
;
Cache
c
ache
;
File
gradle
;
final
Map
<
Type
,
Generator
>
overrides
=
<
Type
,
Generator
>{
AndroidSdk:
()
=>
sdk
,
ProcessManager:
()
=>
mockProcessManager
,
FileSystem:
()
=>
fs
,
Cache:
()
=>
mockC
ache
,
Cache:
()
=>
c
ache
,
};
setUp
(()
async
{
sdk
=
MockitoAndroidSdk
();
mockProcessManager
=
MockitoProcessManager
();
fs
=
MemoryFileSystem
.
test
();
mockCache
=
MockCache
();
cache
=
Cache
.
test
(
processManager:
FakeProcessManager
.
any
()
);
Cache
.
flutterRoot
=
'../..'
;
when
(
sdk
.
licensesAvailable
).
thenReturn
(
true
);
when
(
mockProcessManager
.
canRun
(
any
)).
thenReturn
(
true
);
...
...
@@ -108,13 +110,12 @@ void main() {
.
childFile
(
'gradle.properties'
)
.
writeAsStringSync
(
'irrelevant'
);
final
Directory
gradleWrapperDir
=
globals
.
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_application_package_test_gradle_wrapper.'
);
when
(
mockCache
.
getArtifactDirectory
(
'gradle_wrapper'
)).
thenReturn
(
gradleWrapperDir
);
final
Directory
gradleWrapperDir
=
cache
.
getArtifactDirectory
(
'gradle_wrapper'
);
g
lobals
.
fs
.
directory
(
gradleWrapperDir
.
childDirectory
(
'gradle'
).
childDirectory
(
'wrapper'
))
g
radleWrapperDir
.
fileSystem
.
directory
(
gradleWrapperDir
.
childDirectory
(
'gradle'
).
childDirectory
(
'wrapper'
))
.
createSync
(
recursive:
true
);
g
lobals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
gradleWrapperDir
.
path
,
'gradlew'
)
).
writeAsStringSync
(
'irrelevant'
);
g
lobals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
gradleWrapperDir
.
path
,
'gradlew.bat'
)
).
writeAsStringSync
(
'irrelevant'
);
g
radleWrapperDir
.
childFile
(
'gradlew'
).
writeAsStringSync
(
'irrelevant'
);
g
radleWrapperDir
.
childFile
(
'gradlew.bat'
).
writeAsStringSync
(
'irrelevant'
);
await
ApplicationPackageFactory
.
instance
.
getPackageForPlatform
(
TargetPlatform
.
android_arm
,
...
...
@@ -691,5 +692,4 @@ const String plistData = '''
{"CFBundleIdentifier": "fooBundleId"}
'''
;
class
MockCache
extends
Mock
implements
Cache
{}
class
MockOperatingSystemUtils
extends
Mock
implements
OperatingSystemUtils
{
}
packages/flutter_tools/test/general.shard/cache_test.dart
View file @
becaf491
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/device_test.dart
View file @
becaf491
...
...
@@ -21,13 +21,12 @@ import '../src/fake_devices.dart';
import
'../src/mocks.dart'
;
void
main
(
)
{
Mock
Cache
cache
;
Cache
cache
;
BufferLogger
logger
;
setUp
(()
{
cache
=
MockCache
();
cache
=
Cache
.
test
();
logger
=
BufferLogger
.
test
();
when
(
cache
.
dyLdLibEntry
).
thenReturn
(
const
MapEntry
<
String
,
String
>(
'foo'
,
'bar'
));
});
group
(
'DeviceManager'
,
()
{
...
...
@@ -550,5 +549,4 @@ class TestDeviceManager extends DeviceManager {
class
MockProcess
extends
Mock
implements
Process
{}
class
MockTerminal
extends
Mock
implements
AnsiTerminal
{}
class
MockStdio
extends
Mock
implements
Stdio
{}
class
MockCache
extends
Mock
implements
Cache
{}
class
MockDeviceDiscovery
extends
Mock
implements
DeviceDiscovery
{}
packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart
View file @
becaf491
...
...
@@ -827,9 +827,10 @@ void main() {
});
testUsingContext
(
'Correct flutter runner'
,
()
async
{
final
MockCache
cache
=
MockCache
();
final
Cache
cache
=
Cache
.
test
(
processManager:
FakeProcessManager
.
any
(),
);
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
when
(
cache
.
getArtifactDirectory
(
'flutter_runner'
)).
thenReturn
(
fileSystem
.
directory
(
'fuchsia'
));
final
CachedArtifacts
artifacts
=
CachedArtifacts
(
cache:
cache
,
fileSystem:
fileSystem
,
...
...
@@ -1591,4 +1592,3 @@ class MockFuchsiaSdk extends Mock implements FuchsiaSdk {
class
MockDartDevelopmentService
extends
Mock
implements
DartDevelopmentService
{}
class
MockFuchsiaWorkflow
extends
Mock
implements
FuchsiaWorkflow
{}
class
MockCache
extends
Mock
implements
Cache
{}
packages/flutter_tools/test/general.shard/ios/devices_test.dart
View file @
becaf491
...
...
@@ -37,7 +37,7 @@ void main() {
group
(
'IOSDevice'
,
()
{
final
List
<
Platform
>
unsupportedPlatforms
=
<
Platform
>[
linuxPlatform
,
windowsPlatform
];
Artifacts
mockArtifacts
;
MockCache
mockC
ache
;
Cache
c
ache
;
MockVmService
mockVmService
;
Logger
logger
;
IOSDeploy
iosDeploy
;
...
...
@@ -46,21 +46,19 @@ void main() {
setUp
(()
{
mockArtifacts
=
MockArtifacts
();
mockCache
=
MockCache
();
cache
=
Cache
.
test
();
mockVmService
=
MockVmService
();
const
MapEntry
<
String
,
String
>
dyLdLibEntry
=
MapEntry
<
String
,
String
>(
'DYLD_LIBRARY_PATH'
,
'/path/to/libs'
);
when
(
mockCache
.
dyLdLibEntry
).
thenReturn
(
dyLdLibEntry
);
logger
=
BufferLogger
.
test
();
iosDeploy
=
IOSDeploy
(
artifacts:
mockArtifacts
,
cache:
mockC
ache
,
cache:
c
ache
,
logger:
logger
,
platform:
macPlatform
,
processManager:
FakeProcessManager
.
any
(),
);
iMobileDevice
=
IMobileDevice
(
artifacts:
mockArtifacts
,
cache:
mockC
ache
,
cache:
c
ache
,
logger:
logger
,
processManager:
FakeProcessManager
.
any
(),
);
...
...
@@ -214,7 +212,7 @@ void main() {
IOSDevicePortForwarder
portForwarder
;
ForwardedPort
forwardedPort
;
Artifacts
mockArtifacts
;
MockCache
mockC
ache
;
Cache
c
ache
;
Logger
logger
;
IOSDeploy
iosDeploy
;
FileSystem
nullFileSystem
;
...
...
@@ -262,10 +260,10 @@ void main() {
mockProcess3
=
MockProcess
();
forwardedPort
=
ForwardedPort
.
withContext
(
123
,
456
,
mockProcess3
);
mockArtifacts
=
MockArtifacts
();
mockCache
=
MockCache
();
cache
=
Cache
.
test
();
iosDeploy
=
IOSDeploy
(
artifacts:
mockArtifacts
,
cache:
mockC
ache
,
cache:
c
ache
,
logger:
logger
,
platform:
macPlatform
,
processManager:
FakeProcessManager
.
any
(),
...
...
@@ -306,7 +304,7 @@ void main() {
group
(
'polling'
,
()
{
MockXcdevice
mockXcdevice
;
MockArtifacts
mockArtifacts
;
MockCache
mockC
ache
;
Cache
c
ache
;
MockVmService
mockVmService1
;
MockVmService
mockVmService2
;
FakeProcessManager
fakeProcessManager
;
...
...
@@ -320,7 +318,7 @@ void main() {
setUp
(()
{
mockXcdevice
=
MockXcdevice
();
mockArtifacts
=
MockArtifacts
();
mockCache
=
MockCache
();
cache
=
Cache
.
test
();
mockVmService1
=
MockVmService
();
mockVmService2
=
MockVmService
();
logger
=
BufferLogger
.
test
();
...
...
@@ -328,14 +326,14 @@ void main() {
fakeProcessManager
=
FakeProcessManager
.
any
();
iosDeploy
=
IOSDeploy
(
artifacts:
mockArtifacts
,
cache:
mockC
ache
,
cache:
c
ache
,
logger:
logger
,
platform:
macPlatform
,
processManager:
fakeProcessManager
,
);
iMobileDevice
=
IMobileDevice
(
artifacts:
mockArtifacts
,
cache:
mockC
ache
,
cache:
c
ache
,
processManager:
fakeProcessManager
,
logger:
logger
,
);
...
...
@@ -605,7 +603,6 @@ void main() {
class
MockIOSApp
extends
Mock
implements
IOSApp
{}
class
MockArtifacts
extends
Mock
implements
Artifacts
{}
class
MockCache
extends
Mock
implements
Cache
{}
class
MockIMobileDevice
extends
Mock
implements
IMobileDevice
{}
class
MockIOSDeploy
extends
Mock
implements
IOSDeploy
{}
class
MockIOSWorkflow
extends
Mock
implements
IOSWorkflow
{}
...
...
packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart
View file @
becaf491
...
...
@@ -9,16 +9,25 @@ import 'package:flutter_tools/src/artifacts.dart';
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/ios/devices.dart'
;
import
'package:flutter_tools/src/ios/ios_deploy.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/fakes.dart'
;
void
main
(
)
{
Artifacts
artifacts
;
String
iosDeployPath
;
setUp
(()
{
artifacts
=
Artifacts
.
test
();
iosDeployPath
=
artifacts
.
getArtifactPath
(
Artifact
.
iosDeploy
,
platform:
TargetPlatform
.
ios
);
});
testWithoutContext
(
'IOSDeploy.iosDeployEnv returns path with /usr/bin first'
,
()
{
final
IOSDeploy
iosDeploy
=
setUpIOSDeploy
(
FakeProcessManager
.
any
());
final
Map
<
String
,
String
>
environment
=
iosDeploy
.
iosDeployEnv
;
...
...
@@ -35,7 +44,7 @@ void main () {
'-t'
,
'0'
,
'/dev/null'
,
'ios-deploy'
,
iosDeployPath
,
'--id'
,
'123'
,
'--bundle'
,
...
...
@@ -47,12 +56,12 @@ void main () {
].
join
(
' '
),
],
environment:
const
<
String
,
String
>{
'PATH'
:
'/usr/bin:/usr/local/bin:/usr/bin'
,
'DYLD_LIBRARY_PATH'
:
'/path/to/libs'
,
'DYLD_LIBRARY_PATH'
:
'/path/to/lib
rarie
s'
,
},
stdout:
'(lldb) run
\n
success
\n
Did finish launching.'
,
),
]);
final
IOSDeploy
iosDeploy
=
setUpIOSDeploy
(
processManager
);
final
IOSDeploy
iosDeploy
=
setUpIOSDeploy
(
processManager
,
artifacts:
artifacts
);
final
IOSDeployDebugger
iosDeployDebugger
=
iosDeploy
.
prepareDebuggerForLaunch
(
deviceId:
'123'
,
bundlePath:
'/'
,
...
...
@@ -229,8 +238,8 @@ void main () {
const
String
deviceId
=
'123'
;
const
String
bundleId
=
'com.example.app'
;
final
FakeProcessManager
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[
const
FakeCommand
(
command:
<
String
>[
'ios-deploy'
,
FakeCommand
(
command:
<
String
>[
iosDeployPath
,
'--id'
,
deviceId
,
'--uninstall_only'
,
...
...
@@ -238,7 +247,7 @@ void main () {
bundleId
,
])
]);
final
IOSDeploy
iosDeploy
=
setUpIOSDeploy
(
processManager
);
final
IOSDeploy
iosDeploy
=
setUpIOSDeploy
(
processManager
,
artifacts:
artifacts
);
final
int
exitCode
=
await
iosDeploy
.
uninstallApp
(
deviceId:
deviceId
,
bundleId:
bundleId
,
...
...
@@ -252,8 +261,8 @@ void main () {
const
String
deviceId
=
'123'
;
const
String
bundleId
=
'com.example.app'
;
final
FakeProcessManager
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[
const
FakeCommand
(
command:
<
String
>[
'ios-deploy'
,
FakeCommand
(
command:
<
String
>[
iosDeployPath
,
'--id'
,
deviceId
,
'--uninstall_only'
,
...
...
@@ -261,7 +270,7 @@ void main () {
bundleId
,
],
exitCode:
1
)
]);
final
IOSDeploy
iosDeploy
=
setUpIOSDeploy
(
processManager
);
final
IOSDeploy
iosDeploy
=
setUpIOSDeploy
(
processManager
,
artifacts:
artifacts
);
final
int
exitCode
=
await
iosDeploy
.
uninstallApp
(
deviceId:
deviceId
,
bundleId:
bundleId
,
...
...
@@ -273,30 +282,27 @@ void main () {
});
}
IOSDeploy
setUpIOSDeploy
(
ProcessManager
processManager
)
{
const
MapEntry
<
String
,
String
>
kDyLdLibEntry
=
MapEntry
<
String
,
String
>(
'DYLD_LIBRARY_PATH'
,
'/path/to/libs'
,
);
IOSDeploy
setUpIOSDeploy
(
ProcessManager
processManager
,
{
Artifacts
artifacts
,
})
{
final
FakePlatform
macPlatform
=
FakePlatform
(
operatingSystem:
'macos'
,
environment:
<
String
,
String
>{
'PATH'
:
'/usr/local/bin:/usr/bin'
}
);
final
MockArtifacts
artifacts
=
MockArtifacts
();
final
MockCache
cache
=
MockCache
();
final
Cache
cache
=
Cache
.
test
(
platform:
macPlatform
,
artifacts:
<
ArtifactSet
>[
FakeDyldEnvironmentArtifact
(),
],
);
when
(
cache
.
dyLdLibEntry
).
thenReturn
(
kDyLdLibEntry
);
when
(
artifacts
.
getArtifactPath
(
Artifact
.
iosDeploy
,
platform:
anyNamed
(
'platform'
)))
.
thenReturn
(
'ios-deploy'
);
return
IOSDeploy
(
logger:
BufferLogger
.
test
(),
platform:
macPlatform
,
processManager:
processManager
,
artifacts:
artifacts
,
artifacts:
artifacts
??
Artifacts
.
test
()
,
cache:
cache
,
);
}
class
MockArtifacts
extends
Mock
implements
Artifacts
{}
class
MockCache
extends
Mock
implements
Cache
{}
packages/flutter_tools/test/general.shard/ios/ios_device_install_test.dart
View file @
becaf491
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart
View file @
becaf491
...
...
@@ -25,6 +25,7 @@ import 'package:vm_service/vm_service.dart';
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/fake_process_manager.dart'
;
import
'../../src/fakes.dart'
;
List
<
String
>
_xattrArgs
(
FlutterProject
flutterProject
)
{
return
<
String
>[
...
...
@@ -68,6 +69,14 @@ final FakePlatform macPlatform = FakePlatform(
);
void
main
(
)
{
Artifacts
artifacts
;
String
iosDeployPath
;
setUp
(()
{
artifacts
=
Artifacts
.
test
();
iosDeployPath
=
artifacts
.
getArtifactPath
(
Artifact
.
iosDeploy
,
platform:
TargetPlatform
.
ios
);
});
group
(
'IOSDevice.startApp succeeds in release mode'
,
()
{
FileSystem
fileSystem
;
FakeProcessManager
processManager
;
...
...
@@ -104,6 +113,7 @@ void main() {
fileSystem:
fileSystem
,
processManager:
processManager
,
logger:
logger
,
artifacts:
artifacts
,
);
setUpIOSProject
(
fileSystem
);
final
FlutterProject
flutterProject
=
FlutterProject
.
fromDirectory
(
fileSystem
.
currentDirectory
);
...
...
@@ -114,7 +124,7 @@ void main() {
processManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[...
kRunReleaseArgs
,
'-showBuildSettings'
]));
processManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
'ios-deploy'
,
iosDeployPath
,
'--id'
,
'123'
,
'--bundle'
,
...
...
@@ -155,6 +165,7 @@ void main() {
fileSystem:
fileSystem
,
processManager:
processManager
,
logger:
logger
,
artifacts:
artifacts
,
);
setUpIOSProject
(
fileSystem
);
final
FlutterProject
flutterProject
=
FlutterProject
.
fromDirectory
(
fileSystem
.
currentDirectory
);
...
...
@@ -176,7 +187,7 @@ void main() {
));
processManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
'ios-deploy'
,
iosDeployPath
,
'--id'
,
'123'
,
'--bundle'
,
...
...
@@ -228,6 +239,7 @@ void main() {
fileSystem:
fileSystem
,
processManager:
processManager
,
logger:
logger
,
artifacts:
artifacts
,
);
setUpIOSProject
(
fileSystem
);
final
FlutterProject
flutterProject
=
FlutterProject
.
fromDirectory
(
fileSystem
.
currentDirectory
);
...
...
@@ -250,7 +262,7 @@ void main() {
));
processManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
'ios-deploy'
,
iosDeployPath
,
'--id'
,
'123'
,
'--bundle'
,
...
...
@@ -306,17 +318,16 @@ IOSDevice setUpIOSDevice({
FileSystem
fileSystem
,
Logger
logger
,
ProcessManager
processManager
,
Artifacts
artifacts
,
})
{
const
MapEntry
<
String
,
String
>
dyldLibraryEntry
=
MapEntry
<
String
,
String
>(
'DYLD_LIBRARY_PATH'
,
'/path/to/libraries'
,
artifacts
??=
Artifacts
.
test
();
final
Cache
cache
=
Cache
.
test
(
artifacts:
<
ArtifactSet
>[
FakeDyldEnvironmentArtifact
(),
],
);
final
MockCache
cache
=
MockCache
();
final
MockArtifacts
artifacts
=
MockArtifacts
();
logger
??=
BufferLogger
.
test
();
when
(
cache
.
dyLdLibEntry
).
thenReturn
(
dyldLibraryEntry
);
when
(
artifacts
.
getArtifactPath
(
Artifact
.
iosDeploy
,
platform:
anyNamed
(
'platform'
)))
.
thenReturn
(
'ios-deploy'
);
return
IOSDevice
(
'123'
,
name:
'iPhone 1'
,
sdkVersion:
sdkVersion
,
...
...
@@ -343,8 +354,6 @@ IOSDevice setUpIOSDevice({
);
}
class
MockArtifacts
extends
Mock
implements
Artifacts
{}
class
MockCache
extends
Mock
implements
Cache
{}
class
MockXcode
extends
Mock
implements
Xcode
{}
class
MockXcodeProjectInterpreter
extends
Mock
implements
XcodeProjectInterpreter
{}
class
MockVmService
extends
Mock
implements
VmService
{}
packages/flutter_tools/test/general.shard/ios/ios_device_start_prebuilt_test.dart
View file @
becaf491
...
...
@@ -32,7 +32,7 @@ import '../../src/fakes.dart';
const
FakeCommand
kDeployCommand
=
FakeCommand
(
command:
<
String
>[
'
ios-deploy
'
,
'
Artifact.iosDeploy.TargetPlatform.ios
'
,
'--id'
,
'123'
,
'--bundle'
,
...
...
@@ -48,7 +48,7 @@ const FakeCommand kDeployCommand = FakeCommand(
// The command used to actually launch the app with args in release/profile.
const
FakeCommand
kLaunchReleaseCommand
=
FakeCommand
(
command:
<
String
>[
'
ios-deploy
'
,
'
Artifact.iosDeploy.TargetPlatform.ios
'
,
'--id'
,
'123'
,
'--bundle'
,
...
...
@@ -67,7 +67,7 @@ const FakeCommand kLaunchReleaseCommand = FakeCommand(
// The command used to just launch the app with args in debug.
const
FakeCommand
kLaunchDebugCommand
=
FakeCommand
(
command:
<
String
>[
'
ios-deploy
'
,
'
Artifact.iosDeploy.TargetPlatform.ios
'
,
'--id'
,
'123'
,
'--bundle'
,
...
...
@@ -87,7 +87,7 @@ const FakeCommand kAttachDebuggerCommand = FakeCommand(command: <String>[
'-t'
,
'0'
,
'/dev/null'
,
'
ios-deploy
'
,
'
Artifact.iosDeploy.TargetPlatform.ios
'
,
'--id'
,
'123'
,
'--bundle'
,
...
...
@@ -382,7 +382,7 @@ void main() {
'-t'
,
'0'
,
'/dev/null'
,
'
ios-deploy
'
,
'
Artifact.iosDeploy.TargetPlatform.ios
'
,
'--id'
,
'123'
,
'--bundle'
,
...
...
@@ -482,20 +482,20 @@ IOSDevice setUpIOSDevice({
ProcessManager
processManager
,
VmServiceConnector
vmServiceConnector
,
})
{
const
MapEntry
<
String
,
String
>
dyldLibraryEntry
=
MapEntry
<
String
,
String
>(
'DYLD_LIBRARY_PATH'
,
'/path/to/libraries'
,
);
final
MockCache
cache
=
MockCache
();
final
MockArtifacts
artifacts
=
MockArtifacts
();
final
Artifacts
artifacts
=
Artifacts
.
test
();
final
FakePlatform
macPlatform
=
FakePlatform
(
operatingSystem:
'macos'
,
environment:
<
String
,
String
>{},
);
final
Cache
cache
=
Cache
.
test
(
platform:
macPlatform
,
artifacts:
<
ArtifactSet
>[
FakeDyldEnvironmentArtifact
(),
],
);
vmServiceConnector
??=
(
String
uri
,
{
Log
log
})
async
=>
MockVmService
();
when
(
cache
.
dyLdLibEntry
).
thenReturn
(
dyldLibraryEntry
);
when
(
artifacts
.
getArtifactPath
(
Artifact
.
iosDeploy
,
platform:
anyNamed
(
'platform'
)))
.
thenReturn
(
'ios-deploy'
);
return
IOSDevice
(
'123'
,
name:
'iPhone 1'
,
sdkVersion:
sdkVersion
,
...
...
@@ -526,7 +526,5 @@ class MockDevicePortForwarder extends Mock implements DevicePortForwarder {}
class
MockDeviceLogReader
extends
Mock
implements
DeviceLogReader
{}
class
MockUsage
extends
Mock
implements
Usage
{}
class
MockMDnsObservatoryDiscovery
extends
Mock
implements
MDnsObservatoryDiscovery
{}
class
MockArtifacts
extends
Mock
implements
Artifacts
{}
class
MockCache
extends
Mock
implements
Cache
{}
class
MockVmService
extends
Mock
implements
VmService
{}
class
MockDartDevelopmentService
extends
Mock
implements
DartDevelopmentService
{}
packages/flutter_tools/test/general.shard/ios/mac_test.dart
View file @
becaf491
...
...
@@ -11,7 +11,6 @@ import 'package:flutter_tools/src/base/logger.dart';
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/base/process.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'package:flutter_tools/src/ios/devices.dart'
;
import
'package:flutter_tools/src/ios/mac.dart'
;
import
'package:flutter_tools/src/ios/xcodeproj.dart'
;
...
...
@@ -22,14 +21,13 @@ import 'package:process/process.dart';
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/fakes.dart'
;
final
Generator
_kNoColorTerminalPlatform
=
()
=>
FakePlatform
(
stdoutSupportsAnsi:
false
);
final
Map
<
Type
,
Generator
>
noColorTerminalOverride
=
<
Type
,
Generator
>{
Platform:
_kNoColorTerminalPlatform
,
};
class
MockArtifacts
extends
Mock
implements
Artifacts
{}
class
MockCache
extends
Mock
implements
Cache
{}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
MockXcodeProjectInterpreter
extends
Mock
implements
XcodeProjectInterpreter
{}
class
MockIosProject
extends
Mock
implements
IosProject
{}
...
...
@@ -42,18 +40,15 @@ void main() {
});
group
(
'IMobileDevice'
,
()
{
final
String
libimobiledevicePath
=
globals
.
fs
.
path
.
join
(
'bin'
,
'cache'
,
'artifacts'
,
'libimobiledevice'
);
final
String
idevicescreenshotPath
=
globals
.
fs
.
path
.
join
(
libimobiledevicePath
,
'idevicescreenshot'
);
MockArtifacts
mockArtifacts
;
MockCache
mockCache
;
Artifacts
artifacts
;
Cache
cache
;
setUp
(()
{
mockCache
=
MockCache
();
mockArtifacts
=
MockArtifacts
();
when
(
mockArtifacts
.
getArtifactPath
(
Artifact
.
idevicescreenshot
,
platform:
anyNamed
(
'platform'
))).
thenReturn
(
idevicescreenshotPath
);
when
(
mockCache
.
dyLdLibEntry
).
thenReturn
(
MapEntry
<
String
,
String
>(
'DYLD_LIBRARY_PATH'
,
libimobiledevicePath
)
);
artifacts
=
Artifacts
.
test
();
cache
=
Cache
.
test
(
artifacts:
<
ArtifactSet
>[
FakeDyldEnvironmentArtifact
(),
]);
});
group
(
'screenshot'
,
()
{
...
...
@@ -63,19 +58,19 @@ void main() {
setUp
(()
{
mockProcessManager
=
MockProcessManager
();
outputFile
=
MemoryFileSystem
.
test
().
file
(
'image.png'
);
when
(
mockArtifacts
.
getArtifactPath
(
Artifact
.
idevicescreenshot
,
platform:
anyNamed
(
'platform'
))).
thenReturn
(
idevicescreenshotPath
);
//
when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath);
});
testWithoutContext
(
'error if idevicescreenshot is not installed'
,
()
async
{
// Let `idevicescreenshot` fail with exit code 1.
when
(
mockProcessManager
.
run
(<
String
>[
idevicescreenshotPath
,
outputFile
.
path
],
environment:
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
libimobiledevicePath
},
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
,
''
,
''
)));
final
IMobileDevice
iMobileDevice
=
IMobileDevice
(
artifacts:
mockA
rtifacts
,
cache:
mockC
ache
,
artifacts:
a
rtifacts
,
cache:
c
ache
,
processManager:
mockProcessManager
,
logger:
logger
,
);
...
...
@@ -92,8 +87,8 @@ void main() {
(
Invocation
invocation
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
4
,
0
,
''
,
''
)));
final
IMobileDevice
iMobileDevice
=
IMobileDevice
(
artifacts:
mockA
rtifacts
,
cache:
mockC
ache
,
artifacts:
a
rtifacts
,
cache:
c
ache
,
processManager:
mockProcessManager
,
logger:
logger
,
);
...
...
@@ -103,8 +98,8 @@ void main() {
'1234'
,
IOSDeviceInterface
.
usb
,
);
verify
(
mockProcessManager
.
run
(<
String
>[
idevicescreenshotPath
,
outputFile
.
path
,
'--udid'
,
'1234'
],
environment:
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
libimobiledevicePath
},
verify
(
mockProcessManager
.
run
(<
String
>[
'Artifact.idevicescreenshot.TargetPlatform.ios'
,
outputFile
.
path
,
'--udid'
,
'1234'
],
environment:
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
'/path/to/libraries'
},
workingDirectory:
null
,
));
});
...
...
@@ -114,8 +109,8 @@ void main() {
(
Invocation
invocation
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
4
,
0
,
''
,
''
)));
final
IMobileDevice
iMobileDevice
=
IMobileDevice
(
artifacts:
mockA
rtifacts
,
cache:
mockC
ache
,
artifacts:
a
rtifacts
,
cache:
c
ache
,
processManager:
mockProcessManager
,
logger:
logger
,
);
...
...
@@ -125,8 +120,8 @@ void main() {
'1234'
,
IOSDeviceInterface
.
network
,
);
verify
(
mockProcessManager
.
run
(<
String
>[
idevicescreenshotPath
,
outputFile
.
path
,
'--udid'
,
'1234'
,
'--network'
],
environment:
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
libimobiledevicePath
},
verify
(
mockProcessManager
.
run
(<
String
>[
'Artifact.idevicescreenshot.TargetPlatform.ios'
,
outputFile
.
path
,
'--udid'
,
'1234'
,
'--network'
],
environment:
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
'/path/to/libraries'
},
workingDirectory:
null
,
));
});
...
...
packages/flutter_tools/test/general.shard/macos/xcode_test.dart
View file @
becaf491
...
...
@@ -79,8 +79,8 @@ void main() {
logger:
logger
,
xcode:
mockXcode
,
platform:
null
,
artifacts:
MockArtifacts
(),
cache:
MockCache
(),
artifacts:
Artifacts
.
test
(),
cache:
Cache
.
test
(),
iproxy:
IProxy
.
test
(
logger:
logger
,
processManager:
processManager
),
);
});
...
...
@@ -338,20 +338,16 @@ void main() {
group
(
'xcdevice'
,
()
{
XCDevice
xcdevice
;
MockXcode
mockXcode
;
MockArtifacts
mockArtifacts
;
MockCache
mockCache
;
setUp
(()
{
mockXcode
=
MockXcode
();
mockArtifacts
=
MockArtifacts
();
mockCache
=
MockCache
();
xcdevice
=
XCDevice
(
processManager:
fakeProcessManager
,
logger:
logger
,
xcode:
mockXcode
,
platform:
null
,
artifacts:
mockArtifacts
,
cache:
mockCache
,
artifacts:
Artifacts
.
test
()
,
cache:
Cache
.
test
()
,
iproxy:
IProxy
.
test
(
logger:
logger
,
processManager:
fakeProcessManager
),
);
});
...
...
@@ -843,5 +839,3 @@ class MockXcode extends Mock implements Xcode {}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
MockXcodeProjectInterpreter
extends
Mock
implements
XcodeProjectInterpreter
{}
class
MockPlatform
extends
Mock
implements
Platform
{}
class
MockArtifacts
extends
Mock
implements
Artifacts
{}
class
MockCache
extends
Mock
implements
Cache
{}
packages/flutter_tools/test/src/fakes.dart
View file @
becaf491
...
...
@@ -4,6 +4,7 @@
import
'dart:async'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/device.dart'
;
/// A fake implementation of the [DeviceLogReader].
...
...
@@ -40,3 +41,22 @@ class FakeDeviceLogReader extends DeviceLogReader {
await
_linesController
.
close
();
}
}
/// Environment with DYLD_LIBRARY_PATH=/path/to/libraries
class
FakeDyldEnvironmentArtifact
extends
ArtifactSet
{
FakeDyldEnvironmentArtifact
()
:
super
(
DevelopmentArtifact
.
iOS
);
@override
Map
<
String
,
String
>
get
environment
=>
<
String
,
String
>{
'DYLD_LIBRARY_PATH'
:
'/path/to/libraries'
};
@override
Future
<
bool
>
isUpToDate
()
=>
Future
<
bool
>.
value
(
true
);
@override
String
get
name
=>
'fake'
;
@override
Future
<
void
>
update
(
ArtifactUpdater
artifactUpdater
)
async
{
}
}
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