Skip to content

Commit 6e2d1c3

Browse files
committed
Hide skip reasons in compact and failure reporters
Closes #2546, Fixes #2542 Skipped tests with messages can cause noisy output in otherwise very short test run logs. In most cases the skip messages are not useful, so suppress them by default. They can still be seen in the expanded reporter. Expand the final output when there are skipped tests since the otherwise obvious yellow lines are no longer shown. Add support for testing against disallowed output in the compact reporter tests. Existing tests ignore unexpected output that comes between any expected lines.
1 parent 30aa541 commit 6e2d1c3

File tree

6 files changed

+52
-23
lines changed

6 files changed

+52
-23
lines changed

pkgs/test/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
packages using RegExps.
55
* Require a function definition named `main` directly in a test suite and
66
provide a more direct error message than a failing compiler output.
7+
* Suppress skip reason messages in the compact and failures-only reporters.
78

89
## 1.28.0
910

pkgs/test/test/runner/compact_reporter_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ void main() {
392392
+1 ~2: skip 2
393393
+1 ~2: success 2
394394
+2 ~2: success 2
395-
+2 ~2: All tests passed!''',
395+
+2 ~2: 2 skipped tests.
396+
+2 ~2: All other tests passed!''',
396397
);
397398
});
398399

@@ -431,22 +432,17 @@ void main() {
431432
);
432433
});
433434

