@@ -6,17 +6,19 @@ import 'package:file/file.dart';
6
6
import 'package:path/path.dart' as p;
7
7
8
8
import 'common/core.dart' ;
9
- import 'common/plugin_command .dart' ;
9
+ import 'common/package_looping_command .dart' ;
10
10
import 'common/process_runner.dart' ;
11
11
12
12
/// A command to run the Java tests of Android plugins.
13
- class JavaTestCommand extends PluginCommand {
13
+ class JavaTestCommand extends PackageLoopingCommand {
14
14
/// Creates an instance of the test runner.
15
15
JavaTestCommand (
16
16
Directory packagesDir, {
17
17
ProcessRunner processRunner = const ProcessRunner (),
18
18
}) : super (packagesDir, processRunner: processRunner);
19
19
20
+ static const String _gradleWrapper = 'gradlew' ;
21
+
20
22
@override
21
23
final String name = 'java-test' ;
22
24
@@ -25,12 +27,10 @@ class JavaTestCommand extends PluginCommand {
25
27
'Building the apks of the example apps is required before executing this'
26
28
'command.' ;
27
29
28
- static const String _gradleWrapper = 'gradlew' ;
29
-
30
30
@override
31
- Future <void > run ( ) async {
32
- final Stream <Directory > examplesWithTests = getExamples (). where (
33
- (Directory d) =>
31
+ Future <List < String >> runForPackage ( Directory package ) async {
32
+ final Iterable <Directory > examplesWithTests = getExamplesForPlugin (package)
33
+ . where ( (Directory d) =>
34
34
isFlutterPackage (d) &&
35
35
(d
36
36
.childDirectory ('android' )
@@ -44,18 +44,17 @@ class JavaTestCommand extends PluginCommand {
44
44
.childDirectory ('test' )
45
45
.existsSync ()));
46
46
47
- final List <String > failingPackages = < String > [];
48
- final List <String > missingFlutterBuild = < String > [];
49
- await for (final Directory example in examplesWithTests) {
50
- final String packageName =
51
- p.relative (example.path, from: packagesDir.path);
52
- print ('\n RUNNING JAVA TESTS for $packageName ' );
47
+ final List <String > errors = < String > [];
48
+ for (final Directory example in examplesWithTests) {
49
+ final String exampleName = p.relative (example.path, from: package.path);
50
+ print ('\n RUNNING JAVA TESTS for $exampleName ' );
53
51
54
52
final Directory androidDirectory = example.childDirectory ('android' );
55
53
if (! androidDirectory.childFile (_gradleWrapper).existsSync ()) {
56
- print ('ERROR: Run "flutter build apk" on example app of $packageName '
54
+ printError ('ERROR: Run "flutter build apk" on $exampleName , or run '
55
+ 'this tool\' s "build-examples --apk" command, '
57
56
'before executing tests.' );
58
- missingFlutterBuild .add (packageName );
57
+ errors .add ('$ exampleName has not been built.' );
59
58
continue ;
60
59
}
61
60
@@ -64,31 +63,9 @@ class JavaTestCommand extends PluginCommand {
64
63
< String > ['testDebugUnitTest' , '--info' ],
65
64
workingDir: androidDirectory);
66
65
if (exitCode != 0 ) {
67
- failingPackages.add (packageName);
68
- }
69
- }
70
-
71
- print ('\n\n ' );
72
- if (failingPackages.isNotEmpty) {
73
- print (
74
- 'The Java tests for the following packages are failing (see above for'
75
- 'details):' );
76
- for (final String package in failingPackages) {
77
- print (' * $package ' );
78
- }
79
- }
80
- if (missingFlutterBuild.isNotEmpty) {
81
- print ('Run "pub global run flutter_plugin_tools build-examples --apk" on'
82
- 'the following packages before executing tests again:' );
83
- for (final String package in missingFlutterBuild) {
84
- print (' * $package ' );
66
+ errors.add ('$exampleName tests failed.' );
85
67
}
86
68
}
87
-
88
- if (failingPackages.isNotEmpty || missingFlutterBuild.isNotEmpty) {
89
- throw ToolExit (1 );
90
- }
91
-
92
- print ('All Java tests successful!' );
69
+ return errors;
93
70
}
94
71
}
0 commit comments