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