Remove IMobileDevice from globals, hoist to XCDevice constructor (#53144)
* Convert ios_device_logger_test.dart to testWithoutContext * Remove IMobileDevice from globals, hoist to XCDevice constructor
This commit is contained in:
@@ -51,6 +51,7 @@ void main() {
|
||||
MockCache mockCache;
|
||||
Logger logger;
|
||||
IOSDeploy iosDeploy;
|
||||
IMobileDevice iMobileDevice;
|
||||
FileSystem mockFileSystem;
|
||||
|
||||
setUp(() {
|
||||
@@ -67,6 +68,12 @@ void main() {
|
||||
platform: macPlatform,
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
iMobileDevice = IMobileDevice(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
logger: logger,
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('successfully instantiates on Mac OS', () {
|
||||
@@ -77,6 +84,7 @@ void main() {
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
iosDeploy: iosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
name: 'iPhone 1',
|
||||
sdkVersion: '13.3',
|
||||
cpuArchitecture: DarwinArch.arm64
|
||||
@@ -91,6 +99,7 @@ void main() {
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
iosDeploy: iosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
name: 'iPhone 1',
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
sdkVersion: '1.0.0'
|
||||
@@ -102,6 +111,7 @@ void main() {
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
iosDeploy: iosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
name: 'iPhone 1',
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
sdkVersion: '13.1.1'
|
||||
@@ -113,6 +123,7 @@ void main() {
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
iosDeploy: iosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
name: 'iPhone 1',
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
sdkVersion: '10'
|
||||
@@ -124,6 +135,7 @@ void main() {
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
iosDeploy: iosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
name: 'iPhone 1',
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
sdkVersion: '0'
|
||||
@@ -135,6 +147,7 @@ void main() {
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
iosDeploy: iosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
name: 'iPhone 1',
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
sdkVersion: 'bogus'
|
||||
@@ -152,6 +165,7 @@ void main() {
|
||||
logger: logger,
|
||||
platform: platform,
|
||||
iosDeploy: iosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
name: 'iPhone 1',
|
||||
sdkVersion: '13.3',
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
@@ -205,6 +219,7 @@ void main() {
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
iosDeploy: iosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
name: 'iPhone 1',
|
||||
sdkVersion: '13.3',
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
@@ -288,6 +303,7 @@ void main() {
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
iosDeploy: iosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
name: 'iPhone 1',
|
||||
sdkVersion: '13.3',
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
@@ -488,6 +504,7 @@ void main() {
|
||||
logger: testLogger,
|
||||
platform: macPlatform,
|
||||
iosDeploy: mockIosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
);
|
||||
|
||||
@@ -573,6 +590,7 @@ void main() {
|
||||
FakeProcessManager fakeProcessManager;
|
||||
Logger logger;
|
||||
IOSDeploy iosDeploy;
|
||||
IMobileDevice iMobileDevice;
|
||||
IOSWorkflow mockIosWorkflow;
|
||||
|
||||
setUp(() {
|
||||
@@ -590,6 +608,12 @@ void main() {
|
||||
platform: macPlatform,
|
||||
processManager: fakeProcessManager,
|
||||
);
|
||||
iMobileDevice = IMobileDevice(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
processManager: fakeProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
});
|
||||
|
||||
final List<Platform> unsupportedPlatforms = <Platform>[linuxPlatform, windowsPlatform];
|
||||
@@ -623,6 +647,7 @@ void main() {
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
artifacts: mockArtifacts,
|
||||
iosDeploy: iosDeploy,
|
||||
iMobileDevice: iMobileDevice,
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
fileSystem: mockFileSystem,
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/ios/devices.dart';
|
||||
import 'package:flutter_tools/src/ios/ios_deploy.dart';
|
||||
import 'package:flutter_tools/src/ios/mac.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
@@ -171,6 +172,12 @@ IOSDevice setUpIOSDevice({
|
||||
sdkVersion: '13.3',
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
platform: platform,
|
||||
iMobileDevice: IMobileDevice(
|
||||
logger: BufferLogger.test(),
|
||||
processManager: processManager,
|
||||
artifacts: artifacts,
|
||||
cache: cache,
|
||||
),
|
||||
iosDeploy: IOSDeploy(
|
||||
logger: BufferLogger.test(),
|
||||
platform: platform,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/ios/devices.dart';
|
||||
@@ -11,14 +12,19 @@ import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
||||
void main() {
|
||||
FakeProcessManager processManager;
|
||||
MockArtifacts artifacts;
|
||||
FakeCache fakeCache;
|
||||
BufferLogger logger;
|
||||
|
||||
setUp(() {
|
||||
processManager = FakeProcessManager.list(<FakeCommand>[]);
|
||||
fakeCache = FakeCache();
|
||||
artifacts = MockArtifacts();
|
||||
logger = BufferLogger.test();
|
||||
when(artifacts.getArtifactPath(Artifact.idevicesyslog, platform: TargetPlatform.ios))
|
||||
.thenReturn('idevice-syslog');
|
||||
});
|
||||
@@ -37,8 +43,7 @@ void main() {
|
||||
expect(decoded, r'I \M-b\M^O syslog!');
|
||||
});
|
||||
|
||||
// IMobileDevice uses context.
|
||||
testUsingContext('IOSDeviceLogReader suppresses non-Flutter lines from output with syslog', () async {
|
||||
testWithoutContext('IOSDeviceLogReader suppresses non-Flutter lines from output with syslog', () async {
|
||||
processManager.addCommand(
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
@@ -54,18 +59,19 @@ Runner(UIKit)[297] <Notice>: E is for enpitsu"
|
||||
),
|
||||
);
|
||||
final DeviceLogReader logReader = IOSDeviceLogReader.test(
|
||||
iMobileDevice: IMobileDevice(),
|
||||
iMobileDevice: IMobileDevice(
|
||||
artifacts: artifacts,
|
||||
processManager: processManager,
|
||||
cache: fakeCache,
|
||||
logger: logger,
|
||||
),
|
||||
);
|
||||
final List<String> lines = await logReader.logLines.toList();
|
||||
|
||||
expect(lines, <String>['A is for ari', 'I is for ichigo']);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => processManager,
|
||||
Artifacts: () => artifacts,
|
||||
});
|
||||
|
||||
// IMobileDevice uses context.
|
||||
testUsingContext('IOSDeviceLogReader includes multi-line Flutter logs in the output with syslog', () async {
|
||||
testWithoutContext('IOSDeviceLogReader includes multi-line Flutter logs in the output with syslog', () async {
|
||||
processManager.addCommand(
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
@@ -81,7 +87,12 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt
|
||||
),
|
||||
);
|
||||
final DeviceLogReader logReader = IOSDeviceLogReader.test(
|
||||
iMobileDevice: IMobileDevice()
|
||||
iMobileDevice: IMobileDevice(
|
||||
artifacts: artifacts,
|
||||
processManager: processManager,
|
||||
cache: fakeCache,
|
||||
logger: logger,
|
||||
),
|
||||
);
|
||||
final List<String> lines = await logReader.logLines.toList();
|
||||
|
||||
@@ -91,13 +102,9 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt
|
||||
'This is a multi-line message,',
|
||||
' with a non-Flutter log message following it.',
|
||||
]);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => processManager,
|
||||
Artifacts: () => artifacts,
|
||||
});
|
||||
|
||||
// IMobileDevice uses context.
|
||||
testUsingContext('includes multi-line Flutter logs in the output', () async {
|
||||
testWithoutContext('includes multi-line Flutter logs in the output', () async {
|
||||
processManager.addCommand(
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
@@ -114,7 +121,12 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt
|
||||
);
|
||||
|
||||
final DeviceLogReader logReader = IOSDeviceLogReader.test(
|
||||
iMobileDevice: IMobileDevice()
|
||||
iMobileDevice: IMobileDevice(
|
||||
artifacts: artifacts,
|
||||
processManager: processManager,
|
||||
cache: fakeCache,
|
||||
logger: logger,
|
||||
),
|
||||
);
|
||||
final List<String> lines = await logReader.logLines.toList();
|
||||
|
||||
@@ -124,9 +136,6 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt
|
||||
'This is a multi-line message,',
|
||||
' with a non-Flutter log message following it.',
|
||||
]);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => processManager,
|
||||
Artifacts: () => artifacts,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ IOSDevice setUpIOSDevice(FileSystem fileSystem) {
|
||||
fileSystem: fileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
iosDeploy: null, // not used in this test
|
||||
iMobileDevice: null, // not used in this test
|
||||
platform: FakePlatform(operatingSystem: 'macos'),
|
||||
name: 'iPhone 1',
|
||||
sdkVersion: '13.3',
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/ios/devices.dart';
|
||||
import 'package:flutter_tools/src/ios/ios_deploy.dart';
|
||||
import 'package:flutter_tools/src/ios/mac.dart';
|
||||
import 'package:flutter_tools/src/mdns_discovery.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
@@ -390,6 +391,12 @@ IOSDevice setUpIOSDevice({
|
||||
artifacts: artifacts,
|
||||
cache: cache,
|
||||
),
|
||||
iMobileDevice: IMobileDevice(
|
||||
logger: logger ?? BufferLogger.test(),
|
||||
processManager: processManager ?? FakeProcessManager.any(),
|
||||
artifacts: artifacts,
|
||||
cache: cache,
|
||||
),
|
||||
cpuArchitecture: DarwinArch.arm64,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:file/file.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 ProcessResult;
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/ios/mac.dart';
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
@@ -36,14 +37,14 @@ class MockIosProject extends Mock implements IosProject {}
|
||||
|
||||
void main() {
|
||||
group('IMobileDevice', () {
|
||||
final FakePlatform osx = FakePlatform.fromPlatform(const LocalPlatform())
|
||||
..operatingSystem = 'macos';
|
||||
final String libimobiledevicePath = globals.fs.path.join('bin', 'cache', 'artifacts', 'libimobiledevice');
|
||||
final String idevicescreenshotPath = globals.fs.path.join(libimobiledevicePath, 'idevicescreenshot');
|
||||
MockArtifacts mockArtifacts;
|
||||
MockCache mockCache;
|
||||
Logger logger;
|
||||
|
||||
setUp(() {
|
||||
logger = BufferLogger.test();
|
||||
mockCache = MockCache();
|
||||
mockArtifacts = MockArtifacts();
|
||||
when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath);
|
||||
@@ -63,7 +64,7 @@ void main() {
|
||||
when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath);
|
||||
});
|
||||
|
||||
testUsingContext('error if idevicescreenshot is not installed', () async {
|
||||
testWithoutContext('error if idevicescreenshot is not installed', () async {
|
||||
when(mockOutputFile.path).thenReturn(outputPath);
|
||||
|
||||
// Let `idevicescreenshot` fail with exit code 1.
|
||||
@@ -72,11 +73,14 @@ void main() {
|
||||
workingDirectory: null,
|
||||
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(4, 1, '', '')));
|
||||
|
||||
expect(() async => await globals.iMobileDevice.takeScreenshot(mockOutputFile), throwsA(anything));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Platform: () => osx,
|
||||
Cache: () => mockCache,
|
||||
final IMobileDevice iMobileDevice = IMobileDevice(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(() async => await iMobileDevice.takeScreenshot(mockOutputFile), throwsA(anything));
|
||||
});
|
||||
|
||||
testUsingContext('idevicescreenshot captures and returns screenshot', () async {
|
||||
@@ -84,15 +88,20 @@ void main() {
|
||||
when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer(
|
||||
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
|
||||
|
||||
await globals.iMobileDevice.takeScreenshot(mockOutputFile);
|
||||
final IMobileDevice iMobileDevice = IMobileDevice(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
await iMobileDevice.takeScreenshot(mockOutputFile);
|
||||
verify(mockProcessManager.run(<String>[idevicescreenshotPath, outputPath],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
|
||||
workingDirectory: null,
|
||||
));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Cache: () => mockCache,
|
||||
Artifacts: () => mockArtifacts,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -216,6 +216,7 @@ void main() {
|
||||
processManager: processManager,
|
||||
logger: logger,
|
||||
xcode: mockXcode,
|
||||
iMobileDevice: null,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -844,7 +844,7 @@ class FakeCache implements Cache {
|
||||
String get storageBaseUrl => null;
|
||||
|
||||
@override
|
||||
MapEntry<String, String> get dyLdLibEntry => null;
|
||||
MapEntry<String, String> get dyLdLibEntry => const MapEntry<String, String>('DYLD_LIBRARY_PATH', '');
|
||||
|
||||
@override
|
||||
String get engineRevision => null;
|
||||
|
||||
Reference in New Issue
Block a user