@@ -7,17 +7,20 @@ import 'dart:io' as io;
7
7
import 'package:args/command_runner.dart' ;
8
8
import 'package:file/file.dart' ;
9
9
import 'package:file/local.dart' ;
10
+ import 'package:flutter_plugin_tools/src/common/core.dart' ;
10
11
import 'package:flutter_plugin_tools/src/create_all_plugins_app_command.dart' ;
11
12
import 'package:platform/platform.dart' ;
12
13
import 'package:test/test.dart' ;
13
14
15
+ import 'mocks.dart' ;
14
16
import 'util.dart' ;
15
17
16
18
void main () {
17
19
group ('$CreateAllPluginsAppCommand ' , () {
18
20
late CommandRunner <void > runner;
19
21
late CreateAllPluginsAppCommand command;
20
22
late FileSystem fileSystem;
23
+ late MockPlatform mockPlatform;
21
24
late Directory testRoot;
22
25
late Directory packagesDir;
23
26
late RecordingProcessRunner processRunner;
@@ -27,6 +30,7 @@ void main() {
27
30
// has to use the real filesystem. Put everything possible in a unique
28
31
// temporary to minimize effect on the host system.
29
32
fileSystem = const LocalFileSystem ();
33
+ mockPlatform = MockPlatform ();
30
34
testRoot = fileSystem.systemTempDirectory.createTempSync ();
31
35
packagesDir = testRoot.childDirectory ('packages' );
32
36
processRunner = RecordingProcessRunner ();
@@ -35,6 +39,7 @@ void main() {
35
39
packagesDir,
36
40
processRunner: processRunner,
37
41
pluginsRoot: testRoot,
42
+ platform: mockPlatform,
38
43
);
39
44
runner = CommandRunner <void >(
40
45
'create_all_test' , 'Test for $CreateAllPluginsAppCommand ' );
@@ -107,6 +112,15 @@ void main() {
107
112
});
108
113
109
114
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
+
110
124
await runCapturingPrint (runner, < String > ['all-plugins-app' ]);
111
125
final List <String > podfile = command.app
112
126
.platformDirectory (FlutterPlatform .macos)
@@ -118,10 +132,21 @@ void main() {
118
132
everyElement ((String line) =>
119
133
! line.contains ('platform :osx' ) || line.contains ("'10.15'" )));
120
134
},
121
- // Podfile is only generated on macOS.
135
+ // Podfile is only generated (and thus only edited) on macOS.
122
136
skip: ! io.Platform .isMacOS);
123
137
124
138
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
+
125
150
await runCapturingPrint (runner, < String > ['all-plugins-app' ]);
126
151
final List <String > pbxproj = command.app
127
152
.platformDirectory (FlutterPlatform .macos)
@@ -136,6 +161,42 @@ void main() {
136
161
line.contains ('10.15' )));
137
162
});
138
163
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
+
139
200
test ('handles --output-dir' , () async {
140
201
createFakePlugin ('plugina' , packagesDir);
141
202
0 commit comments