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
21858253
Unverified
Commit
21858253
authored
Aug 10, 2019
by
Jonah Williams
Committed by
GitHub
Aug 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch FormatException caused by bad simctl output (#37958)
parent
78cca625
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
16 deletions
+37
-16
simulators.dart
packages/flutter_tools/lib/src/ios/simulators.dart
+19
-10
simulators_test.dart
...flutter_tools/test/general.shard/ios/simulators_test.dart
+16
-4
context.dart
packages/flutter_tools/test/src/context.dart
+2
-2
No files found.
packages/flutter_tools/lib/src/ios/simulators.dart
View file @
21858253
...
...
@@ -46,11 +46,12 @@ class IOSSimulatorUtils {
/// Returns [IOSSimulatorUtils] active in the current app context (i.e. zone).
static
IOSSimulatorUtils
get
instance
=>
context
.
get
<
IOSSimulatorUtils
>();
List
<
IOSSimulator
>
getAttachedDevices
()
{
Future
<
List
<
IOSSimulator
>>
getAttachedDevices
()
async
{
if
(!
xcode
.
isInstalledAndMeetsVersionCheck
)
return
<
IOSSimulator
>[];
return
SimControl
.
instance
.
getConnectedDevices
().
map
<
IOSSimulator
>((
SimDevice
device
)
{
final
List
<
SimDevice
>
connected
=
await
SimControl
.
instance
.
getConnectedDevices
();
return
connected
.
map
<
IOSSimulator
>((
SimDevice
device
)
{
return
IOSSimulator
(
device
.
udid
,
name:
device
.
name
,
simulatorCategory:
device
.
category
);
}).
toList
();
}
...
...
@@ -63,7 +64,7 @@ class SimControl {
/// Runs `simctl list --json` and returns the JSON of the corresponding
/// [section].
Map
<
String
,
dynamic
>
_list
(
SimControlListSection
section
)
{
Future
<
Map
<
String
,
dynamic
>>
_list
(
SimControlListSection
section
)
async
{
// Sample output from `simctl list --json`:
//
// {
...
...
@@ -83,20 +84,27 @@ class SimControl {
final
List
<
String
>
command
=
<
String
>[
_xcrunPath
,
'simctl'
,
'list'
,
'--json'
,
section
.
name
];
printTrace
(
command
.
join
(
' '
));
final
ProcessResult
results
=
processManager
.
runSync
(
command
);
final
ProcessResult
results
=
await
processManager
.
run
(
command
);
if
(
results
.
exitCode
!=
0
)
{
printError
(
'Error executing simctl:
${results.exitCode}
\n
${results.stderr}
'
);
return
<
String
,
Map
<
String
,
dynamic
>>{};
}
return
json
.
decode
(
results
.
stdout
)[
section
.
name
];
try
{
return
json
.
decode
(
results
.
stdout
)[
section
.
name
];
}
on
FormatException
{
// We failed to parse the simctl output, or it returned junk.
// One known message is "Install Started" isn't valid JSON but is
// returned sometimes.
printError
(
'simctl returned non-JSON response:
${results.stdout}
'
);
return
<
String
,
dynamic
>{};
}
}
/// Returns a list of all available devices, both potential and connected.
List
<
SimDevice
>
getDevices
()
{
Future
<
List
<
SimDevice
>>
getDevices
()
async
{
final
List
<
SimDevice
>
devices
=
<
SimDevice
>[];
final
Map
<
String
,
dynamic
>
devicesSection
=
_list
(
SimControlListSection
.
devices
);
final
Map
<
String
,
dynamic
>
devicesSection
=
await
_list
(
SimControlListSection
.
devices
);
for
(
String
deviceCategory
in
devicesSection
.
keys
)
{
final
List
<
dynamic
>
devicesData
=
devicesSection
[
deviceCategory
];
...
...
@@ -109,8 +117,9 @@ class SimControl {
}
/// Returns all the connected simulator devices.
List
<
SimDevice
>
getConnectedDevices
()
{
return
getDevices
().
where
((
SimDevice
device
)
=>
device
.
isBooted
).
toList
();
Future
<
List
<
SimDevice
>>
getConnectedDevices
()
async
{
final
List
<
SimDevice
>
simDevices
=
await
getDevices
();
return
simDevices
.
where
((
SimDevice
device
)
=>
device
.
isBooted
).
toList
();
}
Future
<
bool
>
isInstalled
(
String
deviceId
,
String
appId
)
{
...
...
packages/flutter_tools/test/general.shard/ios/simulators_test.dart
View file @
21858253
...
...
@@ -390,14 +390,15 @@ void main() {
setUp
(()
{
mockProcessManager
=
MockProcessManager
();
when
(
mockProcessManager
.
runSync
(
any
))
.
thenReturn
(
ProcessResult
(
mockPid
,
0
,
validSimControlOutput
,
''
));
when
(
mockProcessManager
.
run
(
any
)).
thenAnswer
((
Invocation
_
)
async
{
return
ProcessResult
(
mockPid
,
0
,
validSimControlOutput
,
''
);
});
simControl
=
SimControl
();
});
testUsingContext
(
'getDevices succeeds'
,
()
{
final
List
<
SimDevice
>
devices
=
simControl
.
getDevices
();
testUsingContext
(
'getDevices succeeds'
,
()
async
{
final
List
<
SimDevice
>
devices
=
await
simControl
.
getDevices
();
final
SimDevice
watch
=
devices
[
0
];
expect
(
watch
.
category
,
'watchOS 4.3'
);
...
...
@@ -426,6 +427,17 @@ void main() {
ProcessManager:
()
=>
mockProcessManager
,
SimControl:
()
=>
simControl
,
});
testUsingContext
(
'getDevices handles bad simctl output'
,
()
async
{
when
(
mockProcessManager
.
run
(
any
))
.
thenAnswer
((
Invocation
_
)
async
=>
ProcessResult
(
mockPid
,
0
,
'Install Started'
,
''
));
final
List
<
SimDevice
>
devices
=
await
simControl
.
getDevices
();
expect
(
devices
,
isEmpty
);
},
overrides:
<
Type
,
Generator
>{
ProcessManager:
()
=>
mockProcessManager
,
SimControl:
()
=>
simControl
,
});
});
group
(
'startApp'
,
()
{
...
...
packages/flutter_tools/test/src/context.dart
View file @
21858253
...
...
@@ -77,7 +77,7 @@ void testUsingContext(
HttpClient:
()
=>
MockHttpClient
(),
IOSSimulatorUtils:
()
{
final
MockIOSSimulatorUtils
mock
=
MockIOSSimulatorUtils
();
when
(
mock
.
getAttachedDevices
()).
then
Return
(
<
IOSSimulator
>[]);
when
(
mock
.
getAttachedDevices
()).
then
Answer
((
Invocation
_
)
async
=>
<
IOSSimulator
>[]);
return
mock
;
},
OutputPreferences:
()
=>
OutputPreferences
(
showColor:
false
),
...
...
@@ -227,7 +227,7 @@ class FakeDoctor extends Doctor {
class
MockSimControl
extends
Mock
implements
SimControl
{
MockSimControl
()
{
when
(
getConnectedDevices
()).
then
Return
(
<
SimDevice
>[]);
when
(
getConnectedDevices
()).
then
Answer
((
Invocation
_
)
async
=>
<
SimDevice
>[]);
}
}
...
...
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