Make the SwiftPM integration tests more idiomatic (#157971)
I recommend reviewing with [whitespace changes disabled](https://github.com/flutter/flutter/pull/157971/files?diff=split&w=1). Changes: 1. Replaces `expect(string.contains('foo'), isTrue)` with `expect(string, contains('foo'))` 2. Replaces `try/finally` with `addTearDown` Follow-up to: https://github.com/flutter/flutter/pull/157482#discussion_r1813939657
This commit is contained in:
parent
f86b777215
commit
49ccfb7302
@ -29,7 +29,15 @@ void main() {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_enabled.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
|
||||
addTearDown(() async {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
});
|
||||
|
||||
// Create and build an app using the CocoaPods version of
|
||||
// integration_test.
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
@ -212,13 +220,6 @@ void main() {
|
||||
cocoaPodsPlugin: integrationTestPlugin,
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
}
|
||||
|
||||
@ -226,7 +227,15 @@ void main() {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_build_framework.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
|
||||
addTearDown(() async {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
});
|
||||
|
||||
// Create and build an app using the Swift Package Manager version of
|
||||
// integration_test.
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
@ -294,20 +303,21 @@ void main() {
|
||||
.existsSync(),
|
||||
isTrue,
|
||||
);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
|
||||
test('Caches build targets between builds with Swift Package Manager on $platformName', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_caching.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
|
||||
addTearDown(() async {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
});
|
||||
|
||||
// Create and build an app using the Swift Package Manager version of
|
||||
// integration_test.
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
@ -362,14 +372,6 @@ void main() {
|
||||
'Starting due to',
|
||||
],
|
||||
);
|
||||
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
}
|
||||
|
||||
@ -377,7 +379,15 @@ void main() {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_build_framework_module.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
|
||||
addTearDown(() async {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
});
|
||||
|
||||
// Create and build module and framework using the CocoaPods version of
|
||||
// integration_test even though Swift Package Manager is enabled.
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
@ -425,8 +435,8 @@ void main() {
|
||||
.childFile('project.pbxproj');
|
||||
expect(pbxprojFile.existsSync(), isTrue);
|
||||
expect(
|
||||
pbxprojFile.readAsStringSync().contains('FlutterGeneratedPluginSwiftPackage'),
|
||||
isFalse,
|
||||
pbxprojFile.readAsStringSync(),
|
||||
isNot(contains('FlutterGeneratedPluginSwiftPackage')),
|
||||
);
|
||||
final File xcschemeFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
@ -437,8 +447,8 @@ void main() {
|
||||
.childFile('Runner.xcscheme');
|
||||
expect(xcschemeFile.existsSync(), isTrue);
|
||||
expect(
|
||||
xcschemeFile.readAsStringSync().contains('Run Prepare Flutter Framework Script'),
|
||||
isFalse,
|
||||
xcschemeFile.readAsStringSync(),
|
||||
isNot(contains('Run Prepare Flutter Framework Script')),
|
||||
);
|
||||
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
@ -467,20 +477,21 @@ void main() {
|
||||
.existsSync(),
|
||||
isTrue,
|
||||
);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
|
||||
test('Build ios-framework with non module app uses CocoaPods', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_build_framework_non_module.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
|
||||
addTearDown(() async {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
});
|
||||
|
||||
// Create and build a regular app and framework using the CocoaPods version of
|
||||
// integration_test even though Swift Package Manager is enabled.
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
@ -563,20 +574,21 @@ void main() {
|
||||
flutterPluginsDependenciesFile.readAsStringSync(),
|
||||
contains('"swift_package_manager_enabled":false'),
|
||||
);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
|
||||
test("Generated Swift package uses iOS's project minimum deployment", () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_minimum_deployment_ios.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
|
||||
addTearDown(() async {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
});
|
||||
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
final String appDirectoryPath = await SwiftPackageManagerUtils.createApp(
|
||||
flutterBin,
|
||||
@ -629,20 +641,21 @@ void main() {
|
||||
''';
|
||||
|
||||
expect(generatedManifest.contains(expected), isTrue);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
|
||||
test("Generated Swift package uses macOS's project minimum deployment", () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_minimum_deployment_macos.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
|
||||
addTearDown(() async {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
});
|
||||
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
final String appDirectoryPath = await SwiftPackageManagerUtils.createApp(
|
||||
flutterBin,
|
||||
@ -694,21 +707,22 @@ void main() {
|
||||
],
|
||||
''';
|
||||
|
||||
expect(generatedManifest.contains(expected), isTrue);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
expect(generatedManifest, contains(expected));
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
|
||||
test('Removing the last plugin updates the generated Swift package', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_remove_last_plugin.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
|
||||
addTearDown(() async {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
});
|
||||
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
@ -778,22 +792,23 @@ void main() {
|
||||
generatedManifest = generatedManifestFile.readAsStringSync();
|
||||
const String emptyDependencies = 'dependencies: [\n \n ],\n';
|
||||
|
||||
expect(generatedManifest.contains(generatedSwiftDependency), isFalse);
|
||||
expect(generatedManifest.contains(emptyDependencies), isTrue);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
expect(generatedManifest, isNot(contains(generatedSwiftDependency)));
|
||||
expect(generatedManifest, contains(emptyDependencies));
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
|
||||
test('Migrated app builds after Swift Package Manager is turned off', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_turned_off.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
|
||||
addTearDown(() async {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
});
|
||||
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
@ -859,8 +874,8 @@ void main() {
|
||||
],
|
||||
''';
|
||||
|
||||
expect(xcodeProject.contains('FlutterGeneratedPluginSwiftPackage'), isTrue);
|
||||
expect(generatedManifest.contains(generatedSwiftDependency), isTrue);
|
||||
expect(xcodeProject, contains('FlutterGeneratedPluginSwiftPackage'));
|
||||
expect(generatedManifest, contains(generatedSwiftDependency));
|
||||
|
||||
// Disable Swift Package Manager and do a clean re-build of the app.
|
||||
// The build should succeed.
|
||||
@ -886,16 +901,9 @@ void main() {
|
||||
generatedManifest = generatedManifestFile.readAsStringSync();
|
||||
const String emptyDependencies = 'dependencies: [\n \n ],\n';
|
||||
|
||||
expect(xcodeProject.contains('FlutterGeneratedPluginSwiftPackage'), isTrue);
|
||||
expect(generatedManifest.contains('integration_test'), isFalse);
|
||||
expect(generatedManifest.contains(emptyDependencies), isTrue);
|
||||
expect(xcodeProject, contains('FlutterGeneratedPluginSwiftPackage'));
|
||||
expect(generatedManifest, isNot(contains('integration_test')));
|
||||
expect(generatedManifest, contains(emptyDependencies));
|
||||
expect(cocoaPodsPluginFramework.existsSync(), isTrue);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user