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

Commit 45ea1cf

Browse files
committed
Add additional tests to ensure the mocked out flutter pub get call is correct.
1 parent cc6277f commit 45ea1cf

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

script/tool/lib/src/create_all_plugins_app_command.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:io' as io;
66

77
import 'package:file/file.dart';
88
import 'package:path/path.dart' as p;
9+
import 'package:platform/platform.dart';
910
import 'package:pub_semver/pub_semver.dart';
1011
import 'package:pubspec_parse/pubspec_parse.dart';
1112

@@ -27,7 +28,8 @@ class CreateAllPluginsAppCommand extends PackageCommand {
2728
Directory packagesDir, {
2829
ProcessRunner processRunner = const ProcessRunner(),
2930
Directory? pluginsRoot,
30-
}) : super(packagesDir, processRunner: processRunner) {
31+
Platform platform = const LocalPlatform(),
32+
}) : super(packagesDir, processRunner: processRunner, platform: platform) {
3133
final Directory defaultDir =
3234
pluginsRoot ?? packagesDir.fileSystem.currentDirectory;
3335
argParser.addOption(_outputDirectoryFlag,

script/tool/test/create_all_plugins_app_command_test.dart

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ import 'dart:io' as io;
77
import 'package:args/command_runner.dart';
88
import 'package:file/file.dart';
99
import 'package:file/local.dart';
10+
import 'package:flutter_plugin_tools/src/common/core.dart';
1011
import 'package:flutter_plugin_tools/src/create_all_plugins_app_command.dart';
1112
import 'package:platform/platform.dart';
1213
import 'package:test/test.dart';
1314

15+
import 'mocks.dart';
1416
import 'util.dart';
1517

1618
void 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

Comments
 (0)