Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cbracken committed Apr 20, 2024
1 parent b4126bf commit 94ab19b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tools/engine_tool/lib/src/commands/test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f

final List<BuildTarget> testTargets = <BuildTarget>[];
for (final BuildTarget target in selectedTargets) {
if (target.testOnly && target.type == BuildTargetType.executable) {
if (_isTestExecutable(target)) {
testTargets.add(target);
}
if (target.executable == null) {
Expand Down Expand Up @@ -102,4 +102,9 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
}
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;
}
}
24 changes: 24 additions & 0 deletions tools/engine_tool/test/test_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(<String>[
'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();
}
});
}

0 comments on commit 94ab19b

Please sign in to comment.