diff --git a/.ci/scripts/dart_unit_tests_win32.sh b/.ci/scripts/dart_unit_tests_win32.sh index 5fbe4764f6..2cd451c45c 100755 --- a/.ci/scripts/dart_unit_tests_win32.sh +++ b/.ci/scripts/dart_unit_tests_win32.sh @@ -4,6 +4,6 @@ # found in the LICENSE file. set -e -dart ./script/tool/bin/flutter_plugin_tools.dart test \ +dart ./script/tool/bin/flutter_plugin_tools.dart dart-test \ --exclude=script/configs/windows_unit_tests_exceptions.yaml \ --packages-for-branch --log-timing diff --git a/.cirrus.yml b/.cirrus.yml index 47ee7ff760..d7ee3cc6ff 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -231,13 +231,13 @@ task: CHANNEL: "master" CHANNEL: "stable" unit_test_script: - - ./script/tool_runner.sh test --exclude=script/configs/dart_unit_tests_exceptions.yaml + - ./script/tool_runner.sh dart-test --exclude=script/configs/dart_unit_tests_exceptions.yaml pathified_unit_test_script: # Run tests with path-based dependencies to ensure that publishing # the changes won't break tests of other packages in the repository # that depend on it. - ./script/tool_runner.sh make-deps-path-based --target-dependencies-with-non-breaking-updates - - $PLUGIN_TOOL_COMMAND test --run-on-dirty-packages --exclude=script/configs/dart_unit_tests_exceptions.yaml + - $PLUGIN_TOOL_COMMAND dart-test --run-on-dirty-packages --exclude=script/configs/dart_unit_tests_exceptions.yaml - name: linux-custom_package_tests env: PATH: $PATH:/usr/local/bin diff --git a/script/tool/lib/src/custom_test_command.dart b/script/tool/lib/src/custom_test_command.dart index 0ef6e602c0..aac8fa8122 100644 --- a/script/tool/lib/src/custom_test_command.dart +++ b/script/tool/lib/src/custom_test_command.dart @@ -28,6 +28,9 @@ class CustomTestCommand extends PackageLoopingCommand { @override final String name = 'custom-test'; + @override + List get aliases => ['test-custom']; + @override final String description = 'Runs package-specific custom tests defined in ' "a package's tool/$_scriptName file.\n\n" diff --git a/script/tool/lib/src/test_command.dart b/script/tool/lib/src/dart_test_command.dart similarity index 89% rename from script/tool/lib/src/test_command.dart rename to script/tool/lib/src/dart_test_command.dart index 5c793f63ed..9a93d2d9a2 100644 --- a/script/tool/lib/src/test_command.dart +++ b/script/tool/lib/src/dart_test_command.dart @@ -12,9 +12,9 @@ import 'common/process_runner.dart'; import 'common/repository_package.dart'; /// A command to run Dart unit tests for packages. -class TestCommand extends PackageLoopingCommand { +class DartTestCommand extends PackageLoopingCommand { /// Creates an instance of the test command. - TestCommand( + DartTestCommand( Directory packagesDir, { ProcessRunner processRunner = const ProcessRunner(), Platform platform = const LocalPlatform(), @@ -30,7 +30,13 @@ class TestCommand extends PackageLoopingCommand { } @override - final String name = 'test'; + final String name = 'dart-test'; + + // TODO(stuartmorgan): Eventually remove 'test', which is a legacy name from + // before there were other test commands that made it ambiguous. For now it's + // an alias to avoid breaking people's workflows. + @override + List get aliases => ['test', 'test-dart']; @override final String description = 'Runs the Dart tests for all packages.\n\n' diff --git a/script/tool/lib/src/dependabot_check_command.dart b/script/tool/lib/src/dependabot_check_command.dart index 77b44e11b5..d16fb33e92 100644 --- a/script/tool/lib/src/dependabot_check_command.dart +++ b/script/tool/lib/src/dependabot_check_command.dart @@ -32,6 +32,9 @@ class DependabotCheckCommand extends PackageLoopingCommand { @override final String name = 'dependabot-check'; + @override + List get aliases => ['check-dependabot']; + @override final String description = 'Checks that all packages have Dependabot coverage.'; diff --git a/script/tool/lib/src/federation_safety_check_command.dart b/script/tool/lib/src/federation_safety_check_command.dart index 30d4d178d0..837193b1cc 100644 --- a/script/tool/lib/src/federation_safety_check_command.dart +++ b/script/tool/lib/src/federation_safety_check_command.dart @@ -52,6 +52,9 @@ class FederationSafetyCheckCommand extends PackageLoopingCommand { @override final String name = 'federation-safety-check'; + @override + List get aliases => ['check-federation-safety']; + @override final String description = 'Checks that the change does not violate repository rules around changes ' diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index 53da6405be..cbce766b37 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -23,6 +23,9 @@ class GradleCheckCommand extends PackageLoopingCommand { @override final String name = 'gradle-check'; + @override + List get aliases => ['check-gradle']; + @override final String description = 'Checks that gradle files follow repository conventions.'; diff --git a/script/tool/lib/src/license_check_command.dart b/script/tool/lib/src/license_check_command.dart index 0517bcf432..a8d4a7be5f 100644 --- a/script/tool/lib/src/license_check_command.dart +++ b/script/tool/lib/src/license_check_command.dart @@ -114,6 +114,9 @@ class LicenseCheckCommand extends PackageCommand { @override final String name = 'license-check'; + @override + List get aliases => ['check-license']; + @override final String description = 'Ensures that all code files have copyright/license blocks.'; diff --git a/script/tool/lib/src/main.dart b/script/tool/lib/src/main.dart index c86629d4f4..78fa5a3f0c 100644 --- a/script/tool/lib/src/main.dart +++ b/script/tool/lib/src/main.dart @@ -13,6 +13,7 @@ import 'build_examples_command.dart'; import 'common/core.dart'; import 'create_all_packages_app_command.dart'; import 'custom_test_command.dart'; +import 'dart_test_command.dart'; import 'dependabot_check_command.dart'; import 'drive_examples_command.dart'; import 'federation_safety_check_command.dart'; @@ -31,7 +32,6 @@ import 'publish_command.dart'; import 'pubspec_check_command.dart'; import 'readme_check_command.dart'; import 'remove_dev_dependencies_command.dart'; -import 'test_command.dart'; import 'update_dependency_command.dart'; import 'update_excerpts_command.dart'; import 'update_min_sdk_command.dart'; @@ -80,7 +80,7 @@ void main(List args) { ..addCommand(PubspecCheckCommand(packagesDir)) ..addCommand(ReadmeCheckCommand(packagesDir)) ..addCommand(RemoveDevDependenciesCommand(packagesDir)) - ..addCommand(TestCommand(packagesDir)) + ..addCommand(DartTestCommand(packagesDir)) ..addCommand(UpdateDependencyCommand(packagesDir)) ..addCommand(UpdateExcerptsCommand(packagesDir)) ..addCommand(UpdateMinSdkCommand(packagesDir)) diff --git a/script/tool/lib/src/native_test_command.dart b/script/tool/lib/src/native_test_command.dart index f6eb3c164e..d5f720a02e 100644 --- a/script/tool/lib/src/native_test_command.dart +++ b/script/tool/lib/src/native_test_command.dart @@ -73,6 +73,9 @@ class NativeTestCommand extends PackageLoopingCommand { @override final String name = 'native-test'; + @override + List get aliases => ['test-native']; + @override final String description = ''' Runs native unit tests and native integration tests. diff --git a/script/tool/lib/src/podspec_check_command.dart b/script/tool/lib/src/podspec_check_command.dart index dda08eee32..9fcaa46995 100644 --- a/script/tool/lib/src/podspec_check_command.dart +++ b/script/tool/lib/src/podspec_check_command.dart @@ -31,7 +31,7 @@ class PodspecCheckCommand extends PackageLoopingCommand { final String name = 'podspec-check'; @override - List get aliases => ['podspec', 'podspecs']; + List get aliases => ['podspec', 'podspecs', 'check-podspec']; @override final String description = diff --git a/script/tool/lib/src/publish_check_command.dart b/script/tool/lib/src/publish_check_command.dart index 2d7f3ca47f..0ac01535b4 100644 --- a/script/tool/lib/src/publish_check_command.dart +++ b/script/tool/lib/src/publish_check_command.dart @@ -53,6 +53,9 @@ class PublishCheckCommand extends PackageLoopingCommand { @override final String name = 'publish-check'; + @override + List get aliases => ['check-publish']; + @override final String description = 'Checks to make sure that a package *could* be published.'; diff --git a/script/tool/lib/src/pubspec_check_command.dart b/script/tool/lib/src/pubspec_check_command.dart index c56fa2723b..838aac0541 100644 --- a/script/tool/lib/src/pubspec_check_command.dart +++ b/script/tool/lib/src/pubspec_check_command.dart @@ -89,6 +89,9 @@ class PubspecCheckCommand extends PackageLoopingCommand { @override final String name = 'pubspec-check'; + @override + List get aliases => ['check-pubspec']; + @override final String description = 'Checks that pubspecs follow repository conventions.'; @@ -104,8 +107,8 @@ class PubspecCheckCommand extends PackageLoopingCommand { Future initializeRun() async { // Find all local, published packages. for (final File pubspecFile in (await packagesDir.parent - .list(recursive: true, followLinks: false) - .toList()) + .list(recursive: true, followLinks: false) + .toList()) .whereType() .where((File entity) => p.basename(entity.path) == 'pubspec.yaml')) { final Pubspec? pubspec = _tryParsePubspec(pubspecFile.readAsStringSync()); diff --git a/script/tool/lib/src/readme_check_command.dart b/script/tool/lib/src/readme_check_command.dart index 3c119f0428..7e28979c95 100644 --- a/script/tool/lib/src/readme_check_command.dart +++ b/script/tool/lib/src/readme_check_command.dart @@ -48,6 +48,9 @@ class ReadmeCheckCommand extends PackageLoopingCommand { @override final String name = 'readme-check'; + @override + List get aliases => ['check-readme']; + @override final String description = 'Checks that READMEs follow repository conventions.'; diff --git a/script/tool/lib/src/version_check_command.dart b/script/tool/lib/src/version_check_command.dart index fa9f435194..a2ea016c33 100644 --- a/script/tool/lib/src/version_check_command.dart +++ b/script/tool/lib/src/version_check_command.dart @@ -171,6 +171,9 @@ class VersionCheckCommand extends PackageLoopingCommand { @override final String name = 'version-check'; + @override + List get aliases => ['check-version']; + @override final String description = 'Checks if the versions of packages have been incremented per pub specification.\n' diff --git a/script/tool/lib/src/xcode_analyze_command.dart b/script/tool/lib/src/xcode_analyze_command.dart index a81bf15477..7a9a5953f5 100644 --- a/script/tool/lib/src/xcode_analyze_command.dart +++ b/script/tool/lib/src/xcode_analyze_command.dart @@ -42,6 +42,9 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand { @override final String name = 'xcode-analyze'; + @override + List get aliases => ['analyze-xcode']; + @override final String description = 'Runs Xcode analysis on the iOS and/or macOS example apps.'; diff --git a/script/tool/test/test_command_test.dart b/script/tool/test/dart_test_command_test.dart similarity index 85% rename from script/tool/test/test_command_test.dart rename to script/tool/test/dart_test_command_test.dart index c4c655bf71..7f52fcb176 100644 --- a/script/tool/test/test_command_test.dart +++ b/script/tool/test/dart_test_command_test.dart @@ -7,7 +7,7 @@ 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/test_command.dart'; +import 'package:flutter_plugin_tools/src/dart_test_command.dart'; import 'package:platform/platform.dart'; import 'package:test/test.dart'; @@ -27,23 +27,38 @@ void main() { mockPlatform = MockPlatform(); packagesDir = createPackagesDirectory(fileSystem: fileSystem); processRunner = RecordingProcessRunner(); - final TestCommand command = TestCommand( + final DartTestCommand command = DartTestCommand( packagesDir, processRunner: processRunner, platform: mockPlatform, ); - runner = CommandRunner('test_test', 'Test for $TestCommand'); + runner = CommandRunner('test_test', 'Test for $DartTestCommand'); runner.addCommand(command); }); + test('legacy "test" name still works', () async { + final RepositoryPackage plugin = createFakePlugin('a_plugin', packagesDir, + extraFiles: ['test/a_test.dart']); + + await runCapturingPrint(runner, ['test']); + + expect( + processRunner.recordedCalls, + orderedEquals([ + ProcessCall(getFlutterCommand(mockPlatform), + const ['test', '--color'], plugin.path), + ]), + ); + }); + test('runs flutter test on each plugin', () async { final RepositoryPackage plugin1 = createFakePlugin('plugin1', packagesDir, extraFiles: ['test/empty_test.dart']); final RepositoryPackage plugin2 = createFakePlugin('plugin2', packagesDir, extraFiles: ['test/empty_test.dart']); - await runCapturingPrint(runner, ['test']); + await runCapturingPrint(runner, ['dart-test']); expect( processRunner.recordedCalls, @@ -63,7 +78,7 @@ void main() { 'example/test/an_example_test.dart' ]); - await runCapturingPrint(runner, ['test']); + await runCapturingPrint(runner, ['dart-test']); expect( processRunner.recordedCalls, @@ -86,13 +101,13 @@ void main() { .mockProcessesForExecutable[getFlutterCommand(mockPlatform)] = [ FakeProcessInfo( - MockProcess(exitCode: 1), ['test']), // plugin 1 test - FakeProcessInfo(MockProcess(), ['test']), // plugin 2 test + MockProcess(exitCode: 1), ['dart-test']), // plugin 1 test + FakeProcessInfo(MockProcess(), ['dart-test']), // plugin 2 test ]; Error? commandError; final List output = await runCapturingPrint( - runner, ['test'], errorHandler: (Error e) { + runner, ['dart-test'], errorHandler: (Error e) { commandError = e; }); @@ -110,7 +125,7 @@ void main() { final RepositoryPackage plugin2 = createFakePlugin('plugin2', packagesDir, extraFiles: ['test/empty_test.dart']); - await runCapturingPrint(runner, ['test']); + await runCapturingPrint(runner, ['dart-test']); expect( processRunner.recordedCalls, @@ -128,7 +143,7 @@ void main() { extraFiles: ['test/empty_test.dart']); await runCapturingPrint( - runner, ['test', '--enable-experiment=exp1']); + runner, ['dart-test', '--enable-experiment=exp1']); expect( processRunner.recordedCalls, @@ -153,7 +168,7 @@ void main() { 'example/test/an_example_test.dart' ]); - await runCapturingPrint(runner, ['test']); + await runCapturingPrint(runner, ['dart-test']); expect( processRunner.recordedCalls, @@ -178,7 +193,7 @@ void main() { Error? commandError; final List output = await runCapturingPrint( - runner, ['test'], errorHandler: (Error e) { + runner, ['dart-test'], errorHandler: (Error e) { commandError = e; }); @@ -203,7 +218,7 @@ void main() { Error? commandError; final List output = await runCapturingPrint( - runner, ['test'], errorHandler: (Error e) { + runner, ['dart-test'], errorHandler: (Error e) { commandError = e; }); @@ -226,7 +241,7 @@ void main() { }, ); - await runCapturingPrint(runner, ['test']); + await runCapturingPrint(runner, ['dart-test']); expect( processRunner.recordedCalls, @@ -249,7 +264,7 @@ void main() { }, ); - await runCapturingPrint(runner, ['test']); + await runCapturingPrint(runner, ['dart-test']); expect( processRunner.recordedCalls, @@ -267,7 +282,7 @@ void main() { extraFiles: ['test/empty_test.dart']); await runCapturingPrint( - runner, ['test', '--enable-experiment=exp1']); + runner, ['dart-test', '--enable-experiment=exp1']); expect( processRunner.recordedCalls,