diff --git a/script/tool/lib/src/drive_examples_command.dart b/script/tool/lib/src/drive_examples_command.dart index 0230ebd671..1572b94107 100644 --- a/script/tool/lib/src/drive_examples_command.dart +++ b/script/tool/lib/src/drive_examples_command.dart @@ -52,23 +52,37 @@ class DriveExamplesCommand extends PluginCommand { @override Future run() async { final List failingTests = []; + final List pluginsWithoutTests = []; final bool isLinux = argResults[kLinux] == true; final bool isMacos = argResults[kMacos] == true; final bool isWeb = argResults[kWeb] == true; final bool isWindows = argResults[kWindows] == true; await for (final Directory plugin in getPlugins()) { + final String pluginName = plugin.basename; + if (pluginName.endsWith('_platform_interface') && + !plugin.childDirectory('example').existsSync()) { + // Platform interface packages generally aren't intended to have + // examples, and don't need integration tests, so silently skip them + // unless for some reason there is an example directory. + continue; + } + print('\n==========\nChecking $pluginName...'); + if (!(await _pluginSupportedOnCurrentPlatform(plugin, fileSystem))) { + print('Not supported for the target platform; skipping.'); + continue; + } + int examplesFound = 0; + bool testsRan = false; final String flutterCommand = const LocalPlatform().isWindows ? 'flutter.bat' : 'flutter'; for (final Directory example in getExamplesForPlugin(plugin)) { + ++examplesFound; final String packageName = p.relative(example.path, from: packagesDir.path); - if (!(await _pluginSupportedOnCurrentPlatform(plugin, fileSystem))) { - continue; - } final Directory driverTests = fileSystem.directory(p.join(example.path, 'test_driver')); if (!driverTests.existsSync()) { - // No driver tests available for this example + print('No driver tests found for $packageName'); continue; } // Look for driver tests ending in _test.dart in test_driver/ @@ -160,6 +174,7 @@ Tried searching for the following: } for (final String targetPath in targetPaths) { + testsRan = true; final int exitCode = await processRunner.runAndStream( flutterCommand, [ @@ -177,6 +192,11 @@ Tried searching for the following: } } } + if (!testsRan) { + pluginsWithoutTests.add(pluginName); + print( + 'No driver tests run for $pluginName ($examplesFound examples found)'); + } } print('\n\n'); @@ -188,6 +208,15 @@ Tried searching for the following: throw ToolExit(1); } + if (pluginsWithoutTests.isNotEmpty) { + print('The following plugins did not run any integration tests:'); + for (final String plugin in pluginsWithoutTests) { + print(' * $plugin'); + } + print('If this is intentional, they must be explicitly excluded.'); + throw ToolExit(1); + } + print('All driver tests successful!'); } diff --git a/script/tool/test/drive_examples_command_test.dart b/script/tool/test/drive_examples_command_test.dart index c5960b2c34..5ba8d8af25 100644 --- a/script/tool/test/drive_examples_command_test.dart +++ b/script/tool/test/drive_examples_command_test.dart @@ -55,6 +55,7 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', '\n\n', 'All driver tests successful!', ]), @@ -100,6 +101,7 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', '\n\n', 'All driver tests successful!', ]), @@ -143,6 +145,25 @@ void main() { throwsA(const TypeMatcher())); }); + test('a plugin without any integration test files is reported as an error', + () async { + createFakePlugin('plugin', + withExtraFiles: >[ + ['example', 'lib', 'main.dart'], + ], + isAndroidPlugin: true, + isIosPlugin: true); + + final Directory pluginExampleDirectory = + mockPackagesDir.childDirectory('plugin').childDirectory('example'); + + createFakePubspec(pluginExampleDirectory, isFlutter: true); + + await expectLater( + () => runCapturingPrint(runner, ['drive-examples']), + throwsA(const TypeMatcher())); + }); + test( 'driving under folder "test_driver" when targets are under "integration_test"', () async { @@ -168,6 +189,7 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', '\n\n', 'All driver tests successful!', ]), @@ -223,6 +245,8 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', + 'Not supported for the target platform; skipping.', '\n\n', 'All driver tests successful!', ]), @@ -255,6 +279,7 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', '\n\n', 'All driver tests successful!', ]), @@ -300,6 +325,8 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', + 'Not supported for the target platform; skipping.', '\n\n', 'All driver tests successful!', ]), @@ -332,6 +359,7 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', '\n\n', 'All driver tests successful!', ]), @@ -379,6 +407,8 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', + 'Not supported for the target platform; skipping.', '\n\n', 'All driver tests successful!', ]), @@ -411,6 +441,7 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', '\n\n', 'All driver tests successful!', ]), @@ -460,6 +491,8 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', + 'Not supported for the target platform; skipping.', '\n\n', 'All driver tests successful!', ]), @@ -492,6 +525,7 @@ void main() { expect( output, orderedEquals([ + '\n==========\nChecking plugin...', '\n\n', 'All driver tests successful!', ]), @@ -535,6 +569,29 @@ void main() { 'drive-examples', ]); + expect( + output, + orderedEquals([ + '\n==========\nChecking plugin...', + 'Not supported for the target platform; skipping.', + '\n\n', + 'All driver tests successful!', + ]), + ); + + print(processRunner.recordedCalls); + // Output should be empty since running drive-examples --macos with no macos + // implementation is a no-op. + expect(processRunner.recordedCalls, []); + }); + + test('platform interface plugins are silently skipped', () async { + createFakePlugin('aplugin_platform_interface'); + + final List output = await runCapturingPrint(runner, [ + 'drive-examples', + ]); + expect( output, orderedEquals([