Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a silent reporter #2093

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/test/test/runner/compiler_runtime_matrix_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void main() {
if (runtime.isDartVM) {
test('forwards stdout/stderr', () async {
await d.file('test.dart', _testWithStdOutAndErr).create();
var test = await runTest(testArgs);
var test = await runTest(testArgs, reporter: 'silent');

expect(test.stdout, emitsThrough('hello'));
expect(test.stderr, emits('world'));
Expand Down
10 changes: 5 additions & 5 deletions pkgs/test_core/lib/src/runner/configuration/args.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ final ArgParser _parser = (() {
parser.addFlag('fail-fast',
help: 'Stop running tests after the first failure.\n');

var reporterDescriptions = <String, String>{};
for (var reporter in allReporters.keys) {
reporterDescriptions[reporter] = allReporters[reporter]!.description;
}
var reporterDescriptions = <String, String>{
for (final MapEntry(:key, :value) in allReporters.entries)
if (!value.hidden) key: value.description
};

parser.addSeparator('Output:');
parser.addOption('reporter',
abbr: 'r',
help: 'Set how to print test results.',
defaultsTo: defaultReporter,
allowed: reporterDescriptions.keys.toList(),
allowed: allReporters.keys,
allowedHelp: reporterDescriptions,
valueHelp: 'option');
parser.addOption('file-reporter',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ typedef ReporterFactory = Reporter Function(Configuration, Engine, StringSink);
class ReporterDetails {
final String description;
final ReporterFactory factory;
ReporterDetails(this.description, this.factory);
final bool hidden;
ReporterDetails(this.description, this.factory, {this.hidden = false});
}

/// All reporters and their corresponding details.
Expand Down Expand Up @@ -58,6 +59,10 @@ final _allReporters = <String, ReporterDetails>{
'https://dart.dev/go/test-docs/json_reporter.md).',
(config, engine, sink) =>
JsonReporter.watch(engine, sink, isDebugRun: config.debug)),
'silent': ReporterDetails(
hidden: true,
'A reporter with no output.',
(config, engine, sink) => SilentReporter()),
};

final defaultReporter = inTestTests
Expand Down
9 changes: 9 additions & 0 deletions pkgs/test_core/lib/src/runner/reporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ abstract class Reporter {
/// paused.
void resume();
}

/// A reporter that prints nothing.
class SilentReporter implements Reporter {
@override
void pause() {}

@override
void resume() {}
}
Loading