flutter/dev/bots/test/run_command_test.dart
Michael Goderbauer 5491c8c146
Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
2024-12-19 20:06:21 +00:00

66 lines
3.1 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io' as io;
import '../run_command.dart';
import '../utils.dart';
import 'common.dart';
void main() {
// These tests only run on Linux. They test platform-agnostic code that is
// triggered by platform-sensitive code. To avoid having to complicate our
// test harness by using a mockable process manager, the tests rely on one
// platform's conventions (Linux having `sh`). The logic being tested is not
// so critical that it matters that we're only testing it on one platform.
test('short output on runCommand failure', () async {
final List<Object?> log = <String>[];
final PrintCallback oldPrint = print;
print = log.add;
try {
await runCommand('/usr/bin/sh', <String>['-c', 'echo test; false']);
expect(log, <Object>[
startsWith('RUNNING:'),
'workingDirectory: null, executable: /usr/bin/sh, arguments: [-c, echo test; false]',
'test',
'╔═╡ERROR #1╞════════════════════════════════════════════════════════════════════',
startsWith('║ Command: '),
'║ Command exited with exit code 1 but expected zero exit code.',
startsWith('║ Working directory: '),
'║ stdout and stderr output:',
'║ test',
'',
'╚═══════════════════════════════════════════════════════════════════════════════',
]);
} finally {
print = oldPrint;
resetErrorStatus();
}
}, skip: !io.Platform.isLinux); // [intended] See comments above.
test('long output on runCommand failure', () async {
final List<Object?> log = <String>[];
final PrintCallback oldPrint = print;
print = log.add;
try {
await runCommand('/usr/bin/sh', <String>['-c', 'echo ${"meow" * 1024}; false']);
expect(log, <Object>[
startsWith('RUNNING:'),
'workingDirectory: null, executable: /usr/bin/sh, arguments: [-c, echo ${"meow" * 1024}; false]',
'meow' * 1024,
'╔═╡ERROR #1╞════════════════════════════════════════════════════════════════════',
startsWith('║ Command: '),
'║ Command exited with exit code 1 but expected zero exit code.',
startsWith('║ Working directory: '),
'╚═══════════════════════════════════════════════════════════════════════════════',
]);
} finally {
print = oldPrint;
resetErrorStatus();
}
}, skip: !io.Platform.isLinux); // [intended] See comments above.
}