Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit b8573eb

Browse files
committed
Added a unit test for changing the macOS deployment version.
1 parent 2b9fcd0 commit b8573eb

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

script/tool/lib/src/create_all_plugins_app_command.dart

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import 'common/repository_package.dart';
1515

1616
const String _outputDirectoryFlag = 'output-dir';
1717

18+
const int _exitUpdateMacosPodfileFailed = 3;
19+
const int _exitUpdateMacosPbxprojFailed = 4;
20+
1821
/// A command to create an application that builds all in a single application.
1922
class CreateAllPluginsAppCommand extends PackageCommand {
2023
/// Creates an instance of the builder command.
@@ -270,12 +273,6 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)}
270273
}
271274

272275
Future<int> _genNativeBuildFiles() async {
273-
// Only run on macOS.
274-
// Other platforms don't need generation of additional files.
275-
if (!io.Platform.isMacOS) {
276-
return 0;
277-
}
278-
279276
final io.ProcessResult result = io.Process.runSync(
280277
flutterCommand,
281278
<String>[
@@ -291,15 +288,10 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)}
291288
}
292289

293290
Future<void> _updateMacosPodfile() async {
294-
// Only change the macOS deployment target if the host platform is macOS.
295-
if (!io.Platform.isMacOS) {
296-
return;
297-
}
298-
299291
final File podfileFile =
300292
app.platformDirectory(FlutterPlatform.macos).childFile('Podfile');
301293
if (!podfileFile.existsSync()) {
302-
throw ToolExit(64);
294+
throw ToolExit(_exitUpdateMacosPodfileFailed);
303295
}
304296

305297
final StringBuffer newPodfile = StringBuffer();
@@ -315,17 +307,12 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)}
315307
}
316308

317309
Future<void> _updateMacosPbxproj() async {
318-
// Only change the macOS deployment target if the host platform is macOS.
319-
if (!io.Platform.isMacOS) {
320-
return;
321-
}
322-
323310
final File pbxprojFile = app
324311
.platformDirectory(FlutterPlatform.macos)
325312
.childDirectory('Runner.xcodeproj')
326313
.childFile('project.pbxproj');
327314
if (!pbxprojFile.existsSync()) {
328-
throw ToolExit(64);
315+
throw ToolExit(_exitUpdateMacosPbxprojFailed);
329316
}
330317

331318
final StringBuffer newPbxproj = StringBuffer();

script/tool/test/create_all_plugins_app_command_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,31 @@ void main() {
103103
baselinePubspec.environment?[dartSdkKey]);
104104
});
105105

106+
test('macOS deployment target is modified', () async {
107+
await runCapturingPrint(runner, <String>['all-plugins-app']);
108+
109+
final List<String> podfile = command.app
110+
.platformDirectory(FlutterPlatform.macos)
111+
.childFile('Podfile')
112+
.readAsLinesSync();
113+
final List<String> pbxproj = command.app
114+
.platformDirectory(FlutterPlatform.macos)
115+
.childDirectory('Runner.xcodeproj')
116+
.childFile('project.pbxproj')
117+
.readAsLinesSync();
118+
119+
expect(
120+
podfile,
121+
everyElement((String line) =>
122+
!line.contains('platform :osx') || line.contains("'10.15'")));
123+
124+
expect(
125+
pbxproj,
126+
everyElement((String line) =>
127+
!line.contains('MACOSX_DEPLOYMENT_TARGET') ||
128+
line.contains('10.15')));
129+
});
130+
106131
test('handles --output-dir', () async {
107132
createFakePlugin('plugina', packagesDir);
108133

0 commit comments

Comments
 (0)