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
1eaa8c30
Unverified
Commit
1eaa8c30
authored
May 13, 2020
by
Jenn Magder
Committed by
GitHub
May 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Swap xcode_tests from MockProcessManager to FakeProcessManager (#56502)
parent
1aaf73fa
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
405 additions
and
306 deletions
+405
-306
xcode_test.dart
...es/flutter_tools/test/general.shard/macos/xcode_test.dart
+405
-306
No files found.
packages/flutter_tools/test/general.shard/macos/xcode_test.dart
View file @
1eaa8c30
...
...
@@ -4,7 +4,6 @@
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
ProcessException
,
ProcessResult
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
...
...
@@ -20,30 +19,31 @@ import '../../src/common.dart';
import
'../../src/context.dart'
;
void
main
(
)
{
ProcessManager
processManager
;
Logger
logger
;
setUp
(()
{
logger
=
BufferLogger
.
test
();
});
// Group exists to work around https://github.com/flutter/flutter/issues/56415.
// Do not add more `MockProcessManager` tests.
group
(
'MockProcessManager'
,
()
{
ProcessManager
processManager
;
setUp
(()
{
processManager
=
MockProcessManager
();
});
group
(
'Xcode'
,
()
{
Xcode
xcode
;
MockXcodeProjectInterpreter
mockXcodeProjectInterpreter
;
MockPlatform
platform
;
FileSystem
fileSystem
;
setUp
(()
{
fileSystem
=
MemoryFileSystem
();
mockXcodeProjectInterpreter
=
MockXcodeProjectInterpreter
();
platform
=
MockPlatform
();
xcode
=
Xcode
(
logger:
logger
,
platform:
platform
,
fileSystem:
fileSystem
,
platform:
MockPlatform
()
,
fileSystem:
MemoryFileSystem
.
test
()
,
processManager:
processManager
,
xcodeProjectInterpreter:
mockXcodeProjectInterpreter
,
xcodeProjectInterpreter:
MockXcodeProjectInterpreter
()
,
);
});
...
...
@@ -57,12 +57,98 @@ void main() {
expect
(
xcode
.
xcodeSelectPath
,
isNull
);
});
testWithoutContext
(
'eulaSigned is false when clang is not installed'
,
()
{
when
(
processManager
.
runSync
(<
String
>[
'/usr/bin/xcrun'
,
'clang'
]))
.
thenThrow
(
const
ProcessException
(
'/usr/bin/xcrun'
,
<
String
>[
'clang'
]));
expect
(
xcode
.
eulaSigned
,
isFalse
);
});
});
group
(
'xcdevice'
,
()
{
XCDevice
xcdevice
;
MockXcode
mockXcode
;
setUp
(()
{
mockXcode
=
MockXcode
();
xcdevice
=
XCDevice
(
processManager:
processManager
,
logger:
logger
,
xcode:
mockXcode
,
platform:
null
,
artifacts:
MockArtifacts
(),
cache:
MockCache
(),
);
});
testWithoutContext
(
"xcrun can't find xcdevice"
,
()
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenThrow
(
const
ProcessException
(
'xcrun'
,
<
String
>[
'--find'
,
'xcdevice'
]));
expect
(
xcdevice
.
isInstalled
,
false
);
verify
(
processManager
.
runSync
(
any
)).
called
(
1
);
});
testWithoutContext
(
'available devices xcdevice fails'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]))
.
thenThrow
(
const
ProcessException
(
'xcrun'
,
<
String
>[
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]));
expect
(
await
xcdevice
.
getAvailableTetheredIOSDevices
(),
isEmpty
);
});
testWithoutContext
(
'diagnostics xcdevice fails'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]))
.
thenThrow
(
const
ProcessException
(
'xcrun'
,
<
String
>[
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]));
expect
(
await
xcdevice
.
getDiagnostics
(),
isEmpty
);
});
});
});
group
(
'FakeProcessManager'
,
()
{
FakeProcessManager
fakeProcessManager
;
setUp
(()
{
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]);
});
group
(
'Xcode'
,
()
{
Xcode
xcode
;
MockXcodeProjectInterpreter
mockXcodeProjectInterpreter
;
MockPlatform
platform
;
setUp
(()
{
mockXcodeProjectInterpreter
=
MockXcodeProjectInterpreter
();
platform
=
MockPlatform
();
xcode
=
Xcode
(
logger:
logger
,
platform:
platform
,
fileSystem:
MemoryFileSystem
.
test
(),
processManager:
fakeProcessManager
,
xcodeProjectInterpreter:
mockXcodeProjectInterpreter
,
);
});
testWithoutContext
(
'xcodeSelectPath returns path when xcode-select is installed'
,
()
{
const
String
xcodePath
=
'/Applications/Xcode8.0.app/Contents/Developer'
;
when
(
processManager
.
runSync
(<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
xcodePath
,
''
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
],
stdout:
xcodePath
,
));
expect
(
xcode
.
xcodeSelectPath
,
xcodePath
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'xcodeVersionSatisfactory is false when version is less than minimum'
,
()
{
...
...
@@ -111,68 +197,79 @@ void main() {
testWithoutContext
(
'isInstalledAndMeetsVersionCheck is false when not installed'
,
()
{
when
(
platform
.
isMacOS
).
thenReturn
(
true
);
const
String
xcodePath
=
'/Applications/Xcode8.0.app/Contents/Developer'
;
when
(
processManager
.
runSync
(<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
xcodePath
,
''
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
],
stdout:
'/Applications/Xcode8.0.app/Contents/Developer'
,
));
when
(
mockXcodeProjectInterpreter
.
isInstalled
).
thenReturn
(
false
);
expect
(
xcode
.
isInstalledAndMeetsVersionCheck
,
isFalse
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'isInstalledAndMeetsVersionCheck is false when no xcode-select'
,
()
{
when
(
platform
.
isMacOS
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
]))
.
thenReturn
(
ProcessResult
(
1
,
127
,
''
,
'ERROR'
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
],
exitCode:
127
,
stderr:
'ERROR'
,
));
when
(
mockXcodeProjectInterpreter
.
isInstalled
).
thenReturn
(
true
);
when
(
mockXcodeProjectInterpreter
.
majorVersion
).
thenReturn
(
11
);
when
(
mockXcodeProjectInterpreter
.
minorVersion
).
thenReturn
(
0
);
expect
(
xcode
.
isInstalledAndMeetsVersionCheck
,
isFalse
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'isInstalledAndMeetsVersionCheck is false when version not satisfied'
,
()
{
when
(
platform
.
isMacOS
).
thenReturn
(
true
);
const
String
xcodePath
=
'/Applications/Xcode8.0.app/Contents/Developer'
;
when
(
processManager
.
runSync
(<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
xcodePath
,
''
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
],
stdout:
'/Applications/Xcode8.0.app/Contents/Developer'
,
));
when
(
mockXcodeProjectInterpreter
.
isInstalled
).
thenReturn
(
true
);
when
(
mockXcodeProjectInterpreter
.
majorVersion
).
thenReturn
(
10
);
when
(
mockXcodeProjectInterpreter
.
minorVersion
).
thenReturn
(
2
);
expect
(
xcode
.
isInstalledAndMeetsVersionCheck
,
isFalse
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'isInstalledAndMeetsVersionCheck is true when macOS and installed and version is satisfied'
,
()
{
when
(
platform
.
isMacOS
).
thenReturn
(
true
);
const
String
xcodePath
=
'/Applications/Xcode8.0.app/Contents/Developer'
;
when
(
processManager
.
runSync
(<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
xcodePath
,
''
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
],
stdout:
'/Applications/Xcode8.0.app/Contents/Developer'
,
));
when
(
mockXcodeProjectInterpreter
.
isInstalled
).
thenReturn
(
true
);
when
(
mockXcodeProjectInterpreter
.
majorVersion
).
thenReturn
(
11
);
when
(
mockXcodeProjectInterpreter
.
minorVersion
).
thenReturn
(
0
);
expect
(
xcode
.
isInstalledAndMeetsVersionCheck
,
isTrue
);
});
testWithoutContext
(
'eulaSigned is false when clang is not installed'
,
()
{
when
(
processManager
.
runSync
(<
String
>[
'/usr/bin/xcrun'
,
'clang'
]))
.
thenThrow
(
const
ProcessException
(
'/usr/bin/xcrun'
,
<
String
>[
'clang'
]));
expect
(
xcode
.
eulaSigned
,
isFalse
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'eulaSigned is false when clang output indicates EULA not yet accepted'
,
()
{
when
(
processManager
.
runSync
(<
String
>[
'/usr/bin/xcrun'
,
'clang'
]))
.
thenReturn
(
ProcessResult
(
1
,
1
,
''
,
'Xcode EULA has not been accepted.
\n
Launch Xcode and accept the license.'
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'/usr/bin/xcrun'
,
'clang'
],
exitCode:
1
,
stderr:
'Xcode EULA has not been accepted.
\n
Launch Xcode and accept the license.'
,
));
expect
(
xcode
.
eulaSigned
,
isFalse
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'eulaSigned is true when clang output indicates EULA has been accepted'
,
()
{
when
(
processManager
.
runSync
(<
String
>[
'/usr/bin/xcrun'
,
'clang'
]))
.
thenReturn
(
ProcessResult
(
1
,
1
,
''
,
'clang: error: no input files'
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'/usr/bin/xcrun'
,
'clang'
],
exitCode:
1
,
stderr:
'clang: error: no input files'
,
));
expect
(
xcode
.
eulaSigned
,
isTrue
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'SDK name'
,
()
{
...
...
@@ -185,25 +282,35 @@ void main() {
const
String
sdkroot
=
'Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk'
;
testWithoutContext
(
'--show-sdk-path iphoneos'
,
()
async
{
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'--sdk'
,
'iphoneos'
,
'--show-sdk-path'
])).
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
1
,
0
,
sdkroot
,
''
)));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'--sdk'
,
'iphoneos'
,
'--show-sdk-path'
],
stdout:
sdkroot
,
));
expect
(
await
xcode
.
sdkLocation
(
SdkType
.
iPhone
),
sdkroot
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'--show-sdk-path macosx'
,
()
async
{
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'--sdk'
,
'macosx'
,
'--show-sdk-path'
])).
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
1
,
0
,
sdkroot
,
''
)));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'--sdk'
,
'macosx'
,
'--show-sdk-path'
],
stdout:
sdkroot
,
));
expect
(
await
xcode
.
sdkLocation
(
SdkType
.
macOS
),
sdkroot
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testWithoutContext
(
'--show-sdk-path fails'
,
()
async
{
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'--sdk'
,
'iphoneos'
,
'--show-sdk-path'
])).
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
1
,
1
,
''
,
'xcrun: error:'
)));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'--sdk'
,
'iphoneos'
,
'--show-sdk-path'
],
exitCode:
1
,
stderr:
'xcrun: error:'
,
));
expect
(()
async
=>
await
xcode
.
sdkLocation
(
SdkType
.
iPhone
),
throwsToolExit
(
message:
'Could not find SDK location'
));
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
});
});
...
...
@@ -219,7 +326,7 @@ void main() {
mockArtifacts
=
MockArtifacts
();
mockCache
=
MockCache
();
xcdevice
=
XCDevice
(
processManager:
p
rocessManager
,
processManager:
fakeP
rocessManager
,
logger:
logger
,
xcode:
mockXcode
,
platform:
null
,
...
...
@@ -234,21 +341,15 @@ void main() {
expect
(
xcdevice
.
isInstalled
,
false
);
});
testWithoutContext
(
"xcrun can't find xcdevice"
,
()
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenThrow
(
const
ProcessException
(
'xcrun'
,
<
String
>[
'--find'
,
'xcdevice'
]));
expect
(
xcdevice
.
isInstalled
,
false
);
verify
(
processManager
.
runSync
(
any
)).
called
(
1
);
});
testWithoutContext
(
'is installed'
,
()
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
],
stdout:
'/path/to/xcdevice'
,
));
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
expect
(
xcdevice
.
isInstalled
,
true
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
});
...
...
@@ -258,27 +359,15 @@ void main() {
testWithoutContext
(
'Xcode not installed'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
false
);
expect
(
await
xcdevice
.
getAvailableTetheredIOSDevices
(),
isEmpty
);
verifyNever
(
processManager
.
run
(
any
));
});
testWithoutContext
(
'xcdevice fails'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]))
.
thenThrow
(
const
ProcessException
(
'xcrun'
,
<
String
>[
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]));
expect
(
await
xcdevice
.
getAvailableTetheredIOSDevices
(),
isEmpty
);
});
testUsingContext
(
'returns devices'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
],
stdout:
'/path/to/xcdevice'
,
));
const
String
devicesOutput
=
'''
[
...
...
@@ -373,8 +462,10 @@ void main() {
]
'''
;
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]))
.
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
1
,
0
,
devicesOutput
,
''
)));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
],
stdout:
devicesOutput
,
));
final
List
<
IOSDevice
>
devices
=
await
xcdevice
.
getAvailableTetheredIOSDevices
();
expect
(
devices
,
hasLength
(
3
));
expect
(
devices
[
0
].
id
,
'd83d5bc53967baa0ee18626ba87b6254b2ab5418'
);
...
...
@@ -389,27 +480,32 @@ void main() {
expect
(
devices
[
2
].
name
,
'iPad 2'
);
expect
(
await
devices
[
2
].
sdkNameAndVersion
,
'iOS 10.1'
);
expect
(
devices
[
2
].
cpuArchitecture
,
DarwinArch
.
arm64
);
// Defaults to arm64 for unknown architecture.
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
macPlatform
,
});
testWithoutContext
(
'uses timeout'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
when
(
processManager
.
run
(
any
))
.
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
1
,
0
,
'[]'
,
''
)));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
],
stdout:
'/path/to/xcdevice'
,
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'20'
],
stdout:
'[]'
,
));
await
xcdevice
.
getAvailableTetheredIOSDevices
(
timeout:
const
Duration
(
seconds:
20
));
verify
(
processManager
.
run
(<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'20'
])).
called
(
1
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
});
testUsingContext
(
'ignores "Preparing debugger support for iPhone" error'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
],
stdout:
'/path/to/xcdevice'
,
));
const
String
devicesOutput
=
'''
[
...
...
@@ -435,20 +531,24 @@ void main() {
]
'''
;
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]))
.
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
1
,
0
,
devicesOutput
,
''
)));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
],
stdout:
devicesOutput
,
));
final
List
<
IOSDevice
>
devices
=
await
xcdevice
.
getAvailableTetheredIOSDevices
();
expect
(
devices
,
hasLength
(
1
));
expect
(
devices
[
0
].
id
,
'43ad2fda7991b34fe1acbda82f9e2fd3d6ddc9f7'
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
macPlatform
,
});
testUsingContext
(
'handles unknown architectures'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
],
stdout:
'/path/to/xcdevice'
,
));
const
String
devicesOutput
=
'''
[
...
...
@@ -479,11 +579,14 @@ void main() {
]
'''
;
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]))
.
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
1
,
0
,
devicesOutput
,
''
)));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
],
stdout:
devicesOutput
,
));
final
List
<
IOSDevice
>
devices
=
await
xcdevice
.
getAvailableTetheredIOSDevices
();
expect
(
devices
[
0
].
cpuArchitecture
,
DarwinArch
.
armv7
);
expect
(
devices
[
1
].
cpuArchitecture
,
DarwinArch
.
arm64
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
macPlatform
,
});
...
...
@@ -495,27 +598,15 @@ void main() {
testWithoutContext
(
'Xcode not installed'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
false
);
expect
(
await
xcdevice
.
getDiagnostics
(),
isEmpty
);
verifyNever
(
processManager
.
run
(
any
));
});
testWithoutContext
(
'xcdevice fails'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]))
.
thenThrow
(
const
ProcessException
(
'xcrun'
,
<
String
>[
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]));
expect
(
await
xcdevice
.
getDiagnostics
(),
isEmpty
);
});
testUsingContext
(
'uses cache'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
],
stdout:
'/path/to/xcdevice'
,
));
const
String
devicesOutput
=
'''
[
...
...
@@ -538,22 +629,25 @@ void main() {
]
'''
;
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]))
.
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
1
,
0
,
devicesOutput
,
''
)));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
],
stdout:
devicesOutput
,
));
await
xcdevice
.
getAvailableTetheredIOSDevices
();
final
List
<
String
>
errors
=
await
xcdevice
.
getDiagnostics
();
expect
(
errors
,
hasLength
(
1
));
verify
(
processManager
.
run
(
any
)).
called
(
1
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
macPlatform
,
});
testUsingContext
(
'returns error message'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
when
(
processManager
.
runSync
(<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
]))
.
thenReturn
(
ProcessResult
(
1
,
0
,
'/path/to/xcdevice'
,
''
));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'--find'
,
'xcdevice'
],
stdout:
'/path/to/xcdevice'
,
));
const
String
devicesOutput
=
'''
[
...
...
@@ -640,19 +734,24 @@ void main() {
]
'''
;
when
(
processManager
.
run
(<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
]))
.
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
1
,
0
,
devicesOutput
,
''
)));
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'xcrun'
,
'xcdevice'
,
'list'
,
'--timeout'
,
'2'
],
stdout:
devicesOutput
,
));
final
List
<
String
>
errors
=
await
xcdevice
.
getDiagnostics
();
expect
(
errors
,
hasLength
(
4
));
expect
(
errors
[
0
],
'Error: iPhone is not paired with your computer. To use iPhone with Xcode, unlock it and choose to trust this computer when prompted. (code -9)'
);
expect
(
errors
[
1
],
'Error: iPhone is not paired with your computer.'
);
expect
(
errors
[
2
],
'Error: Xcode pairing error. (code -13)'
);
expect
(
errors
[
3
],
'Error: iPhone is busy: Preparing debugger support for iPhone. Xcode will continue when iPhone is finished. (code -10)'
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
macPlatform
,
});
});
});
});
}
class
MockXcode
extends
Mock
implements
Xcode
{}
...
...
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