From f68d1a66ccd75b0920cd9dab543207bce9989be2 Mon Sep 17 00:00:00 2001 From: Yegor Date: Tue, 1 Jun 2021 10:46:06 -0700 Subject: [PATCH] suppress output from intentionally failing tests (flutter/engine#26253) * suppress output from intentionally failing tests --- .../flutter/lib/web_ui/dev/test_runner.dart | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/engine/src/flutter/lib/web_ui/dev/test_runner.dart b/engine/src/flutter/lib/web_ui/dev/test_runner.dart index e56f400811c..5712d2a653a 100644 --- a/engine/src/flutter/lib/web_ui/dev/test_runner.dart +++ b/engine/src/flutter/lib/web_ui/dev/test_runner.dart @@ -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 with ArgUtils { ...['-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 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([ SupportedBrowsers.instance.supportedBrowsersToRuntimes[browser] ], () { @@ -801,6 +826,7 @@ class TestCommand extends Command 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() {} +}