Replace MockCache with Cache.test() (#66946)
This commit is contained in:
@@ -109,9 +109,11 @@ class GradleUtils {
|
||||
},
|
||||
);
|
||||
// Add the `gradle-wrapper.properties` file if it doesn't exist.
|
||||
final File propertiesFile = directory.childFile(
|
||||
globals.fs.path.join('gradle', 'wrapper', 'gradle-wrapper.properties'));
|
||||
final Directory propertiesDirectory = directory.childDirectory(
|
||||
globals.fs.path.join('gradle', 'wrapper'));
|
||||
final File propertiesFile = propertiesDirectory.childFile('gradle-wrapper.properties');
|
||||
if (!propertiesFile.existsSync()) {
|
||||
propertiesDirectory.createSync(recursive: true);
|
||||
final String gradleVersion = getGradleVersionForAndroidPlugin(directory);
|
||||
propertiesFile.writeAsStringSync('''
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:archive/archive.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:package_config/package_config.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import 'android/gradle_utils.dart';
|
||||
import 'base/common.dart';
|
||||
@@ -92,8 +94,8 @@ class Cache {
|
||||
/// [rootOverride] is configurable for testing.
|
||||
/// [artifacts] is configurable for testing.
|
||||
Cache({
|
||||
Directory rootOverride,
|
||||
List<ArtifactSet> artifacts,
|
||||
@protected Directory rootOverride,
|
||||
@protected List<ArtifactSet> artifacts,
|
||||
// TODO(jonahwilliams): make required once migrated to context-free.
|
||||
Logger logger,
|
||||
FileSystem fileSystem,
|
||||
@@ -143,6 +145,38 @@ class Cache {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a [Cache] for testing.
|
||||
///
|
||||
/// Defaults to a memory file system, fake platform,
|
||||
/// buffer logger, and no accessible artifacts.
|
||||
/// By default, the root cache directory path is "cache".
|
||||
@visibleForTesting
|
||||
factory Cache.test({
|
||||
Directory rootOverride,
|
||||
List<ArtifactSet> artifacts,
|
||||
Logger logger,
|
||||
FileSystem fileSystem,
|
||||
Platform platform,
|
||||
ProcessManager processManager,
|
||||
}) {
|
||||
fileSystem ??= rootOverride?.fileSystem ?? MemoryFileSystem.test();
|
||||
platform ??= FakePlatform(environment: <String, String>{});
|
||||
logger ??= BufferLogger.test();
|
||||
return Cache(
|
||||
rootOverride: rootOverride ??= fileSystem.directory('cache'),
|
||||
artifacts: artifacts ?? <ArtifactSet>[],
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
platform: platform,
|
||||
osUtils: OperatingSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final Logger _logger;
|
||||
final Platform _platform;
|
||||
final FileSystem _fileSystem;
|
||||
|
||||
@@ -23,7 +23,6 @@ void main() {
|
||||
MemoryFileSystem memoryFileSystem;
|
||||
MockFlutterVersion mockFlutterVersion;
|
||||
MockGitTagVersion mockGitTagVersion;
|
||||
MockCache mockCache;
|
||||
Directory outputDirectory;
|
||||
FakePlatform fakePlatform;
|
||||
|
||||
@@ -31,12 +30,17 @@ void main() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
const String storageBaseUrl = 'https://fake.googleapis.com';
|
||||
setUp(() {
|
||||
memoryFileSystem = MemoryFileSystem.test();
|
||||
mockFlutterVersion = MockFlutterVersion();
|
||||
mockGitTagVersion = MockGitTagVersion();
|
||||
mockCache = MockCache();
|
||||
fakePlatform = FakePlatform()..operatingSystem = 'macos';
|
||||
fakePlatform = FakePlatform(
|
||||
operatingSystem: 'macos',
|
||||
environment: <String, String>{
|
||||
'FLUTTER_STORAGE_BASE_URL': storageBaseUrl,
|
||||
},
|
||||
);
|
||||
|
||||
when(mockFlutterVersion.gitTagVersion).thenReturn(mockGitTagVersion);
|
||||
outputDirectory = globals.fs.systemTempDirectory
|
||||
@@ -46,16 +50,20 @@ void main() {
|
||||
});
|
||||
|
||||
group('podspec', () {
|
||||
const String storageBaseUrl = 'https://fake.googleapis.com';
|
||||
const String engineRevision = '0123456789abcdef';
|
||||
File licenseFile;
|
||||
Cache cache;
|
||||
|
||||
setUp(() {
|
||||
final Directory rootOverride = memoryFileSystem.directory('cache');
|
||||
cache = Cache.test(
|
||||
rootOverride: rootOverride,
|
||||
platform: fakePlatform,
|
||||
fileSystem: memoryFileSystem,
|
||||
);
|
||||
rootOverride.childDirectory('bin').childDirectory('internal').childFile('engine.version')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(engineRevision);
|
||||
when(mockFlutterVersion.gitTagVersion).thenReturn(mockGitTagVersion);
|
||||
when(mockCache.storageBaseUrl).thenReturn(storageBaseUrl);
|
||||
when(mockCache.engineRevision).thenReturn(engineRevision);
|
||||
licenseFile = memoryFileSystem.file('LICENSE');
|
||||
when(mockCache.getLicenseFile()).thenReturn(licenseFile);
|
||||
});
|
||||
|
||||
testUsingContext('version unknown', () async {
|
||||
@@ -66,7 +74,7 @@ void main() {
|
||||
buildSystem: MockBuildSystem(),
|
||||
platform: fakePlatform,
|
||||
flutterVersion: mockFlutterVersion,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
verboseHelp: false,
|
||||
);
|
||||
|
||||
@@ -91,7 +99,7 @@ void main() {
|
||||
buildSystem: MockBuildSystem(),
|
||||
platform: fakePlatform,
|
||||
flutterVersion: mockFlutterVersion,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
verboseHelp: false,
|
||||
);
|
||||
|
||||
@@ -113,7 +121,7 @@ void main() {
|
||||
buildSystem: MockBuildSystem(),
|
||||
platform: fakePlatform,
|
||||
flutterVersion: mockFlutterVersion,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
verboseHelp: false,
|
||||
);
|
||||
|
||||
@@ -136,7 +144,7 @@ void main() {
|
||||
|
||||
when(mockFlutterVersion.frameworkVersion).thenReturn(frameworkVersion);
|
||||
|
||||
licenseFile
|
||||
cache.getLicenseFile()
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(licenseText);
|
||||
});
|
||||
@@ -151,7 +159,7 @@ void main() {
|
||||
buildSystem: MockBuildSystem(),
|
||||
platform: fakePlatform,
|
||||
flutterVersion: mockFlutterVersion,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
verboseHelp: false,
|
||||
);
|
||||
command.produceFlutterPodspec(BuildMode.debug, outputDirectory, force: true);
|
||||
@@ -174,7 +182,7 @@ void main() {
|
||||
buildSystem: MockBuildSystem(),
|
||||
platform: fakePlatform,
|
||||
flutterVersion: mockFlutterVersion,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
verboseHelp: false,
|
||||
);
|
||||
command.produceFlutterPodspec(BuildMode.debug, outputDirectory);
|
||||
@@ -194,7 +202,7 @@ void main() {
|
||||
buildSystem: MockBuildSystem(),
|
||||
platform: fakePlatform,
|
||||
flutterVersion: mockFlutterVersion,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
verboseHelp: false,
|
||||
);
|
||||
command.produceFlutterPodspec(BuildMode.debug, outputDirectory);
|
||||
@@ -212,7 +220,7 @@ void main() {
|
||||
buildSystem: MockBuildSystem(),
|
||||
platform: fakePlatform,
|
||||
flutterVersion: mockFlutterVersion,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
verboseHelp: false,
|
||||
);
|
||||
command.produceFlutterPodspec(BuildMode.profile, outputDirectory);
|
||||
@@ -230,7 +238,7 @@ void main() {
|
||||
buildSystem: MockBuildSystem(),
|
||||
platform: fakePlatform,
|
||||
flutterVersion: mockFlutterVersion,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
verboseHelp: false,
|
||||
);
|
||||
command.produceFlutterPodspec(BuildMode.release, outputDirectory);
|
||||
@@ -250,5 +258,4 @@ void main() {
|
||||
|
||||
class MockFlutterVersion extends Mock implements FlutterVersion {}
|
||||
class MockGitTagVersion extends Mock implements GitTagVersion {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
class MockBuildSystem extends Mock implements BuildSystem {}
|
||||
|
||||
@@ -24,11 +24,10 @@ void main() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
MockCache cache;
|
||||
Cache cache;
|
||||
|
||||
setUp(() {
|
||||
cache = MockCache();
|
||||
when(cache.dyLdLibEntry).thenReturn(const MapEntry<String, String>('foo', 'bar'));
|
||||
cache = Cache.test();
|
||||
});
|
||||
|
||||
testUsingContext('returns 0 when called', () async {
|
||||
@@ -192,5 +191,3 @@ class NoDevicesManager extends DeviceManager {
|
||||
@override
|
||||
List<DeviceDiscovery> get deviceDiscoverers => <DeviceDiscovery>[];
|
||||
}
|
||||
|
||||
class MockCache extends Mock implements Cache {}
|
||||
|
||||
@@ -29,7 +29,7 @@ void main() {
|
||||
|
||||
await createTestCommandRunner(command).run(<String>['install']);
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => MockCache(),
|
||||
Cache: () => Cache.test(),
|
||||
});
|
||||
|
||||
testUsingContext('returns 1 when targeted device is not Android with --device-user', () async {
|
||||
@@ -46,7 +46,7 @@ void main() {
|
||||
expect(() async => await createTestCommandRunner(command).run(<String>['install', '--device-user', '10']),
|
||||
throwsToolExit(message: '--device-user is only supported for Android'));
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => MockCache(),
|
||||
Cache: () => Cache.test(),
|
||||
});
|
||||
|
||||
testUsingContext('returns 0 when iOS is connected and ready for an install', () async {
|
||||
@@ -60,9 +60,7 @@ void main() {
|
||||
|
||||
await createTestCommandRunner(command).run(<String>['install']);
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => MockCache(),
|
||||
Cache: () => Cache.test(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class MockCache extends Mock implements Cache {}
|
||||
|
||||
@@ -39,20 +39,22 @@ void main() {
|
||||
AndroidSdk sdk;
|
||||
ProcessManager mockProcessManager;
|
||||
MemoryFileSystem fs;
|
||||
Cache mockCache;
|
||||
Cache cache;
|
||||
File gradle;
|
||||
final Map<Type, Generator> overrides = <Type, Generator>{
|
||||
AndroidSdk: () => sdk,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
FileSystem: () => fs,
|
||||
Cache: () => mockCache,
|
||||
Cache: () => cache,
|
||||
};
|
||||
|
||||
setUp(() async {
|
||||
sdk = MockitoAndroidSdk();
|
||||
mockProcessManager = MockitoProcessManager();
|
||||
fs = MemoryFileSystem.test();
|
||||
mockCache = MockCache();
|
||||
cache = Cache.test(
|
||||
processManager: FakeProcessManager.any()
|
||||
);
|
||||
Cache.flutterRoot = '../..';
|
||||
when(sdk.licensesAvailable).thenReturn(true);
|
||||
when(mockProcessManager.canRun(any)).thenReturn(true);
|
||||
@@ -108,13 +110,12 @@ void main() {
|
||||
.childFile('gradle.properties')
|
||||
.writeAsStringSync('irrelevant');
|
||||
|
||||
final Directory gradleWrapperDir = globals.fs.systemTempDirectory.createTempSync('flutter_application_package_test_gradle_wrapper.');
|
||||
when(mockCache.getArtifactDirectory('gradle_wrapper')).thenReturn(gradleWrapperDir);
|
||||
final Directory gradleWrapperDir = cache.getArtifactDirectory('gradle_wrapper');
|
||||
|
||||
globals.fs.directory(gradleWrapperDir.childDirectory('gradle').childDirectory('wrapper'))
|
||||
gradleWrapperDir.fileSystem.directory(gradleWrapperDir.childDirectory('gradle').childDirectory('wrapper'))
|
||||
.createSync(recursive: true);
|
||||
globals.fs.file(globals.fs.path.join(gradleWrapperDir.path, 'gradlew')).writeAsStringSync('irrelevant');
|
||||
globals.fs.file(globals.fs.path.join(gradleWrapperDir.path, 'gradlew.bat')).writeAsStringSync('irrelevant');
|
||||
gradleWrapperDir.childFile('gradlew').writeAsStringSync('irrelevant');
|
||||
gradleWrapperDir.childFile('gradlew.bat').writeAsStringSync('irrelevant');
|
||||
|
||||
await ApplicationPackageFactory.instance.getPackageForPlatform(
|
||||
TargetPlatform.android_arm,
|
||||
@@ -691,5 +692,4 @@ const String plistData = '''
|
||||
{"CFBundleIdentifier": "fooBundleId"}
|
||||
''';
|
||||
|
||||
class MockCache extends Mock implements Cache {}
|
||||
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils { }
|
||||
|
||||
@@ -85,10 +85,17 @@ void main() {
|
||||
|
||||
group('Cache', () {
|
||||
MockCache mockCache;
|
||||
Cache cache;
|
||||
MemoryFileSystem memoryFileSystem;
|
||||
ProcessManager fakeProcessManager;
|
||||
|
||||
setUp(() {
|
||||
fakeProcessManager = FakeProcessManager.any();
|
||||
mockCache = MockCache();
|
||||
cache = Cache.test(
|
||||
fileSystem: memoryFileSystem,
|
||||
processManager: fakeProcessManager,
|
||||
);
|
||||
memoryFileSystem = MemoryFileSystem.test();
|
||||
});
|
||||
|
||||
@@ -110,30 +117,27 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('Gradle wrapper should not be up to date, if some cached artifact is not available', () {
|
||||
final GradleWrapper gradleWrapper = GradleWrapper(mockCache);
|
||||
final Directory directory = globals.fs.directory('/Applications/flutter/bin/cache');
|
||||
directory.createSync(recursive: true);
|
||||
globals.fs.file(globals.fs.path.join(directory.path, 'artifacts', 'gradle_wrapper', 'gradle', 'wrapper', 'gradle-wrapper.jar')).createSync(recursive: true);
|
||||
when(mockCache.getCacheDir(globals.fs.path.join('artifacts', 'gradle_wrapper'))).thenReturn(globals.fs.directory(globals.fs.path.join(directory.path, 'artifacts', 'gradle_wrapper')));
|
||||
final GradleWrapper gradleWrapper = GradleWrapper(cache);
|
||||
final Directory directory = cache.getCacheDir(globals.fs.path.join('artifacts', 'gradle_wrapper'));
|
||||
globals.fs.file(globals.fs.path.join(directory.path, 'gradle', 'wrapper', 'gradle-wrapper.jar')).createSync(recursive: true);
|
||||
|
||||
expect(gradleWrapper.isUpToDateInner(), false);
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => mockCache,
|
||||
Cache: () => cache,
|
||||
FileSystem: () => memoryFileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('Gradle wrapper should be up to date, only if all cached artifact are available', () {
|
||||
final GradleWrapper gradleWrapper = GradleWrapper(mockCache);
|
||||
final Directory directory = globals.fs.directory('/Applications/flutter/bin/cache');
|
||||
directory.createSync(recursive: true);
|
||||
globals.fs.file(globals.fs.path.join(directory.path, 'artifacts', 'gradle_wrapper', 'gradle', 'wrapper', 'gradle-wrapper.jar')).createSync(recursive: true);
|
||||
globals.fs.file(globals.fs.path.join(directory.path, 'artifacts', 'gradle_wrapper', 'gradlew')).createSync(recursive: true);
|
||||
globals.fs.file(globals.fs.path.join(directory.path, 'artifacts', 'gradle_wrapper', 'gradlew.bat')).createSync(recursive: true);
|
||||
final GradleWrapper gradleWrapper = GradleWrapper(cache);
|
||||
final Directory directory = cache.getCacheDir(globals.fs.path.join('artifacts', 'gradle_wrapper'));
|
||||
globals.fs.file(globals.fs.path.join(directory.path, 'gradle', 'wrapper', 'gradle-wrapper.jar')).createSync(recursive: true);
|
||||
globals.fs.file(globals.fs.path.join(directory.path, 'gradlew')).createSync(recursive: true);
|
||||
globals.fs.file(globals.fs.path.join(directory.path, 'gradlew.bat')).createSync(recursive: true);
|
||||
|
||||
when(mockCache.getCacheDir(globals.fs.path.join('artifacts', 'gradle_wrapper'))).thenReturn(globals.fs.directory(globals.fs.path.join(directory.path, 'artifacts', 'gradle_wrapper')));
|
||||
expect(gradleWrapper.isUpToDateInner(), true);
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => mockCache,
|
||||
Cache: () => cache,
|
||||
FileSystem: () => memoryFileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
@@ -201,9 +205,8 @@ void main() {
|
||||
cache.dyLdLibEntry.value,
|
||||
'/path/to/alpha:/path/to/beta:/path/to/gamma:/path/to/delta:/path/to/epsilon',
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => mockCache,
|
||||
});
|
||||
|
||||
testUsingContext('failed storage.googleapis.com download shows China warning', () async {
|
||||
final CachedArtifact artifact1 = MockCachedArtifact();
|
||||
final CachedArtifact artifact2 = MockCachedArtifact();
|
||||
@@ -300,33 +303,29 @@ void main() {
|
||||
group('AndroidMavenArtifacts', () {
|
||||
MemoryFileSystem memoryFileSystem;
|
||||
MockProcessManager processManager;
|
||||
MockCache mockCache;
|
||||
Cache cache;
|
||||
|
||||
setUp(() {
|
||||
memoryFileSystem = MemoryFileSystem.test();
|
||||
processManager = MockProcessManager();
|
||||
mockCache = MockCache();
|
||||
cache = Cache.test(
|
||||
fileSystem: memoryFileSystem,
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
});
|
||||
|
||||
test('development artifact', () async {
|
||||
final AndroidMavenArtifacts mavenArtifacts = AndroidMavenArtifacts(mockCache);
|
||||
final AndroidMavenArtifacts mavenArtifacts = AndroidMavenArtifacts(cache);
|
||||
expect(mavenArtifacts.developmentArtifact, DevelopmentArtifact.androidMaven);
|
||||
});
|
||||
|
||||
testUsingContext('update', () async {
|
||||
final Directory cacheRoot = globals.fs.directory('/bin/cache')
|
||||
..createSync(recursive: true);
|
||||
when(mockCache.getRoot()).thenReturn(cacheRoot);
|
||||
final AndroidMavenArtifacts mavenArtifacts = AndroidMavenArtifacts(mockCache);
|
||||
final AndroidMavenArtifacts mavenArtifacts = AndroidMavenArtifacts(cache);
|
||||
expect(await mavenArtifacts.isUpToDate(), isFalse);
|
||||
|
||||
final Directory gradleWrapperDir = globals.fs.systemTempDirectory.createTempSync('flutter_cache_test_gradle_wrapper.');
|
||||
when(mockCache.getArtifactDirectory('gradle_wrapper')).thenReturn(gradleWrapperDir);
|
||||
|
||||
globals.fs.directory(gradleWrapperDir.childDirectory('gradle').childDirectory('wrapper'))
|
||||
.createSync(recursive: true);
|
||||
globals.fs.file(globals.fs.path.join(gradleWrapperDir.path, 'gradlew')).writeAsStringSync('irrelevant');
|
||||
globals.fs.file(globals.fs.path.join(gradleWrapperDir.path, 'gradlew.bat')).writeAsStringSync('irrelevant');
|
||||
final Directory gradleWrapperDir = cache.getArtifactDirectory('gradle_wrapper')..createSync(recursive: true);
|
||||
gradleWrapperDir.childFile('gradlew').writeAsStringSync('irrelevant');
|
||||
gradleWrapperDir.childFile('gradlew.bat').writeAsStringSync('irrelevant');
|
||||
|
||||
when(globals.processManager.run(any, environment: captureAnyNamed('environment')))
|
||||
.thenAnswer((Invocation invocation) {
|
||||
@@ -343,22 +342,23 @@ void main() {
|
||||
|
||||
expect(await mavenArtifacts.isUpToDate(), isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => mockCache,
|
||||
Cache: () => cache,
|
||||
FileSystem: () => memoryFileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
});
|
||||
});
|
||||
|
||||
group('macOS artifacts', () {
|
||||
MockCache mockCache;
|
||||
Cache cache;
|
||||
|
||||
setUp(() {
|
||||
mockCache = MockCache();
|
||||
cache = Cache.test(
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('verifies executables for libimobiledevice in isUpToDateInner', () async {
|
||||
final IosUsbArtifacts iosUsbArtifacts = IosUsbArtifacts('libimobiledevice', mockCache);
|
||||
when(mockCache.getArtifactDirectory(any)).thenReturn(globals.fs.currentDirectory);
|
||||
final IosUsbArtifacts iosUsbArtifacts = IosUsbArtifacts('libimobiledevice', cache);
|
||||
iosUsbArtifacts.location.createSync();
|
||||
final File ideviceScreenshotFile = iosUsbArtifacts.location.childFile('idevicescreenshot')
|
||||
..createSync();
|
||||
@@ -371,14 +371,13 @@ void main() {
|
||||
|
||||
expect(iosUsbArtifacts.isUpToDateInner(), false);
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => mockCache,
|
||||
Cache: () => cache,
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('verifies iproxy for usbmuxd in isUpToDateInner', () async {
|
||||
final IosUsbArtifacts iosUsbArtifacts = IosUsbArtifacts('usbmuxd', mockCache);
|
||||
when(mockCache.getArtifactDirectory(any)).thenReturn(globals.fs.currentDirectory);
|
||||
final IosUsbArtifacts iosUsbArtifacts = IosUsbArtifacts('usbmuxd', cache);
|
||||
iosUsbArtifacts.location.createSync();
|
||||
final File iproxy = iosUsbArtifacts.location.childFile('iproxy')
|
||||
..createSync();
|
||||
@@ -389,47 +388,48 @@ void main() {
|
||||
|
||||
expect(iosUsbArtifacts.isUpToDateInner(), false);
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => mockCache,
|
||||
Cache: () => cache,
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('Does not verify executables for openssl in isUpToDateInner', () async {
|
||||
final IosUsbArtifacts iosUsbArtifacts = IosUsbArtifacts('openssl', mockCache);
|
||||
when(mockCache.getArtifactDirectory(any)).thenReturn(globals.fs.currentDirectory);
|
||||
final IosUsbArtifacts iosUsbArtifacts = IosUsbArtifacts('openssl', cache);
|
||||
iosUsbArtifacts.location.createSync();
|
||||
|
||||
expect(iosUsbArtifacts.isUpToDateInner(), true);
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => mockCache,
|
||||
Cache: () => cache,
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('use unsigned when specified', () async {
|
||||
when(mockCache.useUnsignedMacBinaries).thenReturn(true);
|
||||
cache.useUnsignedMacBinaries = true;
|
||||
|
||||
final IosUsbArtifacts iosUsbArtifacts = IosUsbArtifacts('name', mockCache);
|
||||
final IosUsbArtifacts iosUsbArtifacts = IosUsbArtifacts('name', cache);
|
||||
expect(iosUsbArtifacts.archiveUri.toString(), contains('/unsigned/'));
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => mockCache,
|
||||
Cache: () => cache,
|
||||
});
|
||||
|
||||
testUsingContext('not use unsigned when not specified', () async {
|
||||
when(mockCache.useUnsignedMacBinaries).thenReturn(false);
|
||||
cache.useUnsignedMacBinaries = false;
|
||||
|
||||
final IosUsbArtifacts iosUsbArtifacts = IosUsbArtifacts('name', mockCache);
|
||||
final IosUsbArtifacts iosUsbArtifacts = IosUsbArtifacts('name', cache);
|
||||
expect(iosUsbArtifacts.archiveUri.toString(), isNot(contains('/unsigned/')));
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => mockCache,
|
||||
Cache: () => cache,
|
||||
});
|
||||
});
|
||||
|
||||
testWithoutContext('Downloads Flutter runner debug symbols', () async {
|
||||
final MockCache mockCache = MockCache();
|
||||
final Cache cache = Cache.test(
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
final MockVersionedPackageResolver mockPackageResolver = MockVersionedPackageResolver();
|
||||
final FlutterRunnerDebugSymbols flutterRunnerDebugSymbols = FlutterRunnerDebugSymbols(
|
||||
mockCache,
|
||||
cache,
|
||||
packageResolver: mockPackageResolver,
|
||||
platform: FakePlatform(operatingSystem: 'linux'),
|
||||
);
|
||||
@@ -444,51 +444,51 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('FontSubset in univeral artifacts', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
|
||||
final Cache cache = Cache.test();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache);
|
||||
expect(artifacts.developmentArtifact, DevelopmentArtifact.universal);
|
||||
});
|
||||
|
||||
testUsingContext('FontSubset artifacts on linux', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
final Cache cache = Cache.test();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache);
|
||||
cache.includeAllPlatforms = false;
|
||||
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['linux-x64', 'linux-x64/font-subset.zip']]);
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform(operatingSystem: 'linux'),
|
||||
});
|
||||
|
||||
testUsingContext('FontSubset artifacts on windows', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
final Cache cache = Cache.test();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache);
|
||||
cache.includeAllPlatforms = false;
|
||||
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['windows-x64', 'windows-x64/font-subset.zip']]);
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform(operatingSystem: 'windows'),
|
||||
});
|
||||
|
||||
testUsingContext('FontSubset artifacts on macos', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
final Cache cache = Cache.test();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache);
|
||||
cache.includeAllPlatforms = false;
|
||||
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['darwin-x64', 'darwin-x64/font-subset.zip']]);
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform(operatingSystem: 'macos'),
|
||||
});
|
||||
|
||||
testUsingContext('FontSubset artifacts on fuchsia', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
final Cache cache = Cache.test();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache);
|
||||
cache.includeAllPlatforms = false;
|
||||
expect(artifacts.getBinaryDirs, throwsToolExit(message: 'Unsupported operating system: ${globals.platform.operatingSystem}'));
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform(operatingSystem: 'fuchsia'),
|
||||
});
|
||||
|
||||
testUsingContext('FontSubset artifacts for all platforms', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(true);
|
||||
final Cache cache = Cache.test();
|
||||
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(cache);
|
||||
cache.includeAllPlatforms = true;
|
||||
expect(artifacts.getBinaryDirs(), <List<String>>[
|
||||
<String>['darwin-x64', 'darwin-x64/font-subset.zip'],
|
||||
<String>['linux-x64', 'linux-x64/font-subset.zip'],
|
||||
@@ -499,10 +499,10 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('macOS desktop artifacts ignore filtering when requested', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final MacOSEngineArtifacts artifacts = MacOSEngineArtifacts(mockCache);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
when(mockCache.platformOverrideArtifacts).thenReturn(<String>{'macos'});
|
||||
final Cache cache = Cache.test();
|
||||
final MacOSEngineArtifacts artifacts = MacOSEngineArtifacts(cache);
|
||||
cache.includeAllPlatforms = false;
|
||||
cache.platformOverrideArtifacts = <String>{'macos'};
|
||||
|
||||
expect(artifacts.getBinaryDirs(), isNotEmpty);
|
||||
}, overrides: <Type, Generator> {
|
||||
@@ -510,21 +510,21 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('Windows desktop artifacts ignore filtering when requested', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final Cache cache = Cache.test();
|
||||
final WindowsEngineArtifacts artifacts = WindowsEngineArtifacts(
|
||||
mockCache,
|
||||
cache,
|
||||
platform: FakePlatform(operatingSystem: 'linux'),
|
||||
);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
when(mockCache.platformOverrideArtifacts).thenReturn(<String>{'windows'});
|
||||
cache.includeAllPlatforms = false;
|
||||
cache.platformOverrideArtifacts = <String>{'windows'};
|
||||
|
||||
expect(artifacts.getBinaryDirs(), isNotEmpty);
|
||||
});
|
||||
|
||||
testWithoutContext('Windows desktop artifacts include profile and release artifacts', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final Cache cache = Cache.test();
|
||||
final WindowsEngineArtifacts artifacts = WindowsEngineArtifacts(
|
||||
mockCache,
|
||||
cache,
|
||||
platform: FakePlatform(operatingSystem: 'windows'),
|
||||
);
|
||||
|
||||
@@ -535,21 +535,21 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('Linux desktop artifacts ignore filtering when requested', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final Cache cache = Cache.test();
|
||||
final LinuxEngineArtifacts artifacts = LinuxEngineArtifacts(
|
||||
mockCache,
|
||||
cache,
|
||||
platform: FakePlatform(operatingSystem: 'macos'),
|
||||
);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
when(mockCache.platformOverrideArtifacts).thenReturn(<String>{'linux'});
|
||||
cache.includeAllPlatforms = false;
|
||||
cache.platformOverrideArtifacts = <String>{'linux'};
|
||||
|
||||
expect(artifacts.getBinaryDirs(), isNotEmpty);
|
||||
});
|
||||
|
||||
testWithoutContext('Linux desktop artifacts include profile and release artifacts', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final Cache cache = Cache.test();
|
||||
final LinuxEngineArtifacts artifacts = LinuxEngineArtifacts(
|
||||
mockCache,
|
||||
cache,
|
||||
platform: FakePlatform(operatingSystem: 'linux'),
|
||||
);
|
||||
|
||||
|
||||
@@ -21,13 +21,12 @@ import '../src/fake_devices.dart';
|
||||
import '../src/mocks.dart';
|
||||
|
||||
void main() {
|
||||
MockCache cache;
|
||||
Cache cache;
|
||||
BufferLogger logger;
|
||||
|
||||
setUp(() {
|
||||
cache = MockCache();
|
||||
cache = Cache.test();
|
||||
logger = BufferLogger.test();
|
||||
when(cache.dyLdLibEntry).thenReturn(const MapEntry<String, String>('foo', 'bar'));
|
||||
});
|
||||
|
||||
group('DeviceManager', () {
|
||||
@@ -550,5 +549,4 @@ class TestDeviceManager extends DeviceManager {
|
||||
class MockProcess extends Mock implements Process {}
|
||||
class MockTerminal extends Mock implements AnsiTerminal {}
|
||||
class MockStdio extends Mock implements Stdio {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
class MockDeviceDiscovery extends Mock implements DeviceDiscovery {}
|
||||
|
||||
@@ -827,9 +827,10 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('Correct flutter runner', () async {
|
||||
final MockCache cache = MockCache();
|
||||
final Cache cache = Cache.test(
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
when(cache.getArtifactDirectory('flutter_runner')).thenReturn(fileSystem.directory('fuchsia'));
|
||||
final CachedArtifacts artifacts = CachedArtifacts(
|
||||
cache: cache,
|
||||
fileSystem: fileSystem,
|
||||
@@ -1591,4 +1592,3 @@ class MockFuchsiaSdk extends Mock implements FuchsiaSdk {
|
||||
|
||||
class MockDartDevelopmentService extends Mock implements DartDevelopmentService {}
|
||||
class MockFuchsiaWorkflow extends Mock implements FuchsiaWorkflow {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
|
||||
@@ -37,7 +37,7 @@ void main() {
|
||||
group('IOSDevice', () {
|
||||
final List<Platform> unsupportedPlatforms = <Platform>[linuxPlatform, windowsPlatform];
|
||||
Artifacts mockArtifacts;
|
||||
MockCache mockCache;
|
||||
Cache cache;
|
||||
MockVmService mockVmService;
|
||||
Logger logger;
|
||||
IOSDeploy iosDeploy;
|
||||
@@ -46,21 +46,19 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
mockArtifacts = MockArtifacts();
|
||||
mockCache = MockCache();
|
||||
cache = Cache.test();
|
||||
mockVmService = MockVmService();
|
||||
const MapEntry<String, String> dyLdLibEntry = MapEntry<String, String>('DYLD_LIBRARY_PATH', '/path/to/libs');
|
||||
when(mockCache.dyLdLibEntry).thenReturn(dyLdLibEntry);
|
||||
logger = BufferLogger.test();
|
||||
iosDeploy = IOSDeploy(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
iMobileDevice = IMobileDevice(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
logger: logger,
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
@@ -214,7 +212,7 @@ void main() {
|
||||
IOSDevicePortForwarder portForwarder;
|
||||
ForwardedPort forwardedPort;
|
||||
Artifacts mockArtifacts;
|
||||
MockCache mockCache;
|
||||
Cache cache;
|
||||
Logger logger;
|
||||
IOSDeploy iosDeploy;
|
||||
FileSystem nullFileSystem;
|
||||
@@ -262,10 +260,10 @@ void main() {
|
||||
mockProcess3 = MockProcess();
|
||||
forwardedPort = ForwardedPort.withContext(123, 456, mockProcess3);
|
||||
mockArtifacts = MockArtifacts();
|
||||
mockCache = MockCache();
|
||||
cache = Cache.test();
|
||||
iosDeploy = IOSDeploy(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
processManager: FakeProcessManager.any(),
|
||||
@@ -306,7 +304,7 @@ void main() {
|
||||
group('polling', () {
|
||||
MockXcdevice mockXcdevice;
|
||||
MockArtifacts mockArtifacts;
|
||||
MockCache mockCache;
|
||||
Cache cache;
|
||||
MockVmService mockVmService1;
|
||||
MockVmService mockVmService2;
|
||||
FakeProcessManager fakeProcessManager;
|
||||
@@ -320,7 +318,7 @@ void main() {
|
||||
setUp(() {
|
||||
mockXcdevice = MockXcdevice();
|
||||
mockArtifacts = MockArtifacts();
|
||||
mockCache = MockCache();
|
||||
cache = Cache.test();
|
||||
mockVmService1 = MockVmService();
|
||||
mockVmService2 = MockVmService();
|
||||
logger = BufferLogger.test();
|
||||
@@ -328,14 +326,14 @@ void main() {
|
||||
fakeProcessManager = FakeProcessManager.any();
|
||||
iosDeploy = IOSDeploy(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
logger: logger,
|
||||
platform: macPlatform,
|
||||
processManager: fakeProcessManager,
|
||||
);
|
||||
iMobileDevice = IMobileDevice(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
cache: cache,
|
||||
processManager: fakeProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
@@ -605,7 +603,6 @@ void main() {
|
||||
|
||||
class MockIOSApp extends Mock implements IOSApp {}
|
||||
class MockArtifacts extends Mock implements Artifacts {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
class MockIMobileDevice extends Mock implements IMobileDevice {}
|
||||
class MockIOSDeploy extends Mock implements IOSDeploy {}
|
||||
class MockIOSWorkflow extends Mock implements IOSWorkflow {}
|
||||
|
||||
@@ -9,16 +9,25 @@ import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
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:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
|
||||
void main () {
|
||||
Artifacts artifacts;
|
||||
String iosDeployPath;
|
||||
|
||||
setUp(() {
|
||||
artifacts = Artifacts.test();
|
||||
iosDeployPath = artifacts.getArtifactPath(Artifact.iosDeploy, platform: TargetPlatform.ios);
|
||||
});
|
||||
|
||||
testWithoutContext('IOSDeploy.iosDeployEnv returns path with /usr/bin first', () {
|
||||
final IOSDeploy iosDeploy = setUpIOSDeploy(FakeProcessManager.any());
|
||||
final Map<String, String> environment = iosDeploy.iosDeployEnv;
|
||||
@@ -35,7 +44,7 @@ void main () {
|
||||
'-t',
|
||||
'0',
|
||||
'/dev/null',
|
||||
'ios-deploy',
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'123',
|
||||
'--bundle',
|
||||
@@ -47,12 +56,12 @@ void main () {
|
||||
].join(' '),
|
||||
], environment: const <String, String>{
|
||||
'PATH': '/usr/bin:/usr/local/bin:/usr/bin',
|
||||
'DYLD_LIBRARY_PATH': '/path/to/libs',
|
||||
'DYLD_LIBRARY_PATH': '/path/to/libraries',
|
||||
},
|
||||
stdout: '(lldb) run\nsuccess\nDid finish launching.',
|
||||
),
|
||||
]);
|
||||
final IOSDeploy iosDeploy = setUpIOSDeploy(processManager);
|
||||
final IOSDeploy iosDeploy = setUpIOSDeploy(processManager, artifacts: artifacts);
|
||||
final IOSDeployDebugger iosDeployDebugger = iosDeploy.prepareDebuggerForLaunch(
|
||||
deviceId: '123',
|
||||
bundlePath: '/',
|
||||
@@ -229,8 +238,8 @@ void main () {
|
||||
const String deviceId = '123';
|
||||
const String bundleId = 'com.example.app';
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
deviceId,
|
||||
'--uninstall_only',
|
||||
@@ -238,7 +247,7 @@ void main () {
|
||||
bundleId,
|
||||
])
|
||||
]);
|
||||
final IOSDeploy iosDeploy = setUpIOSDeploy(processManager);
|
||||
final IOSDeploy iosDeploy = setUpIOSDeploy(processManager, artifacts: artifacts);
|
||||
final int exitCode = await iosDeploy.uninstallApp(
|
||||
deviceId: deviceId,
|
||||
bundleId: bundleId,
|
||||
@@ -252,8 +261,8 @@ void main () {
|
||||
const String deviceId = '123';
|
||||
const String bundleId = 'com.example.app';
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
deviceId,
|
||||
'--uninstall_only',
|
||||
@@ -261,7 +270,7 @@ void main () {
|
||||
bundleId,
|
||||
], exitCode: 1)
|
||||
]);
|
||||
final IOSDeploy iosDeploy = setUpIOSDeploy(processManager);
|
||||
final IOSDeploy iosDeploy = setUpIOSDeploy(processManager, artifacts: artifacts);
|
||||
final int exitCode = await iosDeploy.uninstallApp(
|
||||
deviceId: deviceId,
|
||||
bundleId: bundleId,
|
||||
@@ -273,30 +282,27 @@ void main () {
|
||||
});
|
||||
}
|
||||
|
||||
IOSDeploy setUpIOSDeploy(ProcessManager processManager) {
|
||||
const MapEntry<String, String> kDyLdLibEntry = MapEntry<String, String>(
|
||||
'DYLD_LIBRARY_PATH', '/path/to/libs',
|
||||
);
|
||||
IOSDeploy setUpIOSDeploy(ProcessManager processManager, {
|
||||
Artifacts artifacts,
|
||||
}) {
|
||||
final FakePlatform macPlatform = FakePlatform(
|
||||
operatingSystem: 'macos',
|
||||
environment: <String, String>{
|
||||
'PATH': '/usr/local/bin:/usr/bin'
|
||||
}
|
||||
);
|
||||
final MockArtifacts artifacts = MockArtifacts();
|
||||
final MockCache cache = MockCache();
|
||||
final Cache cache = Cache.test(
|
||||
platform: macPlatform,
|
||||
artifacts: <ArtifactSet>[
|
||||
FakeDyldEnvironmentArtifact(),
|
||||
],
|
||||
);
|
||||
|
||||
when(cache.dyLdLibEntry).thenReturn(kDyLdLibEntry);
|
||||
when(artifacts.getArtifactPath(Artifact.iosDeploy, platform: anyNamed('platform')))
|
||||
.thenReturn('ios-deploy');
|
||||
return IOSDeploy(
|
||||
logger: BufferLogger.test(),
|
||||
platform: macPlatform,
|
||||
processManager: processManager,
|
||||
artifacts: artifacts,
|
||||
artifacts: artifacts ?? Artifacts.test(),
|
||||
cache: cache,
|
||||
);
|
||||
}
|
||||
|
||||
class MockArtifacts extends Mock implements Artifacts {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
|
||||
@@ -21,12 +21,21 @@ import 'package:vm_service/vm_service.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
|
||||
const Map<String, String> kDyLdLibEntry = <String, String>{
|
||||
'DYLD_LIBRARY_PATH': '/path/to/libs',
|
||||
'DYLD_LIBRARY_PATH': '/path/to/libraries',
|
||||
};
|
||||
|
||||
void main() {
|
||||
Artifacts artifacts;
|
||||
String iosDeployPath;
|
||||
|
||||
setUp(() {
|
||||
artifacts = Artifacts.test();
|
||||
iosDeployPath = artifacts.getArtifactPath(Artifact.iosDeploy, platform: TargetPlatform.ios);
|
||||
});
|
||||
|
||||
testWithoutContext('IOSDevice.installApp calls ios-deploy correctly with USB', () async {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final IOSApp iosApp = PrebuiltIOSApp(
|
||||
@@ -34,14 +43,14 @@ void main() {
|
||||
bundleDir: fileSystem.currentDirectory,
|
||||
);
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'1234',
|
||||
'--bundle',
|
||||
'/',
|
||||
'--no-wifi',
|
||||
], environment: <String, String>{
|
||||
], environment: const <String, String>{
|
||||
'PATH': '/usr/bin:null',
|
||||
...kDyLdLibEntry,
|
||||
})
|
||||
@@ -50,6 +59,7 @@ void main() {
|
||||
processManager: processManager,
|
||||
fileSystem: fileSystem,
|
||||
interfaceType: IOSDeviceInterface.usb,
|
||||
artifacts: artifacts,
|
||||
);
|
||||
final bool wasInstalled = await device.installApp(iosApp);
|
||||
|
||||
@@ -64,13 +74,13 @@ void main() {
|
||||
bundleDir: fileSystem.currentDirectory,
|
||||
);
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'1234',
|
||||
'--bundle',
|
||||
'/',
|
||||
], environment: <String, String>{
|
||||
], environment: const <String, String>{
|
||||
'PATH': '/usr/bin:null',
|
||||
...kDyLdLibEntry,
|
||||
})
|
||||
@@ -79,6 +89,7 @@ void main() {
|
||||
processManager: processManager,
|
||||
fileSystem: fileSystem,
|
||||
interfaceType: IOSDeviceInterface.network,
|
||||
artifacts: artifacts,
|
||||
);
|
||||
final bool wasInstalled = await device.installApp(iosApp);
|
||||
|
||||
@@ -89,19 +100,19 @@ void main() {
|
||||
testWithoutContext('IOSDevice.uninstallApp calls ios-deploy correctly', () async {
|
||||
final IOSApp iosApp = PrebuiltIOSApp(projectBundleId: 'app');
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'1234',
|
||||
'--uninstall_only',
|
||||
'--bundle_id',
|
||||
'app',
|
||||
], environment: <String, String>{
|
||||
], environment: const <String, String>{
|
||||
'PATH': '/usr/bin:null',
|
||||
...kDyLdLibEntry,
|
||||
})
|
||||
]);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager, artifacts: artifacts);
|
||||
final bool wasUninstalled = await device.uninstallApp(iosApp);
|
||||
|
||||
expect(wasUninstalled, true);
|
||||
@@ -112,8 +123,8 @@ void main() {
|
||||
testWithoutContext('catches ProcessException from ios-deploy', () async {
|
||||
final IOSApp iosApp = PrebuiltIOSApp(projectBundleId: 'app');
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
FakeCommand(command: const <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'1234',
|
||||
'--exists',
|
||||
@@ -128,7 +139,7 @@ void main() {
|
||||
throw const ProcessException('ios-deploy', <String>[]);
|
||||
})
|
||||
]);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager, artifacts: artifacts);
|
||||
final bool isAppInstalled = await device.isAppInstalled(iosApp);
|
||||
|
||||
expect(isAppInstalled, false);
|
||||
@@ -138,8 +149,8 @@ void main() {
|
||||
testWithoutContext('returns true when app is installed', () async {
|
||||
final IOSApp iosApp = PrebuiltIOSApp(projectBundleId: 'app');
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'1234',
|
||||
'--exists',
|
||||
@@ -147,12 +158,12 @@ void main() {
|
||||
'10',
|
||||
'--bundle_id',
|
||||
'app',
|
||||
], environment: <String, String>{
|
||||
], environment: const <String, String>{
|
||||
'PATH': '/usr/bin:null',
|
||||
...kDyLdLibEntry,
|
||||
}, exitCode: 0)
|
||||
]);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager, artifacts: artifacts);
|
||||
final bool isAppInstalled = await device.isAppInstalled(iosApp);
|
||||
|
||||
expect(isAppInstalled, isTrue);
|
||||
@@ -162,8 +173,8 @@ void main() {
|
||||
testWithoutContext('returns false when app is not installed', () async {
|
||||
final IOSApp iosApp = PrebuiltIOSApp(projectBundleId: 'app');
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'1234',
|
||||
'--exists',
|
||||
@@ -171,13 +182,13 @@ void main() {
|
||||
'10',
|
||||
'--bundle_id',
|
||||
'app',
|
||||
], environment: <String, String>{
|
||||
], environment: const <String, String>{
|
||||
'PATH': '/usr/bin:null',
|
||||
...kDyLdLibEntry,
|
||||
}, exitCode: 255)
|
||||
]);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager, logger: logger);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager, logger: logger, artifacts: artifacts);
|
||||
final bool isAppInstalled = await device.isAppInstalled(iosApp);
|
||||
|
||||
expect(isAppInstalled, isFalse);
|
||||
@@ -189,8 +200,8 @@ void main() {
|
||||
final IOSApp iosApp = PrebuiltIOSApp(projectBundleId: 'app');
|
||||
const String stderr = '2020-03-26 17:48:43.484 ios-deploy[21518:5501783] [ !! ] Timed out waiting for device';
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'1234',
|
||||
'--exists',
|
||||
@@ -198,14 +209,14 @@ void main() {
|
||||
'10',
|
||||
'--bundle_id',
|
||||
'app',
|
||||
], environment: <String, String>{
|
||||
], environment: const <String, String>{
|
||||
'PATH': '/usr/bin:null',
|
||||
...kDyLdLibEntry,
|
||||
}, stderr: stderr,
|
||||
exitCode: 253)
|
||||
]);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager, logger: logger);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager, logger: logger, artifacts: artifacts);
|
||||
final bool isAppInstalled = await device.isAppInstalled(iosApp);
|
||||
|
||||
expect(isAppInstalled, isFalse);
|
||||
@@ -221,8 +232,8 @@ void main() {
|
||||
bundleDir: fileSystem.currentDirectory,
|
||||
);
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
FakeCommand(command: const <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'1234',
|
||||
'--bundle',
|
||||
@@ -235,7 +246,7 @@ void main() {
|
||||
throw const ProcessException('ios-deploy', <String>[]);
|
||||
})
|
||||
]);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager, artifacts: artifacts);
|
||||
final bool wasAppInstalled = await device.installApp(iosApp);
|
||||
|
||||
expect(wasAppInstalled, false);
|
||||
@@ -244,8 +255,8 @@ void main() {
|
||||
testWithoutContext('IOSDevice.uninstallApp catches ProcessException from ios-deploy', () async {
|
||||
final IOSApp iosApp = PrebuiltIOSApp(projectBundleId: 'app');
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
FakeCommand(command: const <String>[
|
||||
'ios-deploy',
|
||||
FakeCommand(command: <String>[
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'1234',
|
||||
'--uninstall_only',
|
||||
@@ -258,7 +269,7 @@ void main() {
|
||||
throw const ProcessException('ios-deploy', <String>[]);
|
||||
})
|
||||
]);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager);
|
||||
final IOSDevice device = setUpIOSDevice(processManager: processManager, artifacts: artifacts);
|
||||
final bool wasAppUninstalled = await device.uninstallApp(iosApp);
|
||||
|
||||
expect(wasAppUninstalled, false);
|
||||
@@ -270,17 +281,20 @@ IOSDevice setUpIOSDevice({
|
||||
FileSystem fileSystem,
|
||||
Logger logger,
|
||||
IOSDeviceInterface interfaceType,
|
||||
Artifacts artifacts,
|
||||
}) {
|
||||
logger ??= BufferLogger.test();
|
||||
final FakePlatform platform = FakePlatform(
|
||||
operatingSystem: 'macos',
|
||||
environment: <String, String>{},
|
||||
);
|
||||
final MockArtifacts artifacts = MockArtifacts();
|
||||
final MockCache cache = MockCache();
|
||||
when(cache.dyLdLibEntry).thenReturn(kDyLdLibEntry.entries.first);
|
||||
when(artifacts.getArtifactPath(Artifact.iosDeploy, platform: anyNamed('platform')))
|
||||
.thenReturn('ios-deploy');
|
||||
artifacts ??= Artifacts.test();
|
||||
final Cache cache = Cache.test(
|
||||
platform: platform,
|
||||
artifacts: <ArtifactSet>[
|
||||
FakeDyldEnvironmentArtifact(),
|
||||
],
|
||||
);
|
||||
return IOSDevice(
|
||||
'1234',
|
||||
name: 'iPhone 1',
|
||||
@@ -308,6 +322,4 @@ IOSDevice setUpIOSDevice({
|
||||
);
|
||||
}
|
||||
|
||||
class MockArtifacts extends Mock implements Artifacts {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
class MockVmService extends Mock implements VmService {}
|
||||
|
||||
@@ -25,6 +25,7 @@ import 'package:vm_service/vm_service.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fake_process_manager.dart';
|
||||
import '../../src/fakes.dart';
|
||||
|
||||
List<String> _xattrArgs(FlutterProject flutterProject) {
|
||||
return <String>[
|
||||
@@ -68,6 +69,14 @@ final FakePlatform macPlatform = FakePlatform(
|
||||
);
|
||||
|
||||
void main() {
|
||||
Artifacts artifacts;
|
||||
String iosDeployPath;
|
||||
|
||||
setUp(() {
|
||||
artifacts = Artifacts.test();
|
||||
iosDeployPath = artifacts.getArtifactPath(Artifact.iosDeploy, platform: TargetPlatform.ios);
|
||||
});
|
||||
|
||||
group('IOSDevice.startApp succeeds in release mode', () {
|
||||
FileSystem fileSystem;
|
||||
FakeProcessManager processManager;
|
||||
@@ -104,6 +113,7 @@ void main() {
|
||||
fileSystem: fileSystem,
|
||||
processManager: processManager,
|
||||
logger: logger,
|
||||
artifacts: artifacts,
|
||||
);
|
||||
setUpIOSProject(fileSystem);
|
||||
final FlutterProject flutterProject = FlutterProject.fromDirectory(fileSystem.currentDirectory);
|
||||
@@ -114,7 +124,7 @@ void main() {
|
||||
processManager.addCommand(const FakeCommand(command: <String>[...kRunReleaseArgs, '-showBuildSettings']));
|
||||
processManager.addCommand(FakeCommand(
|
||||
command: <String>[
|
||||
'ios-deploy',
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'123',
|
||||
'--bundle',
|
||||
@@ -155,6 +165,7 @@ void main() {
|
||||
fileSystem: fileSystem,
|
||||
processManager: processManager,
|
||||
logger: logger,
|
||||
artifacts: artifacts,
|
||||
);
|
||||
setUpIOSProject(fileSystem);
|
||||
final FlutterProject flutterProject = FlutterProject.fromDirectory(fileSystem.currentDirectory);
|
||||
@@ -176,7 +187,7 @@ void main() {
|
||||
));
|
||||
processManager.addCommand(FakeCommand(
|
||||
command: <String>[
|
||||
'ios-deploy',
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'123',
|
||||
'--bundle',
|
||||
@@ -228,6 +239,7 @@ void main() {
|
||||
fileSystem: fileSystem,
|
||||
processManager: processManager,
|
||||
logger: logger,
|
||||
artifacts: artifacts,
|
||||
);
|
||||
setUpIOSProject(fileSystem);
|
||||
final FlutterProject flutterProject = FlutterProject.fromDirectory(fileSystem.currentDirectory);
|
||||
@@ -250,7 +262,7 @@ void main() {
|
||||
));
|
||||
processManager.addCommand(FakeCommand(
|
||||
command: <String>[
|
||||
'ios-deploy',
|
||||
iosDeployPath,
|
||||
'--id',
|
||||
'123',
|
||||
'--bundle',
|
||||
@@ -306,17 +318,16 @@ IOSDevice setUpIOSDevice({
|
||||
FileSystem fileSystem,
|
||||
Logger logger,
|
||||
ProcessManager processManager,
|
||||
Artifacts artifacts,
|
||||
}) {
|
||||
const MapEntry<String, String> dyldLibraryEntry = MapEntry<String, String>(
|
||||
'DYLD_LIBRARY_PATH',
|
||||
'/path/to/libraries',
|
||||
artifacts ??= Artifacts.test();
|
||||
final Cache cache = Cache.test(
|
||||
artifacts: <ArtifactSet>[
|
||||
FakeDyldEnvironmentArtifact(),
|
||||
],
|
||||
);
|
||||
final MockCache cache = MockCache();
|
||||
final MockArtifacts artifacts = MockArtifacts();
|
||||
|
||||
logger ??= BufferLogger.test();
|
||||
when(cache.dyLdLibEntry).thenReturn(dyldLibraryEntry);
|
||||
when(artifacts.getArtifactPath(Artifact.iosDeploy, platform: anyNamed('platform')))
|
||||
.thenReturn('ios-deploy');
|
||||
return IOSDevice('123',
|
||||
name: 'iPhone 1',
|
||||
sdkVersion: sdkVersion,
|
||||
@@ -343,8 +354,6 @@ IOSDevice setUpIOSDevice({
|
||||
);
|
||||
}
|
||||
|
||||
class MockArtifacts extends Mock implements Artifacts {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
class MockXcode extends Mock implements Xcode {}
|
||||
class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {}
|
||||
class MockVmService extends Mock implements VmService {}
|
||||
|
||||
@@ -32,7 +32,7 @@ import '../../src/fakes.dart';
|
||||
|
||||
const FakeCommand kDeployCommand = FakeCommand(
|
||||
command: <String>[
|
||||
'ios-deploy',
|
||||
'Artifact.iosDeploy.TargetPlatform.ios',
|
||||
'--id',
|
||||
'123',
|
||||
'--bundle',
|
||||
@@ -48,7 +48,7 @@ const FakeCommand kDeployCommand = FakeCommand(
|
||||
// The command used to actually launch the app with args in release/profile.
|
||||
const FakeCommand kLaunchReleaseCommand = FakeCommand(
|
||||
command: <String>[
|
||||
'ios-deploy',
|
||||
'Artifact.iosDeploy.TargetPlatform.ios',
|
||||
'--id',
|
||||
'123',
|
||||
'--bundle',
|
||||
@@ -67,7 +67,7 @@ const FakeCommand kLaunchReleaseCommand = FakeCommand(
|
||||
|
||||
// The command used to just launch the app with args in debug.
|
||||
const FakeCommand kLaunchDebugCommand = FakeCommand(command: <String>[
|
||||
'ios-deploy',
|
||||
'Artifact.iosDeploy.TargetPlatform.ios',
|
||||
'--id',
|
||||
'123',
|
||||
'--bundle',
|
||||
@@ -87,7 +87,7 @@ const FakeCommand kAttachDebuggerCommand = FakeCommand(command: <String>[
|
||||
'-t',
|
||||
'0',
|
||||
'/dev/null',
|
||||
'ios-deploy',
|
||||
'Artifact.iosDeploy.TargetPlatform.ios',
|
||||
'--id',
|
||||
'123',
|
||||
'--bundle',
|
||||
@@ -382,7 +382,7 @@ void main() {
|
||||
'-t',
|
||||
'0',
|
||||
'/dev/null',
|
||||
'ios-deploy',
|
||||
'Artifact.iosDeploy.TargetPlatform.ios',
|
||||
'--id',
|
||||
'123',
|
||||
'--bundle',
|
||||
@@ -482,20 +482,20 @@ IOSDevice setUpIOSDevice({
|
||||
ProcessManager processManager,
|
||||
VmServiceConnector vmServiceConnector,
|
||||
}) {
|
||||
const MapEntry<String, String> dyldLibraryEntry = MapEntry<String, String>(
|
||||
'DYLD_LIBRARY_PATH',
|
||||
'/path/to/libraries',
|
||||
);
|
||||
final MockCache cache = MockCache();
|
||||
final MockArtifacts artifacts = MockArtifacts();
|
||||
final Artifacts artifacts = Artifacts.test();
|
||||
final FakePlatform macPlatform = FakePlatform(
|
||||
operatingSystem: 'macos',
|
||||
environment: <String, String>{},
|
||||
);
|
||||
|
||||
final Cache cache = Cache.test(
|
||||
platform: macPlatform,
|
||||
artifacts: <ArtifactSet>[
|
||||
FakeDyldEnvironmentArtifact(),
|
||||
],
|
||||
);
|
||||
|
||||
vmServiceConnector ??= (String uri, {Log log}) async => MockVmService();
|
||||
when(cache.dyLdLibEntry).thenReturn(dyldLibraryEntry);
|
||||
when(artifacts.getArtifactPath(Artifact.iosDeploy, platform: anyNamed('platform')))
|
||||
.thenReturn('ios-deploy');
|
||||
return IOSDevice('123',
|
||||
name: 'iPhone 1',
|
||||
sdkVersion: sdkVersion,
|
||||
@@ -526,7 +526,5 @@ class MockDevicePortForwarder extends Mock implements DevicePortForwarder {}
|
||||
class MockDeviceLogReader extends Mock implements DeviceLogReader {}
|
||||
class MockUsage extends Mock implements Usage {}
|
||||
class MockMDnsObservatoryDiscovery extends Mock implements MDnsObservatoryDiscovery {}
|
||||
class MockArtifacts extends Mock implements Artifacts {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
class MockVmService extends Mock implements VmService {}
|
||||
class MockDartDevelopmentService extends Mock implements DartDevelopmentService {}
|
||||
|
||||
@@ -11,7 +11,6 @@ import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/process.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/ios/devices.dart';
|
||||
import 'package:flutter_tools/src/ios/mac.dart';
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
@@ -22,14 +21,13 @@ import 'package:process/process.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
|
||||
final Generator _kNoColorTerminalPlatform = () => FakePlatform(stdoutSupportsAnsi: false);
|
||||
final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
|
||||
Platform: _kNoColorTerminalPlatform,
|
||||
};
|
||||
|
||||
class MockArtifacts extends Mock implements Artifacts {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {}
|
||||
class MockIosProject extends Mock implements IosProject {}
|
||||
@@ -42,18 +40,15 @@ void main() {
|
||||
});
|
||||
|
||||
group('IMobileDevice', () {
|
||||
final String libimobiledevicePath = globals.fs.path.join('bin', 'cache', 'artifacts', 'libimobiledevice');
|
||||
final String idevicescreenshotPath = globals.fs.path.join(libimobiledevicePath, 'idevicescreenshot');
|
||||
MockArtifacts mockArtifacts;
|
||||
MockCache mockCache;
|
||||
Artifacts artifacts;
|
||||
Cache cache;
|
||||
|
||||
setUp(() {
|
||||
mockCache = MockCache();
|
||||
mockArtifacts = MockArtifacts();
|
||||
when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath);
|
||||
when(mockCache.dyLdLibEntry).thenReturn(
|
||||
MapEntry<String, String>('DYLD_LIBRARY_PATH', libimobiledevicePath)
|
||||
);
|
||||
artifacts = Artifacts.test();
|
||||
cache = Cache.test(
|
||||
artifacts: <ArtifactSet>[
|
||||
FakeDyldEnvironmentArtifact(),
|
||||
]);
|
||||
});
|
||||
|
||||
group('screenshot', () {
|
||||
@@ -63,19 +58,19 @@ void main() {
|
||||
setUp(() {
|
||||
mockProcessManager = MockProcessManager();
|
||||
outputFile = MemoryFileSystem.test().file('image.png');
|
||||
when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath);
|
||||
// when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath);
|
||||
});
|
||||
|
||||
testWithoutContext('error if idevicescreenshot is not installed', () async {
|
||||
// Let `idevicescreenshot` fail with exit code 1.
|
||||
when(mockProcessManager.run(<String>[idevicescreenshotPath, outputFile.path],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
|
||||
when(mockProcessManager.run(<String>['Artifact.idevicescreenshot.TargetPlatform.ios', outputFile.path],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': 'Artifact.idevicescreenshot.TargetPlatform.ios'},
|
||||
workingDirectory: null,
|
||||
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(4, 1, '', '')));
|
||||
|
||||
final IMobileDevice iMobileDevice = IMobileDevice(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
artifacts: artifacts,
|
||||
cache: cache,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
@@ -92,8 +87,8 @@ void main() {
|
||||
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
|
||||
|
||||
final IMobileDevice iMobileDevice = IMobileDevice(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
artifacts: artifacts,
|
||||
cache: cache,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
@@ -103,8 +98,8 @@ void main() {
|
||||
'1234',
|
||||
IOSDeviceInterface.usb,
|
||||
);
|
||||
verify(mockProcessManager.run(<String>[idevicescreenshotPath, outputFile.path, '--udid', '1234'],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
|
||||
verify(mockProcessManager.run(<String>['Artifact.idevicescreenshot.TargetPlatform.ios', outputFile.path, '--udid', '1234'],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': '/path/to/libraries'},
|
||||
workingDirectory: null,
|
||||
));
|
||||
});
|
||||
@@ -114,8 +109,8 @@ void main() {
|
||||
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
|
||||
|
||||
final IMobileDevice iMobileDevice = IMobileDevice(
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
artifacts: artifacts,
|
||||
cache: cache,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
@@ -125,8 +120,8 @@ void main() {
|
||||
'1234',
|
||||
IOSDeviceInterface.network,
|
||||
);
|
||||
verify(mockProcessManager.run(<String>[idevicescreenshotPath, outputFile.path, '--udid', '1234', '--network'],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
|
||||
verify(mockProcessManager.run(<String>['Artifact.idevicescreenshot.TargetPlatform.ios', outputFile.path, '--udid', '1234', '--network'],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': '/path/to/libraries'},
|
||||
workingDirectory: null,
|
||||
));
|
||||
});
|
||||
|
||||
@@ -79,8 +79,8 @@ void main() {
|
||||
logger: logger,
|
||||
xcode: mockXcode,
|
||||
platform: null,
|
||||
artifacts: MockArtifacts(),
|
||||
cache: MockCache(),
|
||||
artifacts: Artifacts.test(),
|
||||
cache: Cache.test(),
|
||||
iproxy: IProxy.test(logger: logger, processManager: processManager),
|
||||
);
|
||||
});
|
||||
@@ -338,20 +338,16 @@ void main() {
|
||||
group('xcdevice', () {
|
||||
XCDevice xcdevice;
|
||||
MockXcode mockXcode;
|
||||
MockArtifacts mockArtifacts;
|
||||
MockCache mockCache;
|
||||
|
||||
setUp(() {
|
||||
mockXcode = MockXcode();
|
||||
mockArtifacts = MockArtifacts();
|
||||
mockCache = MockCache();
|
||||
xcdevice = XCDevice(
|
||||
processManager: fakeProcessManager,
|
||||
logger: logger,
|
||||
xcode: mockXcode,
|
||||
platform: null,
|
||||
artifacts: mockArtifacts,
|
||||
cache: mockCache,
|
||||
artifacts: Artifacts.test(),
|
||||
cache: Cache.test(),
|
||||
iproxy: IProxy.test(logger: logger, processManager: fakeProcessManager),
|
||||
);
|
||||
});
|
||||
@@ -843,5 +839,3 @@ class MockXcode extends Mock implements Xcode {}
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {}
|
||||
class MockPlatform extends Mock implements Platform {}
|
||||
class MockArtifacts extends Mock implements Artifacts {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
|
||||
/// A fake implementation of the [DeviceLogReader].
|
||||
@@ -40,3 +41,22 @@ class FakeDeviceLogReader extends DeviceLogReader {
|
||||
await _linesController.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// Environment with DYLD_LIBRARY_PATH=/path/to/libraries
|
||||
class FakeDyldEnvironmentArtifact extends ArtifactSet {
|
||||
FakeDyldEnvironmentArtifact() : super(DevelopmentArtifact.iOS);
|
||||
@override
|
||||
Map<String, String> get environment => <String, String>{
|
||||
'DYLD_LIBRARY_PATH': '/path/to/libraries'
|
||||
};
|
||||
|
||||
@override
|
||||
Future<bool> isUpToDate() => Future<bool>.value(true);
|
||||
|
||||
@override
|
||||
String get name => 'fake';
|
||||
|
||||
@override
|
||||
Future<void> update(ArtifactUpdater artifactUpdater) async {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user