Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 94ab19b

Browse files
committed
Add unit test
1 parent b4126bf commit 94ab19b

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

tools/engine_tool/lib/src/commands/test_command.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
7272

7373
final List<BuildTarget> testTargets = <BuildTarget>[];
7474
for (final BuildTarget target in selectedTargets) {
75-
if (target.testOnly && target.type == BuildTargetType.executable) {
75+
if (_isTestExecutable(target)) {
7676
testTargets.add(target);
7777
}
7878
if (target.executable == null) {
@@ -102,4 +102,9 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
102102
}
103103
return await workerPool.run(tasks) ? 0 : 1;
104104
}
105+
106+
/// Returns true if `target` is a testonly executable.
107+
static bool _isTestExecutable(BuildTarget target) {
108+
return target.testOnly && target.type == BuildTargetType.executable;
109+
}
105110
}

tools/engine_tool/test/test_command_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,28 @@ void main() {
6767
testEnvironment.cleanup();
6868
}
6969
});
70+
71+
test('test command skips non-testonly executables', () async {
72+
final TestEnvironment testEnvironment = TestEnvironment.withTestEngine(
73+
cannedProcesses: cannedProcesses,
74+
);
75+
try {
76+
final Environment env = testEnvironment.environment;
77+
final ToolCommandRunner runner = ToolCommandRunner(
78+
environment: env,
79+
configs: configs,
80+
);
81+
final int result = await runner.run(<String>[
82+
'test',
83+
'//third_party/protobuf:protoc',
84+
]);
85+
expect(result, equals(1));
86+
expect(testEnvironment.processHistory.length, lessThan(3));
87+
expect(testEnvironment.processHistory.where((ExecutedProcess process) {
88+
return process.command[0].contains("protoc");
89+
}), isEmpty);
90+
} finally {
91+
testEnvironment.cleanup();
92+
}
93+
});
7094
}

0 commit comments

Comments
 (0)