@@ -7,17 +7,20 @@ import 'dart:io' as io;
77import 'package:args/command_runner.dart' ;
88import 'package:file/file.dart' ;
99import 'package:file/local.dart' ;
10+ import 'package:flutter_plugin_tools/src/common/core.dart' ;
1011import 'package:flutter_plugin_tools/src/create_all_plugins_app_command.dart' ;
1112import 'package:platform/platform.dart' ;
1213import 'package:test/test.dart' ;
1314
15+ import 'mocks.dart' ;
1416import 'util.dart' ;
1517
1618void main () {
1719 group ('$CreateAllPluginsAppCommand ' , () {
1820 late CommandRunner <void > runner;
1921 late CreateAllPluginsAppCommand command;
2022 late FileSystem fileSystem;
23+ late MockPlatform mockPlatform;
2124 late Directory testRoot;
2225 late Directory packagesDir;
2326 late RecordingProcessRunner processRunner;
@@ -27,6 +30,7 @@ void main() {
2730 // has to use the real filesystem. Put everything possible in a unique
2831 // temporary to minimize effect on the host system.
2932 fileSystem = const LocalFileSystem ();
33+ mockPlatform = MockPlatform ();
3034 testRoot = fileSystem.systemTempDirectory.createTempSync ();
3135 packagesDir = testRoot.childDirectory ('packages' );
3236 processRunner = RecordingProcessRunner ();
@@ -35,6 +39,7 @@ void main() {
3539 packagesDir,
3640 processRunner: processRunner,
3741 pluginsRoot: testRoot,
42+ platform: mockPlatform,
3843 );
3944 runner = CommandRunner <void >(
4045 'create_all_test' , 'Test for $CreateAllPluginsAppCommand ' );
@@ -107,6 +112,15 @@ void main() {
107112 });
108113
109114 test ('macOS deployment target is modified in Podfile' , () async {
115+ final RepositoryPackage plugin = createFakePlugin ('plugina' , packagesDir);
116+ final File podfileFile =
117+ plugin.directory.childDirectory ('macos' ).childFile ('Podfile' );
118+ podfileFile.createSync (recursive: true );
119+ podfileFile.writeAsStringSync ("""
120+ platform :osx, '10.11'
121+ # some other line
122+ """ );
123+
110124 await runCapturingPrint (runner, < String > ['all-plugins-app' ]);
111125 final List <String > podfile = command.app
112126 .platformDirectory (FlutterPlatform .macos)
@@ -118,10 +132,21 @@ void main() {
118132 everyElement ((String line) =>
119133 ! line.contains ('platform :osx' ) || line.contains ("'10.15'" )));
120134 },
121- // Podfile is only generated on macOS.
135+ // Podfile is only generated (and thus only edited) on macOS.
122136 skip: ! io.Platform .isMacOS);
123137
124138 test ('macOS deployment target is modified in pbxproj' , () async {
139+ final RepositoryPackage plugin = createFakePlugin ('plugina' , packagesDir);
140+ final File pbxprojFile = plugin.directory
141+ .childDirectory ('Runner.xcodeproj' )
142+ .childFile ('project.pbxproj' );
143+ pbxprojFile.createSync (recursive: true );
144+ pbxprojFile.writeAsStringSync ('''
145+ MACOSX_DEPLOYMENT_TARGET = 10.11;
146+ /* some other line */
147+ MACOSX_DEPLOYMENT_TARGET = 10.11;
148+ ''' );
149+
125150 await runCapturingPrint (runner, < String > ['all-plugins-app' ]);
126151 final List <String > pbxproj = command.app
127152 .platformDirectory (FlutterPlatform .macos)
@@ -136,6 +161,42 @@ void main() {
136161 line.contains ('10.15' )));
137162 });
138163
164+ test ('calls flutter pub get' , () async {
165+ createFakePlugin ('plugina' , packagesDir);
166+
167+ await runCapturingPrint (runner, < String > ['all-plugins-app' ]);
168+
169+ expect (
170+ processRunner.recordedCalls,
171+ orderedEquals (< ProcessCall > [
172+ ProcessCall (
173+ getFlutterCommand (mockPlatform),
174+ const < String > ['pub' , 'get' ],
175+ testRoot.childDirectory ('all_plugins' ).path),
176+ ]));
177+ });
178+
179+ test ('fails if flutter pub get fails' , () async {
180+ createFakePlugin ('plugina' , packagesDir);
181+
182+ processRunner
183+ .mockProcessesForExecutable[getFlutterCommand (mockPlatform)] =
184+ < io.Process > [MockProcess (exitCode: 1 )];
185+ Error ? commandError;
186+ final List <String > output = await runCapturingPrint (
187+ runner, < String > ['all-plugins-app' ], errorHandler: (Error e) {
188+ commandError = e;
189+ });
190+
191+ expect (commandError, isA <ToolExit >());
192+ expect (
193+ output,
194+ containsAllInOrder (< Matcher > [
195+ contains (
196+ "Failed to generate native build files via 'flutter pub get'" ),
197+ ]));
198+ });
199+
139200 test ('handles --output-dir' , () async {
140201 createFakePlugin ('plugina' , packagesDir);
141202
0 commit comments