434-
test('displays the skip reason if available', () {
435+
test('hides skip reasons', () {
435436
return _expectReport(
436437
'''
437438
test('skip 1', () {}, skip: 'some reason');
438439
test('skip 2', () {}, skip: 'or another');''',
439440
'''
440441
+0: loading test.dart
441-
+0: skip 1
442-
Skip: some reason
443-
444442
+0 ~1: skip 1
445-
+0 ~1: skip 2
446-
Skip: or another
447-
448443
+0 ~2: skip 2
449444
+0 ~2: All tests skipped.''',
445+
disallowedLines: ['some reason', 'or another'],
450446
);
451447
});
452448

@@ -573,6 +569,7 @@ Future<void> _expectReport(
573569
String expected, {
574570
List<String> args = const [],
575571
bool chainStackTraces = true,
572+
Iterable<String>? disallowedLines,
576573
}) async {
577574
await d.file('test.dart', '''
578575
import 'dart:async';
@@ -622,4 +619,7 @@ $tests
622619
});
623620

624621
expect(actual, containsAllInOrder(expectedLines));
622+
for (final disallowed in disallowedLines ?? const <String>[]) {
623+
expect(actual, everyElement(isNot(contains(disallowed))));
624+
}
625625
}

pkgs/test/test/runner/failures_only_reporter_test.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,29 @@ void main() {
196196
});
197197

198198
group('skip:', () {
199-
test('does not emit for skips', () {
199+
test('reports when all tests are skipped', () {
200200
return _expectReport(
201201
'''
202202
test('skip 1', () {}, skip: true);
203203
test('skip 2', () {}, skip: true);
204-
test('skip 3', () {}, skip: true);''',
204+
test('skip 3', () {}, skip: 'some reason');''',
205205
'''
206206
+0 ~3: All tests skipped.''',
207207
);
208208
});
209209

210+
test('reports count of skipped tests', () {
211+
return _expectReport(
212+
'''
213+
test('skip 1', () {});
214+
test('skip 2', () {}, skip: true);
215+
test('skip 3', () {}, skip: 'some reason');''',
216+
'''
217+
+1 ~2: 2 skipped tests.
218+
+1 ~2: All other tests passed!''',
219+
);
220+
});
221+
210222
test('runs skipped tests along with successful and failing tests', () {
211223
return _expectReport(
212224
'''

pkgs/test_core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
packages using RegExps.
55
* Require a function definition named `main` directly in a test suite and
66
provide a more direct error message than a failing compiler output.
7+
* Suppress skip reason messages in the compact and failures-only reporters.
78

89
## 0.6.14
910

pkgs/test_core/lib/src/runner/reporter/compact.dart

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import 'dart:io';
77
import 'dart:isolate';
88

99
import 'package:test_api/src/backend/live_test.dart'; // ignore: implementation_imports
10-
import 'package:test_api/src/backend/message.dart'; // ignore: implementation_imports
1110
import 'package:test_api/src/backend/state.dart'; // ignore: implementation_imports
11+
import 'package:test_api/src/backend/util/pretty_print.dart'; // ignore: implementation_imports
1212

1313
import '../../util/io.dart';
1414
import '../../util/pretty_print.dart';
@@ -228,13 +228,11 @@ class CompactReporter implements Reporter {
228228

229229
_subscriptions.add(
230230
liveTest.onMessage.listen((message) {
231+
if (liveTest.test.metadata.skip) return;
231232
_progressLine(_description(liveTest), truncate: false);
232233
if (!_printedNewline) _sink.writeln('');
233234
_printedNewline = true;
234-
235-
var text = message.text;
236-
if (message.type == MessageType.skip) text = ' $_yellow$text$_noColor';
237-
_sink.writeln(text);
235+
_sink.writeln(message.text);
238236
}),
239237
);
240238

@@ -345,11 +343,21 @@ class CompactReporter implements Reporter {
345343
_progressLine('Some tests failed.', color: _red);
346344
_sink.writeln('');
347345
} else if (_engine.passed.isEmpty) {
348-
_progressLine('All tests skipped.');
346+
_progressLine('${_yellow}All tests skipped.$_noColor');
349347
_sink.writeln('');
350-
} else {
348+
} else if (_engine.skipped.isEmpty) {
351349
_progressLine('All tests passed!');
352350
_sink.writeln('');
351+
} else {
352+
final skippedCount = _engine.skipped.length;
353+
_progressLine(
354+
'$_yellow'
355+
'$skippedCount skipped ${pluralize('test', skippedCount)}.'
356+
'$_noColor',
357+
);
358+
_sink.writeln('');
359+
_progressLine('All other tests passed!');
360+
_sink.writeln('');
353361
}
354362

355363
if (_shouldPrintStackTraceChainingNotice) {

pkgs/test_core/lib/src/runner/reporter/failures_only.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import 'dart:async';
66

77
import 'package:test_api/src/backend/live_test.dart'; // ignore: implementation_imports
8-
import 'package:test_api/src/backend/message.dart'; // ignore: implementation_imports
98
import 'package:test_api/src/backend/state.dart'; // ignore: implementation_imports
9+
import 'package:test_api/src/backend/util/pretty_print.dart'; // ignore: implementation_imports
1010

1111
import '../../util/pretty_print.dart';
1212
import '../engine.dart';
@@ -161,11 +161,10 @@ class FailuresOnlyReporter implements Reporter {
161161

162162
_subscriptions.add(
163163
liveTest.onMessage.listen((message) {
164+
if (liveTest.test.metadata.skip) return;
164165
// TODO - Should this suppress output? Behave like printOnFailure?
165166
_progressLine(_description(liveTest));
166-
var text = message.text;
167-
if (message.type == MessageType.skip) text = ' $_yellow$text$_noColor';
168-
_sink.writeln(text);
167+
_sink.writeln(message.text);
169168
}),
170169
);
171170
}
@@ -219,9 +218,17 @@ class FailuresOnlyReporter implements Reporter {
219218
}
220219
_progressLine('Some tests failed.', color: _red);
221220
} else if (_engine.passed.isEmpty) {
222-
_progressLine('All tests skipped.');
223-
} else {
221+
_progressLine('${_yellow}All tests skipped.$_noColor');
222+
} else if (_engine.skipped.isEmpty) {
224223
_progressLine('All tests passed!');
224+
} else {
225+
final skippedCount = _engine.skipped.length;
226+
_progressLine(
227+
'$_yellow'
228+
'$skippedCount skipped ${pluralize('test', skippedCount)}.'
229+
'$_noColor',
230+
);
231+
_progressLine('All other tests passed!');
225232
}
226233

227234
if (_shouldPrintStackTraceChainingNotice) {

0 commit comments

Comments
 (0)