[flutter_plugin_tools] Include examples in `test` (#5453)

diff --git a/script/tool/CHANGELOG.md b/script/tool/CHANGELOG.md
index 2ce6441..b2319c6 100644
--- a/script/tool/CHANGELOG.md
+++ b/script/tool/CHANGELOG.md
@@ -1,5 +1,6 @@
-## NEXT
+## 0.8.5
 
+- Updates `test` to inculde the Dart unit tests of examples, if any.
 - `drive-examples` now supports non-plugin packages.
 - Commands that iterate over examples now include non-Flutter example packages.
 
diff --git a/script/tool/lib/src/test_command.dart b/script/tool/lib/src/test_command.dart
index d115b65..a1a995d 100644
--- a/script/tool/lib/src/test_command.dart
+++ b/script/tool/lib/src/test_command.dart
@@ -37,6 +37,9 @@
       'This command requires "flutter" to be in your path.';
 
   @override
+  bool get includeSubpackages => true;
+
+  @override
   Future<PackageResult> runForPackage(RepositoryPackage package) async {
     if (!package.directory.childDirectory('test').existsSync()) {
       return PackageResult.skip('No test/ directory.');
@@ -88,7 +91,6 @@
     exitCode = await processRunner.runAndStream(
       'dart',
       <String>[
-        'pub',
         'run',
         if (experiment.isNotEmpty) '--enable-experiment=$experiment',
         'test',
diff --git a/script/tool/pubspec.yaml b/script/tool/pubspec.yaml
index af38193..32bfc1b 100644
--- a/script/tool/pubspec.yaml
+++ b/script/tool/pubspec.yaml
@@ -1,7 +1,7 @@
 name: flutter_plugin_tools
 description: Productivity utils for flutter/plugins and flutter/packages
 repository: https://github.com/flutter/plugins/tree/main/script/tool
-version: 0.8.4
+version: 0.8.5
 
 dependencies:
   args: ^2.1.0
diff --git a/script/tool/test/test_command_test.dart b/script/tool/test/test_command_test.dart
index 9bcd8d1..386eaf0 100644
--- a/script/tool/test/test_command_test.dart
+++ b/script/tool/test/test_command_test.dart
@@ -58,6 +58,28 @@
       );
     });
 
+    test('runs flutter test on Flutter package example tests', () async {
+      final Directory pluginDir = createFakePlugin('a_plugin', packagesDir,
+          extraFiles: <String>[
+            'test/empty_test.dart',
+            'example/test/an_example_test.dart'
+          ]);
+
+      await runCapturingPrint(runner, <String>['test']);
+
+      expect(
+        processRunner.recordedCalls,
+        orderedEquals(<ProcessCall>[
+          ProcessCall(getFlutterCommand(mockPlatform),
+              const <String>['test', '--color'], pluginDir.path),
+          ProcessCall(
+              getFlutterCommand(mockPlatform),
+              const <String>['test', '--color'],
+              pluginDir.childDirectory('example').path),
+        ]),
+      );
+    });
+
     test('fails when Flutter tests fail', () async {
       createFakePlugin('plugin1', packagesDir,
           extraFiles: <String>['test/empty_test.dart']);
@@ -102,7 +124,7 @@
       );
     });
 
-    test('runs pub run test on non-Flutter packages', () async {
+    test('runs dart run test on non-Flutter packages', () async {
       final Directory pluginDir = createFakePlugin('a', packagesDir,
           extraFiles: <String>['test/empty_test.dart']);
       final Directory packageDir = createFakePackage('b', packagesDir,
@@ -121,12 +143,34 @@
           ProcessCall('dart', const <String>['pub', 'get'], packageDir.path),
           ProcessCall(
               'dart',
-              const <String>['pub', 'run', '--enable-experiment=exp1', 'test'],
+              const <String>['run', '--enable-experiment=exp1', 'test'],
               packageDir.path),
         ]),
       );
     });
 
+    test('runs dart run test on non-Flutter package examples', () async {
+      final Directory packageDir = createFakePackage('a_package', packagesDir,
+          extraFiles: <String>[
+            'test/empty_test.dart',
+            'example/test/an_example_test.dart'
+          ]);
+
+      await runCapturingPrint(runner, <String>['test']);
+
+      expect(
+        processRunner.recordedCalls,
+        orderedEquals(<ProcessCall>[
+          ProcessCall('dart', const <String>['pub', 'get'], packageDir.path),
+          ProcessCall('dart', const <String>['run', 'test'], packageDir.path),
+          ProcessCall('dart', const <String>['pub', 'get'],
+              packageDir.childDirectory('example').path),
+          ProcessCall('dart', const <String>['run', 'test'],
+              packageDir.childDirectory('example').path),
+        ]),
+      );
+    });
+
     test('fails when getting non-Flutter package dependencies fails', () async {
       createFakePackage('a_package', packagesDir,
           extraFiles: <String>['test/empty_test.dart']);
@@ -217,7 +261,7 @@
           ProcessCall('dart', const <String>['pub', 'get'], packageDir.path),
           ProcessCall(
               'dart',
-              const <String>['pub', 'run', '--enable-experiment=exp1', 'test'],
+              const <String>['run', '--enable-experiment=exp1', 'test'],
               packageDir.path),
         ]),
       );