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 @override
final ArgParser argParser; final ArgParser argParser;
@override
void printUsage() {
environment.logger.status(usage);
}
} }
/// Adds the -c (--config) option to the parser. /// Adds the -c (--config) option to the parser.

View File

@ -103,4 +103,9 @@ final class ToolCommandRunner extends CommandRunner<int> {
return 1; 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'dart:convert' as convert; import 'dart:convert' as convert;
import 'package:engine_build_configs/engine_build_configs.dart'; import 'package:engine_build_configs/engine_build_configs.dart';
@ -449,9 +448,6 @@ void main() {
}); });
test('et help build line length is not too big', () async { test('et help build line length is not too big', () async {
final prints = <String>[];
await runZoned(
() async {
final testEnv = TestEnvironment.withTestEngine( final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses, cannedProcesses: cannedProcesses,
verbose: true, verbose: true,
@ -468,22 +464,17 @@ void main() {
'build', 'build',
]); ]);
expect(result, equals(0)); expect(result, equals(0));
},
zoneSpecification: ZoneSpecification( // Avoid a degenerate case where nothing is logged.
print: (Zone self, ZoneDelegate parent, Zone zone, String line) { expect(testEnv.testLogs, isNotEmpty, reason: 'No logs were emitted');
prints.addAll(line.split('\n'));
}, 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 { test('non-verbose "et help build" does not contain ci builds', () async {
final prints = <String>[];
await runZoned(
() async {
final testEnv = TestEnvironment.withTestEngine( final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses, cannedProcesses: cannedProcesses,
); );
@ -499,15 +490,13 @@ void main() {
'build', 'build',
]); ]);
expect(result, equals(0)); expect(result, equals(0));
},
zoneSpecification: ZoneSpecification( // Avoid a degenerate case where nothing is logged.
print: (Zone self, ZoneDelegate parent, Zone zone, String line) { expect(testEnv.testLogs, isNotEmpty, reason: 'No logs were emitted');
prints.addAll(line.split('\n'));
}, expect(
), testEnv.testLogs.map((LogRecord r) => r.message),
isNot(contains('[ci/')),
); );
for (final line in prints) {
expect(line.contains('[ci/'), isFalse);
}
}); });
} }