[flutter_plugin_tools] Support non-plugin packages for drive-examples (#5468)

This commit is contained in:
stuartmorgan
2022-05-02 17:44:12 -04:00
committed by GitHub
parent d43fae6fb4
commit fbf53f284b
20 changed files with 398 additions and 112 deletions

View File

@ -123,6 +123,8 @@ class DriveExamplesCommand extends PackageLoopingCommand {
@override
Future<PackageResult> runForPackage(RepositoryPackage package) async {
final bool isPlugin = isFlutterPlugin(package);
if (package.isPlatformInterface &&
!package.getSingleExampleDeprecated().directory.existsSync()) {
// Platform interface packages generally aren't intended to have
@ -131,23 +133,23 @@ class DriveExamplesCommand extends PackageLoopingCommand {
'Platform interfaces are not expected to have integration tests.');
}
final List<String> deviceFlags = <String>[];
for (final MapEntry<String, List<String>> entry
in _targetDeviceFlags.entries) {
final String platform = entry.key;
if (pluginSupportsPlatform(platform, package)) {
deviceFlags.addAll(entry.value);
} else {
print('Skipping unsupported platform ${entry.key}...');
// For plugin packages, skip if the plugin itself doesn't support any
// requested platform(s).
if (isPlugin) {
final Iterable<String> requestedPlatforms = _targetDeviceFlags.keys;
final Iterable<String> unsupportedPlatforms = requestedPlatforms.where(
(String platform) => !pluginSupportsPlatform(platform, package));
for (final String platform in unsupportedPlatforms) {
print('Skipping unsupported platform $platform...');
}
if (unsupportedPlatforms.length == requestedPlatforms.length) {
return PackageResult.skip(
'${package.displayName} does not support any requested platform.');
}
}
// If there is no supported target platform, skip the plugin.
if (deviceFlags.isEmpty) {
return PackageResult.skip(
'${package.displayName} does not support any requested platform.');
}
int examplesFound = 0;
int supportedExamplesFound = 0;
bool testsRan = false;
final List<String> errors = <String>[];
for (final RepositoryPackage example in package.getExamples()) {
@ -155,6 +157,15 @@ class DriveExamplesCommand extends PackageLoopingCommand {
final String exampleName =
getRelativePosixPath(example.directory, from: packagesDir);
// Skip examples that don't support any requested platform(s).
final List<String> deviceFlags = _deviceFlagsForExample(example);
if (deviceFlags.isEmpty) {
print(
'Skipping $exampleName; does not support any requested platforms.');
continue;
}
++supportedExamplesFound;
final List<File> drivers = await _getDrivers(example);
if (drivers.isEmpty) {
print('No driver tests found for $exampleName');
@ -195,14 +206,41 @@ class DriveExamplesCommand extends PackageLoopingCommand {
}
}
if (!testsRan) {
printError('No driver tests were run ($examplesFound example(s) found).');
errors.add('No tests ran (use --exclude if this is intentional).');
// It is an error for a plugin not to have integration tests, because that
// is the only way to test the method channel communication.
if (isPlugin) {
printError(
'No driver tests were run ($examplesFound example(s) found).');
errors.add('No tests ran (use --exclude if this is intentional).');
} else {
return PackageResult.skip(supportedExamplesFound == 0
? 'No example supports requested platform(s).'
: 'No example is configured for driver tests.');
}
}
return errors.isEmpty
? PackageResult.success()
: PackageResult.fail(errors);
}
/// Returns the device flags for the intersection of the requested platforms
/// and the platforms supported by [example].
List<String> _deviceFlagsForExample(RepositoryPackage example) {
final List<String> deviceFlags = <String>[];
for (final MapEntry<String, List<String>> entry
in _targetDeviceFlags.entries) {
final String platform = entry.key;
if (example.directory.childDirectory(platform).existsSync()) {
deviceFlags.addAll(entry.value);
} else {
final String exampleName =
getRelativePosixPath(example.directory, from: packagesDir);
print('Skipping unsupported platform $platform for $exampleName');
}
}
return deviceFlags;
}
Future<List<String>> _getDevicesForPlatform(String platform) async {
final List<String> deviceIds = <String>[];