diff --git a/tools/engine_tool/lib/src/commands/test_command.dart b/tools/engine_tool/lib/src/commands/test_command.dart index 20381fb1718bc..63dd438c1dabb 100644 --- a/tools/engine_tool/lib/src/commands/test_command.dart +++ b/tools/engine_tool/lib/src/commands/test_command.dart @@ -70,10 +70,10 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f ); } + final List testTargets = []; for (final BuildTarget target in selectedTargets) { - if (!target.testOnly || target.type != BuildTargetType.executable) { - // Remove any targets that aren't testOnly and aren't executable. - selectedTargets.remove(target); + if (_isTestExecutable(target)) { + testTargets.add(target); } if (target.executable == null) { environment.logger.fatal( @@ -81,7 +81,7 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f } } // Chop off the '//' prefix. - final List buildTargets = selectedTargets + final List buildTargets = testTargets .map( (BuildTarget target) => target.label.substring('//'.length)) .toList(); @@ -95,11 +95,16 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f final WorkerPool workerPool = WorkerPool(environment, ProcessTaskProgressReporter(environment)); final Set tasks = {}; - for (final BuildTarget target in selectedTargets) { + for (final BuildTarget target in testTargets) { final List commandLine = [target.executable!.path]; tasks.add(ProcessTask( target.label, environment, environment.engine.srcDir, commandLine)); } return await workerPool.run(tasks) ? 0 : 1; } + + /// Returns true if `target` is a testonly executable. + static bool _isTestExecutable(BuildTarget target) { + return target.testOnly && target.type == BuildTargetType.executable; + } } diff --git a/tools/engine_tool/test/test_command_test.dart b/tools/engine_tool/test/test_command_test.dart index b8e5788b63976..ecc86d3f8b28d 100644 --- a/tools/engine_tool/test/test_command_test.dart +++ b/tools/engine_tool/test/test_command_test.dart @@ -67,4 +67,28 @@ void main() { testEnvironment.cleanup(); } }); + + test('test command skips non-testonly executables', () async { + final TestEnvironment testEnvironment = TestEnvironment.withTestEngine( + cannedProcesses: cannedProcesses, + ); + try { + final Environment env = testEnvironment.environment; + final ToolCommandRunner runner = ToolCommandRunner( + environment: env, + configs: configs, + ); + final int result = await runner.run([ + 'test', + '//third_party/protobuf:protoc', + ]); + expect(result, equals(1)); + expect(testEnvironment.processHistory.length, lessThan(3)); + expect(testEnvironment.processHistory.where((ExecutedProcess process) { + return process.command[0].contains('protoc'); + }), isEmpty); + } finally { + testEnvironment.cleanup(); + } + }); }