@@ -894,16 +894,43 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text''',
894
894
895
895
late FakeProcessManager fakeProcessManager;
896
896
Xcode xcode;
897
+ Xcode xcodeBadSimctl;
897
898
late SimControl simControl;
899
+ late IOSSimulatorUtils simulatorUtils;
900
+ late IOSSimulatorUtils simulatorUtilsBadSimctl;
898
901
late BufferLogger logger;
899
902
const String deviceId = 'smart-phone' ;
900
903
const String appId = 'flutterApp' ;
901
904
902
905
setUp (() {
903
906
fakeProcessManager = FakeProcessManager .empty ();
904
907
xcode = Xcode .test (processManager: FakeProcessManager .any ());
908
+
909
+ final FakeProcessManager fakeProcessManagerBadSimctl = FakeProcessManager .list (< FakeCommand > [
910
+ const FakeCommand (command: < String > ['which' , 'sysctl' ]),
911
+ const FakeCommand (
912
+ command: < String > ['sysctl' , 'hw.optional.arm64' ],
913
+ stdout: 'hw.optional.arm64: 0' ,
914
+ ),
915
+ const FakeCommand (
916
+ command: < String > ['xcrun' , 'simctl' , 'list' , 'devices' , 'booted' ],
917
+ stderr: 'failed to run' ,
918
+ exitCode: 1 ,
919
+ ),
920
+ ]);
921
+ xcodeBadSimctl = Xcode .test (processManager: fakeProcessManagerBadSimctl);
905
922
logger = BufferLogger .test ();
906
923
simControl = SimControl (logger: logger, processManager: fakeProcessManager, xcode: xcode);
924
+ simulatorUtils = IOSSimulatorUtils (
925
+ logger: logger,
926
+ processManager: fakeProcessManager,
927
+ xcode: xcode,
928
+ );
929
+ simulatorUtilsBadSimctl = IOSSimulatorUtils (
930
+ logger: logger,
931
+ processManager: fakeProcessManager,
932
+ xcode: xcodeBadSimctl,
933
+ );
907
934
});
908
935
909
936
testWithoutContext ('getConnectedDevices succeeds' , () async {
@@ -933,6 +960,33 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text''',
933
960
expect (fakeProcessManager, hasNoRemainingExpectations);
934
961
});
935
962
963
+ testWithoutContext ('IOSSimulatorUtils.getAttachedDevices succeeds' , () async {
964
+ fakeProcessManager.addCommand (
965
+ const FakeCommand (
966
+ command: < String > ['xcrun' , 'simctl' , 'list' , 'devices' , 'booted' , 'iOS' , '--json' ],
967
+ stdout: validSimControlOutput,
968
+ ),
969
+ );
970
+
971
+ final List <IOSSimulator > devices = await simulatorUtils.getAttachedDevices ();
972
+
973
+ final IOSSimulator phone1 = devices[0 ];
974
+ expect (phone1.category, Category .mobile);
975
+ expect (phone1.name, 'iPhone 11' );
976
+ expect (phone1.simulatorCategory, 'com.apple.CoreSimulator.SimRuntime.iOS-14-0' );
977
+
978
+ final IOSSimulator phone2 = devices[1 ];
979
+ expect (phone2.category, Category .mobile);
980
+ expect (phone2.name, 'Phone w Watch' );
981
+ expect (phone2.simulatorCategory, 'com.apple.CoreSimulator.SimRuntime.iOS-16-0' );
982
+
983
+ final IOSSimulator phone3 = devices[2 ];
984
+ expect (phone3.category, Category .mobile);
985
+ expect (phone3.name, 'iPhone 13' );
986
+ expect (phone3.simulatorCategory, 'com.apple.CoreSimulator.SimRuntime.iOS-16-0' );
987
+ expect (fakeProcessManager, hasNoRemainingExpectations);
988
+ });
989
+
936
990
testWithoutContext ('getConnectedDevices handles bad simctl output' , () async {
937
991
fakeProcessManager.addCommand (
938
992
const FakeCommand (
@@ -947,6 +1001,16 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text''',
947
1001
expect (fakeProcessManager, hasNoRemainingExpectations);
948
1002
});
949
1003
1004
+ testWithoutContext (
1005
+ 'IOSSimulatorUtils.getAttachedDevices handles simctl not properly installed' ,
1006
+ () async {
1007
+ final List <IOSSimulator > devices = await simulatorUtilsBadSimctl.getAttachedDevices ();
1008
+
1009
+ expect (devices, isEmpty);
1010
+ expect (fakeProcessManager, hasNoRemainingExpectations);
1011
+ },
1012
+ );
1013
+
950
1014
testWithoutContext ('sdkMajorVersion defaults to 11 when sdkNameAndVersion is junk' , () async {
951
1015
final IOSSimulator iosSimulatorA = IOSSimulator (
952
1016
'x' ,
@@ -1186,6 +1250,17 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text''',
1186
1250
expect (logger.errorText, contains ('simctl returned non-JSON response:' ));
1187
1251
expect (fakeProcessManager, hasNoRemainingExpectations);
1188
1252
});
1253
+
1254
+ testWithoutContext (
1255
+ 'IOSSimulatorUtils.getAvailableIOSRuntimes handles simctl not properly installed' ,
1256
+ () async {
1257
+ final List <IOSSimulatorRuntime > runtimes =
1258
+ await simulatorUtilsBadSimctl.getAvailableIOSRuntimes ();
1259
+
1260
+ expect (runtimes, isEmpty);
1261
+ expect (fakeProcessManager, hasNoRemainingExpectations);
1262
+ },
1263
+ );
1189
1264
});
1190
1265
1191
1266
group ('startApp' , () {
0 commit comments