Use simctl exit code instead of stderr (#73070)

This commit is contained in:
Jenn Magder 2021-01-07 13:13:56 -08:00 committed by GitHub
parent 273630c09d
commit bc7286f118
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 4 deletions

View file

@ -124,7 +124,7 @@ class Xcode {
final RunResult result = _processUtils.runSync(
<String>[...xcrunCommand(), 'simctl', 'list'],
);
_isSimctlInstalled = result.stderr == null || result.stderr == '';
_isSimctlInstalled = result.exitCode == 0;
} on ProcessException {
_isSimctlInstalled = false;
}

View file

@ -140,6 +140,53 @@ void main() {
expect(xcode.isInstalledAndMeetsVersionCheck, isFalse);
});
testWithoutContext('isSimctlInstalled is true when simctl list succeeds', () {
when(mockXcodeProjectInterpreter.xcrunCommand()).thenReturn(<String>['xcrun']);
fakeProcessManager.addCommand(
const FakeCommand(
command: <String>[
'xcrun',
'simctl',
'list',
],
),
);
final Xcode xcode = Xcode(
logger: logger,
platform: FakePlatform(operatingSystem: 'macos'),
fileSystem: MemoryFileSystem.test(),
processManager: fakeProcessManager,
xcodeProjectInterpreter: mockXcodeProjectInterpreter,
);
expect(xcode.isSimctlInstalled, isTrue);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
});
testWithoutContext('isSimctlInstalled is true when simctl list fails', () {
when(mockXcodeProjectInterpreter.xcrunCommand()).thenReturn(<String>['xcrun']);
fakeProcessManager.addCommand(
const FakeCommand(
command: <String>[
'xcrun',
'simctl',
'list',
],
exitCode: 1,
),
);
final Xcode xcode = Xcode(
logger: logger,
platform: FakePlatform(operatingSystem: 'macos'),
fileSystem: MemoryFileSystem.test(),
processManager: fakeProcessManager,
xcodeProjectInterpreter: mockXcodeProjectInterpreter,
);
expect(xcode.isSimctlInstalled, isFalse);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
});
group('macOS', () {
Xcode xcode;
FakePlatform platform;

View file

@ -7,12 +7,9 @@ import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/macos/xcode.dart';
import 'package:flutter_tools/src/macos/xcode_validator.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
import '../../src/context.dart';
class MockProcessManager extends Mock implements ProcessManager {}
class MockXcode extends Mock implements Xcode {}
void main() {