Unverified Commit ff9082cf authored by Yegor's avatar Yegor Committed by GitHub

Refactor command utilities for tests (#68324)

* refactor command running utilities for tests
Co-authored-by: 's avatarJonah Williams <jonahwilliams@google.com>
parent 03b5825d
This diff is collapsed.
...@@ -26,7 +26,7 @@ typedef ShardRunner = Future<void> Function(); ...@@ -26,7 +26,7 @@ typedef ShardRunner = Future<void> Function();
/// ///
/// If the output does not match expectations, the function shall return an /// If the output does not match expectations, the function shall return an
/// appropriate error message. /// appropriate error message.
typedef OutputChecker = String Function(CapturedOutput); typedef OutputChecker = String Function(CommandResult);
final String exe = Platform.isWindows ? '.exe' : ''; final String exe = Platform.isWindows ? '.exe' : '';
final String bat = Platform.isWindows ? '.bat' : ''; final String bat = Platform.isWindows ? '.bat' : '';
...@@ -143,9 +143,8 @@ Future<void> _validateEngineHash() async { ...@@ -143,9 +143,8 @@ Future<void> _validateEngineHash() async {
return; return;
} }
final String expectedVersion = File(engineVersionFile).readAsStringSync().trim(); final String expectedVersion = File(engineVersionFile).readAsStringSync().trim();
final CapturedOutput flutterTesterOutput = CapturedOutput(); final CommandResult result = await runCommand(flutterTester, <String>['--help'], outputMode: OutputMode.capture);
await runCommand(flutterTester, <String>['--help'], output: flutterTesterOutput, outputMode: OutputMode.capture); final String actualVersion = result.flattenedStderr.split('\n').firstWhere((final String line) {
final String actualVersion = flutterTesterOutput.stderr.split('\n').firstWhere((final String line) {
return line.startsWith('Flutter Engine Version:'); return line.startsWith('Flutter Engine Version:');
}); });
if (!actualVersion.contains(expectedVersion)) { if (!actualVersion.contains(expectedVersion)) {
...@@ -190,8 +189,8 @@ Future<void> _runSmokeTests() async { ...@@ -190,8 +189,8 @@ Future<void> _runSmokeTests() async {
script: path.join('test_smoke_test', 'pending_timer_fail_test.dart'), script: path.join('test_smoke_test', 'pending_timer_fail_test.dart'),
expectFailure: true, expectFailure: true,
printOutput: false, printOutput: false,
outputChecker: (CapturedOutput output) { outputChecker: (CommandResult result) {
return output.stdout.contains('failingPendingTimerTest') return result.flattenedStdout.contains('failingPendingTimerTest')
? null ? null
: 'Failed to find the stack trace for the pending Timer.'; : 'Failed to find the stack trace for the pending Timer.';
} }
...@@ -230,7 +229,7 @@ Future<void> _runSmokeTests() async { ...@@ -230,7 +229,7 @@ Future<void> _runSmokeTests() async {
<String>['drive', '--use-existing-app', '-t', path.join('test_driver', 'failure.dart')], <String>['drive', '--use-existing-app', '-t', path.join('test_driver', 'failure.dart')],
workingDirectory: path.join(flutterRoot, 'packages', 'flutter_driver'), workingDirectory: path.join(flutterRoot, 'packages', 'flutter_driver'),
expectNonZeroExit: true, expectNonZeroExit: true,
outputMode: OutputMode.discard, outputMode: OutputMode.capture,
), ),
], ],
); );
...@@ -287,7 +286,7 @@ Future<void> _runToolCoverage() async { ...@@ -287,7 +286,7 @@ Future<void> _runToolCoverage() async {
'--report-on=lib/' '--report-on=lib/'
], ],
workingDirectory: toolRoot, workingDirectory: toolRoot,
outputMode: OutputMode.discard, outputMode: OutputMode.capture,
); );
} }
...@@ -642,11 +641,11 @@ Future<void> _runFrameworkTests() async { ...@@ -642,11 +641,11 @@ Future<void> _runFrameworkTests() async {
script: path.join('test', 'bindings_test_failure.dart'), script: path.join('test', 'bindings_test_failure.dart'),
expectFailure: true, expectFailure: true,
printOutput: false, printOutput: false,
outputChecker: (CapturedOutput output) { outputChecker: (CommandResult result) {
final Iterable<Match> matches = httpClientWarning.allMatches(output.stdout); final Iterable<Match> matches = httpClientWarning.allMatches(result.flattenedStdout);
if (matches == null || matches.isEmpty || matches.length > 1) { if (matches == null || matches.isEmpty || matches.length > 1) {
return 'Failed to print warning about HttpClientUsage, or printed it too many times.\n' return 'Failed to print warning about HttpClientUsage, or printed it too many times.\n'
'stdout:\n${output.stdout}'; 'stdout:\n${result.flattenedStdout}';
} }
return null; return null;
}, },
...@@ -868,9 +867,8 @@ Future<void> _runWebDebugTest(String target, { ...@@ -868,9 +867,8 @@ Future<void> _runWebDebugTest(String target, {
List<String> additionalArguments = const<String>[], List<String> additionalArguments = const<String>[],
}) async { }) async {
final String testAppDirectory = path.join(flutterRoot, 'dev', 'integration_tests', 'web'); final String testAppDirectory = path.join(flutterRoot, 'dev', 'integration_tests', 'web');
final CapturedOutput output = CapturedOutput();
bool success = false; bool success = false;
await runCommand( final CommandResult result = await runCommand(
flutter, flutter,
<String>[ <String>[
'run', 'run',
...@@ -889,7 +887,6 @@ Future<void> _runWebDebugTest(String target, { ...@@ -889,7 +887,6 @@ Future<void> _runWebDebugTest(String target, {
'-t', '-t',
target, target,
], ],
output: output,
outputMode: OutputMode.capture, outputMode: OutputMode.capture,
outputListener: (String line, Process process) { outputListener: (String line, Process process) {
if (line.contains('--- TEST SUCCEEDED ---')) { if (line.contains('--- TEST SUCCEEDED ---')) {
...@@ -908,7 +905,8 @@ Future<void> _runWebDebugTest(String target, { ...@@ -908,7 +905,8 @@ Future<void> _runWebDebugTest(String target, {
if (success) { if (success) {
print('${green}Web stack trace integration test passed.$reset'); print('${green}Web stack trace integration test passed.$reset');
} else { } else {
print(output.stdout); print(result.flattenedStdout);
print(result.flattenedStderr);
print('${red}Web stack trace integration test failed.$reset'); print('${red}Web stack trace integration test failed.$reset');
exit(1); exit(1);
} }
...@@ -1125,29 +1123,22 @@ Future<void> _runFlutterTest(String workingDirectory, { ...@@ -1125,29 +1123,22 @@ Future<void> _runFlutterTest(String workingDirectory, {
args.addAll(tests); args.addAll(tests);
if (!shouldProcessOutput) { if (!shouldProcessOutput) {
OutputMode outputMode = OutputMode.discard; final OutputMode outputMode = outputChecker == null && printOutput
CapturedOutput output; ? OutputMode.print
: OutputMode.capture;
if (outputChecker != null) { final CommandResult result = await runCommand(
outputMode = OutputMode.capture;
output = CapturedOutput();
} else if (printOutput) {
outputMode = OutputMode.print;
}
await runCommand(
flutter, flutter,
args, args,
workingDirectory: workingDirectory, workingDirectory: workingDirectory,
expectNonZeroExit: expectFailure, expectNonZeroExit: expectFailure,
outputMode: outputMode, outputMode: outputMode,
output: output,
skip: skip, skip: skip,
environment: environment, environment: environment,
); );
if (outputChecker != null) { if (outputChecker != null) {
final String message = outputChecker(output); final String message = outputChecker(result);
if (message != null) if (message != null)
exitWithError(<String>[message]); exitWithError(<String>[message]);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment