File tree Expand file tree Collapse file tree 3 files changed +55
-4
lines changed
Expand file tree Collapse file tree 3 files changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ Future<void> main() async {
1616 await testWithNewIOSSimulator ('TestHotReloadSim' , (String deviceId) async {
1717 simulatorDeviceId = deviceId;
1818 // This isn't actually a benchmark test, so do not use the returned `benchmarkScoreKeys` result.
19- await createHotModeTest (deviceIdOverride: deviceId)();
19+ await createHotModeTest (deviceIdOverride: deviceId, checkAppRunningOnLocalDevice : true )();
2020 });
2121 } finally {
2222 await removeIOSimulator (simulatorDeviceId);
Original file line number Diff line number Diff line change @@ -257,6 +257,25 @@ class SimControl {
257257 return result;
258258 }
259259
260+ Future <RunResult > stopApp (String deviceId, String appIdentifier) async {
261+ RunResult result;
262+ try {
263+ result = await _processUtils.run (
264+ < String > [
265+ ..._xcode.xcrunCommand (),
266+ 'simctl' ,
267+ 'terminate' ,
268+ deviceId,
269+ appIdentifier,
270+ ],
271+ throwOnError: true ,
272+ );
273+ } on ProcessException catch (exception) {
274+ throwToolExit ('Unable to terminate $appIdentifier on $deviceId :\n $exception ' );
275+ }
276+ return result;
277+ }
278+
260279 Future <void > takeScreenshot (String deviceId, String outputPath) async {
261280 try {
262281 await _processUtils.run (
@@ -533,11 +552,13 @@ class IOSSimulator extends Device {
533552
534553 @override
535554 Future <bool > stopApp (
536- ApplicationPackage app, {
555+ ApplicationPackage ? app, {
537556 String ? userIdentifier,
538557 }) async {
539- // Currently we don't have a way to stop an app running on iOS.
540- return false ;
558+ if (app == null ) {
559+ return false ;
560+ }
561+ return (await _simControl.stopApp (id, app.id)).exitCode == 0 ;
541562 }
542563
543564 String get logFilePath {
Original file line number Diff line number Diff line change @@ -901,6 +901,36 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text'''
901901 throwsToolExit (message: r'Unable to launch' ),
902902 );
903903 });
904+
905+ testWithoutContext ('.stopApp() handles exceptions' , () async {
906+ fakeProcessManager.addCommand (const FakeCommand (
907+ command: < String > [
908+ 'xcrun' ,
909+ 'simctl' ,
910+ 'terminate' ,
911+ deviceId,
912+ appId,
913+ ],
914+ exception: ProcessException ('xcrun' , < String > []),
915+ ));
916+
917+ expect (
918+ () async => simControl.stopApp (deviceId, appId),
919+ throwsToolExit (message: 'Unable to terminate' ),
920+ );
921+ expect (fakeProcessManager, hasNoRemainingExpectations);
922+ });
923+
924+ testWithoutContext ('simulator stopApp handles null app package' , () async {
925+ final IOSSimulator iosSimulator = IOSSimulator (
926+ 'x' ,
927+ name: 'Testo' ,
928+ simulatorCategory: 'NaN' ,
929+ simControl: simControl,
930+ );
931+
932+ expect (await iosSimulator.stopApp (null ), isFalse);
933+ });
904934 });
905935
906936 group ('startApp' , () {
You can’t perform that action at this time.
0 commit comments