diff --git a/tools/engine_tool/test/build_command_test.dart b/tools/engine_tool/test/build_command_test.dart index a8a67d55f2a78..fdf1394a401f0 100644 --- a/tools/engine_tool/test/build_command_test.dart +++ b/tools/engine_tool/test/build_command_test.dart @@ -360,13 +360,12 @@ void main() { '//flutter/fml:fml_arc_unittests', ]); expect(result, equals(0)); - expect(testEnv.processHistory.length, greaterThanOrEqualTo(2)); - expect(testEnv.processHistory[6].command[0], contains('ninja')); - expect(testEnv.processHistory[6].command[2], endsWith('/host_debug')); - expect( - testEnv.processHistory[6].command[5], - equals('flutter/fml:fml_arc_unittests'), - ); + expect(testEnv.processHistory, containsCommand((List command) { + return command.length > 4 && + command[0].contains('ninja') && + command[2].endsWith('/host_debug') && + command[5] == 'flutter/fml:fml_arc_unittests'; + })); } finally { testEnv.cleanup(); } @@ -389,21 +388,14 @@ void main() { '//flutter/...', ]); expect(result, equals(0)); - expect(testEnv.processHistory.length, greaterThanOrEqualTo(2)); - expect(testEnv.processHistory[6].command[0], contains('ninja')); - expect(testEnv.processHistory[6].command[2], endsWith('/host_debug')); - expect( - testEnv.processHistory[6].command[5], - equals('flutter/display_list:display_list_unittests'), - ); - expect( - testEnv.processHistory[6].command[6], - equals('flutter/flow:flow_unittests'), - ); - expect( - testEnv.processHistory[6].command[7], - equals('flutter/fml:fml_arc_unittests'), - ); + expect(testEnv.processHistory, containsCommand((List command) { + return command.length > 7 && + command[0].contains('ninja') && + command[2].endsWith('/host_debug') && + command[5] == 'flutter/display_list:display_list_unittests' && + command[6] == 'flutter/flow:flow_unittests' && + command[7] == 'flutter/fml:fml_arc_unittests'; + })); } finally { testEnv.cleanup(); } diff --git a/tools/engine_tool/test/utils.dart b/tools/engine_tool/test/utils.dart index a6955933c6c79..a5035a90673db 100644 --- a/tools/engine_tool/test/utils.dart +++ b/tools/engine_tool/test/utils.dart @@ -8,6 +8,7 @@ import 'dart:io' as io; import 'package:engine_repo_tools/engine_repo_tools.dart'; import 'package:engine_tool/src/environment.dart'; import 'package:engine_tool/src/logger.dart'; +import 'package:litetest/litetest.dart' show Expect, Matcher; import 'package:path/path.dart' as path; import 'package:platform/platform.dart'; import 'package:process_fakes/process_fakes.dart'; @@ -169,3 +170,26 @@ FakeProcess _getCannedResult( } return FakeProcess(); } + +typedef CommandMatcher = bool Function(List command); + +/// Returns a [Matcher] that fails the test if no process has a matching command. +/// +/// Usage: +/// expect(testEnv.processHistory, +/// containsCommand((List command) { +/// return command.length > 5 && +/// command[0].contains('ninja') && +/// command[2].endsWith('/host_debug') && +/// command[5] == 'flutter/fml:fml_arc_unittests'; +/// }) +/// ); +Matcher containsCommand(CommandMatcher commandMatcher) => (dynamic processes) { + Expect.type>(processes); + final List> commands = (processes as List) + .map((ExecutedProcess process) => process.command) + .toList(); + if (!commands.any(commandMatcher)) { + Expect.fail("No process found with matching command"); + } + };