forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpodspec_check_command_test.dart
More file actions
562 lines (491 loc) · 17.4 KB
/
podspec_check_command_test.dart
File metadata and controls
562 lines (491 loc) · 17.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_plugin_tools/src/common/core.dart';
import 'package:flutter_plugin_tools/src/common/plugin_utils.dart';
import 'package:flutter_plugin_tools/src/podspec_check_command.dart';
import 'package:platform/platform.dart';
import 'package:test/test.dart';
import 'mocks.dart';
import 'util.dart';
/// Adds a fake podspec to [plugin]'s [platform] directory.
///
/// If [includeSwiftWorkaround] is set, the xcconfig additions to make Swift
/// libraries work in apps that have no Swift will be included. If
/// [scopeSwiftWorkaround] is set, it will be specific to the iOS configuration.
void _writeFakePodspec(
RepositoryPackage plugin,
String platform, {
bool includeSwiftWorkaround = false,
bool scopeSwiftWorkaround = false,
bool includePrivacyManifest = false,
}) {
final String pluginName = plugin.directory.basename;
final File file = plugin.directory
.childDirectory(platform)
.childFile('$pluginName.podspec');
final String swiftWorkaround = includeSwiftWorkaround
? '''
s.${scopeSwiftWorkaround ? 'ios.' : ''}xcconfig = {
'LIBRARY_SEARCH_PATHS' => '\$(TOOLCHAIN_DIR)/usr/lib/swift/\$(PLATFORM_NAME)/ \$(SDKROOT)/usr/lib/swift',
'LD_RUNPATH_SEARCH_PATHS' => '/usr/lib/swift',
}
'''
: '';
final String privacyManifest = includePrivacyManifest
? '''
s.resource_bundles = {'$pluginName' => ['Resources/PrivacyInfo.xcprivacy']}
'''
: '';
file.createSync(recursive: true);
file.writeAsStringSync('''
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'shared_preferences_foundation'
s.version = '0.0.1'
s.summary = 'iOS and macOS implementation of the shared_preferences plugin.'
s.description = <<-DESC
Wraps NSUserDefaults, providing a persistent store for simple key-value pairs.
DESC
s.homepage = 'https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_foundation'
s.license = { :type => 'BSD', :file => '../LICENSE' }
s.author = { 'Flutter Team' => '[email protected]' }
s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_foundation' }
s.source_files = 'Classes/**/*'
s.ios.dependency 'Flutter'
s.osx.dependency 'FlutterMacOS'
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.11'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
$swiftWorkaround
s.swift_version = '5.0'
$privacyManifest
end
''');
}
void main() {
group('PodspecCheckCommand', () {
FileSystem fileSystem;
late Directory packagesDir;
late CommandRunner<void> runner;
late MockPlatform mockPlatform;
late RecordingProcessRunner processRunner;
setUp(() {
fileSystem = MemoryFileSystem();
packagesDir = createPackagesDirectory(fileSystem: fileSystem);
mockPlatform = MockPlatform(isMacOS: true);
processRunner = RecordingProcessRunner();
final PodspecCheckCommand command = PodspecCheckCommand(
packagesDir,
processRunner: processRunner,
platform: mockPlatform,
);
runner =
CommandRunner<void>('podspec_test', 'Test for $PodspecCheckCommand');
runner.addCommand(command);
});
test('only runs on macOS', () async {
createFakePlugin('plugin1', packagesDir,
extraFiles: <String>['plugin1.podspec']);
mockPlatform.isMacOS = false;
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['podspec-check'], errorHandler: (Error e) {
commandError = e;
});
expect(commandError, isA<ToolExit>());
expect(
processRunner.recordedCalls,
equals(<ProcessCall>[]),
);
expect(
output,
containsAllInOrder(
<Matcher>[contains('only supported on macOS')],
));
});
test('runs pod lib lint on a podspec', () async {
final RepositoryPackage plugin = createFakePlugin(
'plugin1',
packagesDir,
extraFiles: <String>[
'bogus.dart', // Ignore non-podspecs.
],
);
_writeFakePodspec(plugin, 'ios');
processRunner.mockProcessesForExecutable['pod'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(stdout: 'Foo', stderr: 'Bar')),
FakeProcessInfo(MockProcess()),
];
final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall('which', const <String>['pod'], packagesDir.path),
ProcessCall(
'pod',
<String>[
'lib',
'lint',
plugin
.platformDirectory(FlutterPlatform.ios)
.childFile('plugin1.podspec')
.path,
'--configuration=Debug',
'--skip-tests',
'--use-modular-headers',
'--use-libraries'
],
packagesDir.path),
ProcessCall(
'pod',
<String>[
'lib',
'lint',
plugin
.platformDirectory(FlutterPlatform.ios)
.childFile('plugin1.podspec')
.path,
'--configuration=Debug',
'--skip-tests',
'--use-modular-headers',
],
packagesDir.path),
]),
);
expect(output, contains('Linting plugin1.podspec'));
expect(output, contains('Foo'));
expect(output, contains('Bar'));
});
test('skips shim podspecs for the Flutter framework', () async {
final RepositoryPackage plugin = createFakePlugin(
'plugin1',
packagesDir,
extraFiles: <String>[
'example/ios/Flutter/Flutter.podspec',
'example/macos/Flutter/ephemeral/FlutterMacOS.podspec',
],
);
_writeFakePodspec(plugin, 'macos');
final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);
expect(output, isNot(contains('FlutterMacOS.podspec')));
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall('which', const <String>['pod'], packagesDir.path),
ProcessCall(
'pod',
<String>[
'lib',
'lint',
plugin
.platformDirectory(FlutterPlatform.macos)
.childFile('plugin1.podspec')
.path,
'--configuration=Debug',
'--skip-tests',
'--use-modular-headers',
'--use-libraries'
],
packagesDir.path),
ProcessCall(
'pod',
<String>[
'lib',
'lint',
plugin
.platformDirectory(FlutterPlatform.macos)
.childFile('plugin1.podspec')
.path,
'--configuration=Debug',
'--skip-tests',
'--use-modular-headers',
],
packagesDir.path),
]),
);
});
test('fails if pod is missing', () async {
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir);
_writeFakePodspec(plugin, 'ios');
// Simulate failure from `which pod`.
processRunner.mockProcessesForExecutable['which'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(exitCode: 1), <String>['pod']),
];
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['podspec-check'], errorHandler: (Error e) {
commandError = e;
});
expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(
<Matcher>[
contains('Unable to find "pod". Make sure it is in your path.'),
],
));
});
test('fails if linting as a framework fails', () async {
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir);
_writeFakePodspec(plugin, 'ios');
// Simulate failure from `pod`.
processRunner.mockProcessesForExecutable['pod'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(exitCode: 1)),
];
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['podspec-check'], errorHandler: (Error e) {
commandError = e;
});
expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(
<Matcher>[
contains('The following packages had errors:'),
contains('plugin1:\n'
' plugin1.podspec')
],
));
});
test('fails if linting as a static library fails', () async {
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir);
_writeFakePodspec(plugin, 'ios');
// Simulate failure from the second call to `pod`.
processRunner.mockProcessesForExecutable['pod'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess()),
FakeProcessInfo(MockProcess(exitCode: 1)),
];
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['podspec-check'], errorHandler: (Error e) {
commandError = e;
});
expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(
<Matcher>[
contains('The following packages had errors:'),
contains('plugin1:\n'
' plugin1.podspec')
],
));
});
test('fails if an iOS Swift plugin is missing the search paths workaround',
() async {
final RepositoryPackage plugin = createFakePlugin(
'plugin1',
packagesDir,
extraFiles: <String>[
'ios/Classes/SomeSwift.swift',
'ios/plugin1/Package.swift',
],
);
_writeFakePodspec(plugin, 'ios');
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['podspec-check'], errorHandler: (Error e) {
commandError = e;
});
expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(
<Matcher>[
contains(r'''
s.xcconfig = {
'LIBRARY_SEARCH_PATHS' => '$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)/ $(SDKROOT)/usr/lib/swift',
'LD_RUNPATH_SEARCH_PATHS' => '/usr/lib/swift',
}'''),
contains('The following packages had errors:'),
contains('plugin1:\n'
' plugin1.podspec')
],
));
});
test(
'fails if a shared-source Swift plugin is missing the search paths workaround',
() async {
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir,
extraFiles: <String>['darwin/Classes/SomeSwift.swift']);
_writeFakePodspec(plugin, 'darwin');
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['podspec-check'], errorHandler: (Error e) {
commandError = e;
});
expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(
<Matcher>[
contains(r'''
s.xcconfig = {
'LIBRARY_SEARCH_PATHS' => '$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)/ $(SDKROOT)/usr/lib/swift',
'LD_RUNPATH_SEARCH_PATHS' => '/usr/lib/swift',
}'''),
contains('The following packages had errors:'),
contains('plugin1:\n'
' plugin1.podspec')
],
));
});
test('does not require the search paths workaround for iOS Package.swift',
() async {
final RepositoryPackage plugin = createFakePlugin(
'plugin1',
packagesDir,
extraFiles: <String>['ios/plugin1/Package.swift'],
);
_writeFakePodspec(plugin, 'ios');
final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);
expect(
output,
containsAllInOrder(
<Matcher>[
contains('Ran for 1 package(s)'),
],
));
});
test('does not require the search paths workaround for macOS plugins',
() async {
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir,
extraFiles: <String>['macos/Classes/SomeSwift.swift']);
_writeFakePodspec(plugin, 'macos');
final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);
expect(
output,
containsAllInOrder(
<Matcher>[
contains('Ran for 1 package(s)'),
],
));
});
test('does not require the search paths workaround for ObjC iOS plugins',
() async {
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir,
extraFiles: <String>[
'ios/Classes/SomeObjC.h',
'ios/Classes/SomeObjC.m'
]);
_writeFakePodspec(plugin, 'ios');
final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);
expect(
output,
containsAllInOrder(
<Matcher>[
contains('Ran for 1 package(s)'),
],
));
});
test('passes if the search paths workaround is present', () async {
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir,
extraFiles: <String>['ios/Classes/SomeSwift.swift']);
_writeFakePodspec(plugin, 'ios', includeSwiftWorkaround: true);
final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);
expect(
output,
containsAllInOrder(
<Matcher>[
contains('Ran for 1 package(s)'),
],
));
});
test('passes if the search paths workaround is present for iOS only',
() async {
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir,
extraFiles: <String>['ios/Classes/SomeSwift.swift']);
_writeFakePodspec(plugin, 'ios',
includeSwiftWorkaround: true, scopeSwiftWorkaround: true);
final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);
expect(
output,
containsAllInOrder(
<Matcher>[
contains('Ran for 1 package(s)'),
],
));
});
test('does not require the search paths workaround for Swift example code',
() async {
final RepositoryPackage plugin =
createFakePlugin('plugin1', packagesDir, extraFiles: <String>[
'ios/Classes/SomeObjC.h',
'ios/Classes/SomeObjC.m',
'example/ios/Runner/AppDelegate.swift',
]);
_writeFakePodspec(plugin, 'ios');
final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);
expect(
output,
containsAllInOrder(
<Matcher>[
contains('Ran for 1 package(s)'),
],
));
});
test('skips when there are no podspecs', () async {
createFakePlugin('plugin1', packagesDir);
final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);
expect(
output,
containsAllInOrder(
<Matcher>[contains('SKIPPING: No podspecs.')],
));
});
test('fails when an iOS plugin is missing a privacy manifest', () async {
final RepositoryPackage plugin = createFakePlugin(
'plugin1',
packagesDir,
platformSupport: <String, PlatformDetails>{
Platform.iOS: const PlatformDetails(PlatformSupport.inline),
},
);
_writeFakePodspec(plugin, 'ios');
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['podspec-check'], errorHandler: (Error e) {
commandError = e;
});
expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(
<Matcher>[contains('No PrivacyInfo.xcprivacy file specified.')],
));
});
test('passes when an iOS plugin has a privacy manifest', () async {
final RepositoryPackage plugin = createFakePlugin(
'plugin1',
packagesDir,
platformSupport: <String, PlatformDetails>{
Platform.iOS: const PlatformDetails(PlatformSupport.inline),
},
);
_writeFakePodspec(plugin, 'ios', includePrivacyManifest: true);
final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);
expect(
output,
containsAllInOrder(
<Matcher>[contains('Ran for 1 package(s)')],
));
});
});
}