mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
suppress output from intentionally failing tests (flutter/engine#26253)
* suppress output from intentionally failing tests
This commit is contained in:
parent
c9acd920ac
commit
f68d1a66cc
@ -10,8 +10,21 @@ import 'package:args/command_runner.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:pool/pool.dart';
|
||||
|
||||
// TODO(yjbanov): remove hacks when this is fixed:
|
||||
// https://github.com/dart-lang/test/issues/1521
|
||||
import 'package:test_api/src/backend/live_test.dart'
|
||||
as hack;
|
||||
import 'package:test_api/src/backend/group.dart'
|
||||
as hack;
|
||||
import 'package:test_core/src/runner/configuration/reporters.dart'
|
||||
as hack;
|
||||
import 'package:test_core/src/runner/engine.dart'
|
||||
as hack;
|
||||
import 'package:test_core/src/runner/hack_register_platform.dart'
|
||||
as hack;
|
||||
import 'package:test_core/src/runner/reporter.dart'
|
||||
as hack;
|
||||
import 'package:test_api/src/backend/runtime.dart';
|
||||
import 'package:test_core/src/executable.dart'
|
||||
as test;
|
||||
@ -770,6 +783,9 @@ class TestCommand extends Command<bool> with ArgUtils {
|
||||
...<String>['-r', 'compact'],
|
||||
'--concurrency=$concurrency',
|
||||
if (isDebug) '--pause-after-load',
|
||||
// Don't pollute logs with output from tests that are expected to fail.
|
||||
if (expectFailure)
|
||||
'--reporter=name-only',
|
||||
'--platform=${SupportedBrowsers.instance.supportedBrowserToPlatform[browser]}',
|
||||
'--precompiled=${environment.webUiRootDir.path}/build',
|
||||
SupportedBrowsers.instance.browserToConfiguration[browser],
|
||||
@ -777,6 +793,15 @@ class TestCommand extends Command<bool> with ArgUtils {
|
||||
...testFiles.map((f) => f.relativeToWebUi).toList(),
|
||||
];
|
||||
|
||||
if (expectFailure) {
|
||||
hack.registerReporter(
|
||||
'name-only',
|
||||
hack.ReporterDetails(
|
||||
'Prints the name of the test, but suppresses all other test output.',
|
||||
(_, hack.Engine engine, __) => NameOnlyReporter(engine)),
|
||||
);
|
||||
}
|
||||
|
||||
hack.registerPlatformPlugin(<Runtime>[
|
||||
SupportedBrowsers.instance.supportedBrowsersToRuntimes[browser]
|
||||
], () {
|
||||
@ -801,6 +826,7 @@ class TestCommand extends Command<bool> with ArgUtils {
|
||||
if (expectFailure) {
|
||||
if (io.exitCode != 0) {
|
||||
// It failed, as expected.
|
||||
print('Test successfully failed, as expected.');
|
||||
io.exitCode = 0;
|
||||
} else {
|
||||
io.stderr.writeln(
|
||||
@ -850,3 +876,23 @@ class TestBuildInput {
|
||||
}
|
||||
|
||||
class TestFailureException implements Exception {}
|
||||
|
||||
/// Prints the name of the test, but suppresses all other test output.
|
||||
///
|
||||
/// This is useful to prevent pollution of logs by tests that are expected to
|
||||
/// fail.
|
||||
class NameOnlyReporter implements hack.Reporter {
|
||||
NameOnlyReporter(hack.Engine testEngine) {
|
||||
testEngine.onTestStarted.listen(_printTestName);
|
||||
}
|
||||
|
||||
void _printTestName(hack.LiveTest test) {
|
||||
print('Running ${test.groups.map((hack.Group group) => group.name).join(' ')} ${test.individualName}');
|
||||
}
|
||||
|
||||
@override
|
||||
void pause() {}
|
||||
|
||||
@override
|
||||
void resume() {}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user