From 449045c85d07a1e20514285ffc21c12df6aa91ed Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sat, 20 Apr 2024 11:57:47 -0700 Subject: [PATCH] Add tests --- .../engine_tool/test/build_command_test.dart | 5 +-- tools/engine_tool/test/fixtures.dart | 17 ++++++++- tools/engine_tool/test/test_command_test.dart | 36 ++++++++++++++++++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/tools/engine_tool/test/build_command_test.dart b/tools/engine_tool/test/build_command_test.dart index 5bf07a1aefbc0..9f0621e6a29d8 100644 --- a/tools/engine_tool/test/build_command_test.dart +++ b/tools/engine_tool/test/build_command_test.dart @@ -403,12 +403,13 @@ void main() { ]); expect(result, equals(0)); expect(testEnv.processHistory, containsCommand((List command) { - return command.length > 7 && + return command.length > 8 && 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'; + command[7] == 'flutter/fml:fml_arc_unittests' && + command[8] == 'flutter/tools/engine_tool:build_command_test'; })); } finally { testEnv.cleanup(); diff --git a/tools/engine_tool/test/fixtures.dart b/tools/engine_tool/test/fixtures.dart index 53e088d3b213e..6f1f2eab9e7bf 100644 --- a/tools/engine_tool/test/fixtures.dart +++ b/tools/engine_tool/test/fixtures.dart @@ -316,6 +316,21 @@ String gnDescOutput() => ''' "toolchain": "//build/toolchain/mac:clang_x64", "type": "executable", "visibility": [ "*" ] - } + }, + "//flutter/tools/engine_tool:build_command_test": { + "args": [ "../../flutter/prebuilts/macos-x64/dart-sdk/bin/dart", "--deterministic", "compile", "exe", "--packages=/Users/chris/Developer/flutter/engine/src/flutter/tools/engine_tool/.dart_tool/package_config.json", "--output=/Users/chris/Developer/flutter/engine/src/out/host_debug/gen/flutter/tools/engine_tool/build_command_test", "/Users/chris/Developer/flutter/engine/src/flutter/tools/engine_tool/test/build_command_test.dart" ], + "deps": [ ], + "inputs": [ "//flutter/tools/engine_tool/test/build_command_test.dart", "//flutter/tools/engine_tool/.dart_tool/package_config.json" ], + "metadata": { + "action_type": [ "dart_executable" ] + }, + "outputs": [ "//out/host_debug/gen/flutter/tools/engine_tool/build_command_test" ], + "public": "*", + "script": "//build/gn_run_binary.py", + "testonly": true, + "toolchain": "//build/toolchain/mac:clang_x64", + "type": "action", + "visibility": [ "*" ] + } } '''; diff --git a/tools/engine_tool/test/test_command_test.dart b/tools/engine_tool/test/test_command_test.dart index ecc86d3f8b28d..d9c010c487ad2 100644 --- a/tools/engine_tool/test/test_command_test.dart +++ b/tools/engine_tool/test/test_command_test.dart @@ -42,9 +42,19 @@ void main() { final List cannedProcesses = [ CannedProcess((List command) => command.contains('desc'), stdout: fixtures.gnDescOutput()), + CannedProcess( + (List command) => + command.contains('outputs') && + command.contains("display_list_unittests"), + stdout: fixtures.gnOutputsDisplayListUnittestsOutput()), + CannedProcess( + (List command) => + command.contains('outputs') && + command.contains("build_command_test"), + stdout: fixtures.gnOutputsBuildCommandTestOutput()), ]; - test('test command executes test', () async { + test('test command executes executable test', () async { final TestEnvironment testEnvironment = TestEnvironment.withTestEngine( cannedProcesses: cannedProcesses, ); @@ -68,6 +78,30 @@ void main() { } }); + test('test command executes dart_executable test', () 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', + '//flutter/tools/engine_test:build_command_test', + ]); + expect(result, equals(0)); + expect(testEnvironment.processHistory.length, greaterThan(3)); + final int offset = testEnvironment.processHistory.length - 1; + expect(testEnvironment.processHistory[offset].command[0], + endsWith('build_command_test')); + } finally { + testEnvironment.cleanup(); + } + }); + test('test command skips non-testonly executables', () async { final TestEnvironment testEnvironment = TestEnvironment.withTestEngine( cannedProcesses: cannedProcesses,