Remove the need to use runZoned by replacing print statements (flutter/engine#55530)

This commit is contained in:
Matan Lurey 2024-09-30 14:33:21 -07:00 committed by GitHub
parent bdd730c32c
commit a38103ac0e
3 changed files with 55 additions and 56 deletions

View File

@ -28,6 +28,11 @@ abstract base class CommandBase extends Command<int> {
@override
final ArgParser argParser;
@override
void printUsage() {
environment.logger.status(usage);
}
}
/// Adds the -c (--config) option to the parser.

View File

@ -103,4 +103,9 @@ final class ToolCommandRunner extends CommandRunner<int> {
return 1;
}
}
@override
void printUsage() {
environment.logger.status(usage);
}
}

View File

@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert' as convert;
import 'package:engine_build_configs/engine_build_configs.dart';
@ -449,65 +448,55 @@ void main() {
});
test('et help build line length is not too big', () async {
final prints = <String>[];
await runZoned(
() async {
final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
verbose: true,
);
addTearDown(testEnv.cleanup);
final runner = ToolCommandRunner(
environment: testEnv.environment,
configs: configs,
help: true,
);
final result = await runner.run([
'help',
'build',
]);
expect(result, equals(0));
},
zoneSpecification: ZoneSpecification(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
prints.addAll(line.split('\n'));
},
),
final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
verbose: true,
);
addTearDown(testEnv.cleanup);
final runner = ToolCommandRunner(
environment: testEnv.environment,
configs: configs,
help: true,
);
final result = await runner.run([
'help',
'build',
]);
expect(result, equals(0));
// Avoid a degenerate case where nothing is logged.
expect(testEnv.testLogs, isNotEmpty, reason: 'No logs were emitted');
expect(
testEnv.testLogs.map((LogRecord r) => r.message.split('\n')),
everyElement(hasLength(lessThanOrEqualTo(100))),
);
for (final line in prints) {
expect(line.length, lessThanOrEqualTo(100));
}
});
test('non-verbose "et help build" does not contain ci builds', () async {
final prints = <String>[];
await runZoned(
() async {
final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);
final runner = ToolCommandRunner(
environment: testEnv.environment,
configs: configs,
help: true,
);
final result = await runner.run([
'help',
'build',
]);
expect(result, equals(0));
},
zoneSpecification: ZoneSpecification(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
prints.addAll(line.split('\n'));
},
),
final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);
final runner = ToolCommandRunner(
environment: testEnv.environment,
configs: configs,
help: true,
);
final result = await runner.run([
'help',
'build',
]);
expect(result, equals(0));
// Avoid a degenerate case where nothing is logged.
expect(testEnv.testLogs, isNotEmpty, reason: 'No logs were emitted');
expect(
testEnv.testLogs.map((LogRecord r) => r.message),
isNot(contains('[ci/')),
);
for (final line in prints) {
expect(line.contains('[ci/'), isFalse);
}
});
}