mirror of
https://github.com/flutter/packages.git
synced 2025-06-14 17:23:59 +08:00
[flutter_plugin_tools] Fix build-examples for packages (#4248)
The build-examples command was filtering what it attempted to build by plugin platform, which means it never does anything for non-plugin packages. flutter/packages has steps that run this command, which suggests it used to work and regressed at some point, but nobody noticed; this will re-enable those builds so that we are getting CI coverage that the examples in flutter/packages build. Mostly fixes https://github.com/flutter/flutter/issues/88435 (needs a flutter/packages tool pin roll to pick this up)
This commit is contained in:
@ -82,6 +82,35 @@ void main() {
|
||||
]));
|
||||
});
|
||||
|
||||
test('fails if a plugin has no examples', () async {
|
||||
createFakePlugin('plugin', packagesDir,
|
||||
examples: <String>[],
|
||||
platformSupport: <String, PlatformDetails>{
|
||||
kPlatformIos: const PlatformDetails(PlatformSupport.inline)
|
||||
});
|
||||
|
||||
processRunner
|
||||
.mockProcessesForExecutable[getFlutterCommand(mockPlatform)] =
|
||||
<io.Process>[
|
||||
MockProcess(exitCode: 1) // flutter packages get
|
||||
];
|
||||
|
||||
Error? commandError;
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['build-examples', '--ios'], errorHandler: (Error e) {
|
||||
commandError = e;
|
||||
});
|
||||
|
||||
expect(commandError, isA<ToolExit>());
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('The following packages had errors:'),
|
||||
contains(' plugin:\n'
|
||||
' No examples found'),
|
||||
]));
|
||||
});
|
||||
|
||||
test('building for iOS when plugin is not set up for iOS results in no-op',
|
||||
() async {
|
||||
mockPlatform.isMacOS = true;
|
||||
@ -517,5 +546,138 @@ void main() {
|
||||
pluginExampleDirectory.path),
|
||||
]));
|
||||
});
|
||||
|
||||
test('logs skipped platforms', () async {
|
||||
createFakePlugin('plugin', packagesDir,
|
||||
platformSupport: <String, PlatformDetails>{
|
||||
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
|
||||
});
|
||||
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['build-examples', '--apk', '--ios', '--macos']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('Skipping unsupported platform(s): iOS, macOS'),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
group('packages', () {
|
||||
test('builds when requested platform is supported by example', () async {
|
||||
final Directory packageDirectory = createFakePackage(
|
||||
'package', packagesDir, isFlutter: true, extraFiles: <String>[
|
||||
'example/ios/Runner.xcodeproj/project.pbxproj'
|
||||
]);
|
||||
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['build-examples', '--ios']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('Running for package'),
|
||||
contains('BUILDING package/example for iOS'),
|
||||
]),
|
||||
);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
ProcessCall(
|
||||
getFlutterCommand(mockPlatform),
|
||||
const <String>[
|
||||
'build',
|
||||
'ios',
|
||||
'--no-codesign',
|
||||
],
|
||||
packageDirectory.childDirectory('example').path),
|
||||
]));
|
||||
});
|
||||
|
||||
test('skips non-Flutter examples', () async {
|
||||
createFakePackage('package', packagesDir, isFlutter: false);
|
||||
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['build-examples', '--ios']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('Running for package'),
|
||||
contains('No examples found supporting requested platform(s).'),
|
||||
]),
|
||||
);
|
||||
|
||||
expect(processRunner.recordedCalls, orderedEquals(<ProcessCall>[]));
|
||||
});
|
||||
|
||||
test('skips when there is no example', () async {
|
||||
createFakePackage('package', packagesDir,
|
||||
isFlutter: true, examples: <String>[]);
|
||||
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['build-examples', '--ios']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('Running for package'),
|
||||
contains('No examples found supporting requested platform(s).'),
|
||||
]),
|
||||
);
|
||||
|
||||
expect(processRunner.recordedCalls, orderedEquals(<ProcessCall>[]));
|
||||
});
|
||||
|
||||
test('skip when example does not support requested platform', () async {
|
||||
createFakePackage('package', packagesDir,
|
||||
isFlutter: true,
|
||||
extraFiles: <String>['example/linux/CMakeLists.txt']);
|
||||
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['build-examples', '--ios']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('Running for package'),
|
||||
contains('Skipping iOS for package/example; not supported.'),
|
||||
contains('No examples found supporting requested platform(s).'),
|
||||
]),
|
||||
);
|
||||
|
||||
expect(processRunner.recordedCalls, orderedEquals(<ProcessCall>[]));
|
||||
});
|
||||
|
||||
test('logs skipped platforms when only some are supported', () async {
|
||||
final Directory packageDirectory = createFakePackage(
|
||||
'package', packagesDir,
|
||||
isFlutter: true,
|
||||
extraFiles: <String>['example/linux/CMakeLists.txt']);
|
||||
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['build-examples', '--apk', '--linux']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('Running for package'),
|
||||
contains('Building for: Android, Linux'),
|
||||
contains('Skipping Android for package/example; not supported.'),
|
||||
]),
|
||||
);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
ProcessCall(
|
||||
getFlutterCommand(mockPlatform),
|
||||
const <String>['build', 'linux'],
|
||||
packageDirectory.childDirectory('example').path),
|
||||
]));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user