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,65 +448,55 @@ 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>[]; final testEnv = TestEnvironment.withTestEngine(
await runZoned( cannedProcesses: cannedProcesses,
() async { verbose: true,
final testEnv = TestEnvironment.withTestEngine( );
cannedProcesses: cannedProcesses, addTearDown(testEnv.cleanup);
verbose: true,
); final runner = ToolCommandRunner(
addTearDown(testEnv.cleanup); environment: testEnv.environment,
configs: configs,
final runner = ToolCommandRunner( help: true,
environment: testEnv.environment, );
configs: configs, final result = await runner.run([
help: true, 'help',
); 'build',
final result = await runner.run([ ]);
'help', expect(result, equals(0));
'build',
]); // Avoid a degenerate case where nothing is logged.
expect(result, equals(0)); expect(testEnv.testLogs, isNotEmpty, reason: 'No logs were emitted');
},
zoneSpecification: ZoneSpecification( expect(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) { testEnv.testLogs.map((LogRecord r) => r.message.split('\n')),
prints.addAll(line.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>[]; final testEnv = TestEnvironment.withTestEngine(
await runZoned( cannedProcesses: cannedProcesses,
() async { );
final testEnv = TestEnvironment.withTestEngine( addTearDown(testEnv.cleanup);
cannedProcesses: cannedProcesses,
); final runner = ToolCommandRunner(
addTearDown(testEnv.cleanup); environment: testEnv.environment,
configs: configs,
final runner = ToolCommandRunner( help: true,
environment: testEnv.environment, );
configs: configs, final result = await runner.run([
help: true, 'help',
); 'build',
final result = await runner.run([ ]);
'help', expect(result, equals(0));
'build',
]); // Avoid a degenerate case where nothing is logged.
expect(result, equals(0)); expect(testEnv.testLogs, isNotEmpty, reason: 'No logs were emitted');
},
zoneSpecification: ZoneSpecification( expect(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) { testEnv.testLogs.map((LogRecord r) => r.message),
prints.addAll(line.split('\n')); isNot(contains('[ci/')),
},
),
); );
for (final line in prints) {
expect(line.contains('[ci/'), isFalse);
}
}); });
} }