Skip to content

Commit

Permalink
[flutter_plugin_tools] Include examples in test (flutter#5453)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmorgan authored May 3, 2022
1 parent 580de32 commit bce32f6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
3 changes: 2 additions & 1 deletion script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
4 changes: 3 additions & 1 deletion script/tool/lib/src/test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class TestCommand extends PackageLoopingCommand {
final String description = 'Runs the Dart tests for all packages.\n\n'
'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()) {
Expand Down Expand Up @@ -88,7 +91,6 @@ class TestCommand extends PackageLoopingCommand {
exitCode = await processRunner.runAndStream(
'dart',
<String>[
'pub',
'run',
if (experiment.isNotEmpty) '--enable-experiment=$experiment',
'test',
Expand Down
2 changes: 1 addition & 1 deletion script/tool/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
50 changes: 47 additions & 3 deletions script/tool/test/test_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ void main() {
);
});

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']);
Expand Down Expand Up @@ -102,7 +124,7 @@ void main() {
);
});

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,
Expand All @@ -121,12 +143,34 @@ void main() {
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']);
Expand Down Expand Up @@ -217,7 +261,7 @@ void main() {
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),
]),
);
Expand Down

0 comments on commit bce32f6

Please sign in to comment.