Skip to content

Commit b46e273

Browse files
authored
move log about enabling stack trace chaining to the reporters (#1628)
Fixes #1505 Alternatively we could remove this log entirely, but this is one fairly easy solution.
1 parent c586cff commit b46e273

File tree

12 files changed

+94
-37
lines changed

12 files changed

+94
-37
lines changed

pkgs/test/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.19.3
2+
3+
* Remove duplicate logging of suggestion to enable the `chain-stack-traces`
4+
flag, a single log will now appear at the end.
5+
16
## 1.19.2
27

38
* Republish with missing JS file for browser tests.

pkgs/test/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: test
2-
version: 1.19.2
2+
version: 1.19.3
33
description: >-
44
A full featured library for writing and running Dart tests across platforms.
55
repository: https://github.com/dart-lang/test/blob/master/pkgs/test
@@ -32,7 +32,7 @@ dependencies:
3232
webkit_inspection_protocol: ^1.0.0
3333
yaml: ^3.0.0
3434
# Use an exact version until the test_api and test_core package are stable.
35-
test_api: 0.4.6
35+
test_api: 0.4.7
3636
test_core: 0.4.8
3737

3838
dev_dependencies:

pkgs/test/test/runner/compact_reporter_test.dart

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,24 @@ void main() {
413413
+2: All tests passed!''', args: ['--run-skipped']);
414414
});
415415
});
416+
417+
test('Directs users to enable stack trace chaining if disabled', () async {
418+
await _expectReport(
419+
'''test('failure 1', () => throw TestFailure('oh no'));''', '''
420+
+0: loading test.dart
421+
+0: failure 1
422+
+0 -1: failure 1 [E]
423+
oh no
424+
test.dart 6:25 main.<fn>
425+
+0 -1: Some tests failed.
426+
Consider enabling the flag chain-stack-traces to receive more detailed exceptions.
427+
For example, 'dart test --chain-stack-traces'.''',
428+
chainStackTraces: false);
429+
});
416430
}
417431

418432
Future<void> _expectReport(String tests, String expected,
419-
{List<String> args = const []}) async {
433+
{List<String> args = const [], bool chainStackTraces = true}) async {
420434
await d.file('test.dart', '''
421435
import 'dart:async';
422436
@@ -427,8 +441,11 @@ $tests
427441
}
428442
''').create();
429443

430-
var test = await runTest(['test.dart', '--chain-stack-traces', ...args],
431-
reporter: 'compact');
444+
var test = await runTest([
445+
'test.dart',
446+
if (chainStackTraces) '--chain-stack-traces',
447+
...args,
448+
], reporter: 'compact');
432449
await test.shouldExit();
433450

434451
var stdoutLines = await test.stdout.rest.toList();

pkgs/test/test/runner/expanded_reporter_test.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,25 @@ void main() {
316316
+2: All tests passed!''', args: ['--run-skipped']);
317317
});
318318
});
319+
320+
test('Directs users to enable stack trace chaining if disabled', () async {
321+
await _expectReport(
322+
'''test('failure 1', () => throw TestFailure('oh no'));''', '''
323+
+0: failure 1
324+
+0 -1: failure 1 [E]
325+
oh no
326+
test.dart 6:25 main.<fn>
327+
328+
+0 -1: Some tests failed.
329+
330+
Consider enabling the flag chain-stack-traces to receive more detailed exceptions.
331+
For example, 'dart test --chain-stack-traces'.''',
332+
chainStackTraces: false);
333+
});
319334
}
320335

321336
Future<void> _expectReport(String tests, String expected,
322-
{List<String> args = const []}) async {
337+
{List<String> args = const [], bool chainStackTraces = true}) async {
323338
await d.file('test.dart', '''
324339
import 'dart:async';
325340
@@ -330,7 +345,11 @@ $tests
330345
}
331346
''').create();
332347

333-
var test = await runTest(['test.dart', '--chain-stack-traces', ...args]);
348+
var test = await runTest([
349+
'test.dart',
350+
if (chainStackTraces) '--chain-stack-traces',
351+
...args,
352+
]);
334353
await test.shouldExit();
335354

336355
var stdoutLines = await test.stdoutStream().toList();

pkgs/test_api/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.7
2+
3+
* Remove logging about enabling the chain-stack-traces flag from the invoker.
4+
15
## 0.4.6
26

37
* Give a better exception when using `markTestSkipped` outside of a test.

pkgs/test_api/lib/src/backend/invoker.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,6 @@ class Invoker {
348348
_controller.addError(error, stackTrace!);
349349
zone.run(() => _outstandingCallbacks.complete());
350350

351-
if (!liveTest.test.metadata.chainStackTraces &&
352-
!liveTest.suite.isLoadSuite) {
353-
_printsOnFailure.add('Consider enabling the flag chain-stack-traces to '
354-
'receive more detailed exceptions.\n'
355-
"For example, 'dart test --chain-stack-traces'.");
356-
}
357-
358351
if (_printsOnFailure.isNotEmpty) {
359352
print(_printsOnFailure.join('\n\n'));
360353
_printsOnFailure.clear();

pkgs/test_api/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: test_api
2-
version: 0.4.6
2+
version: 0.4.7
33
description: A library for writing Dart tests.
44
homepage: https://github.com/dart-lang/test/blob/master/pkgs/test_api
55

pkgs/test_api/test/backend/invoker_test.dart

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -524,25 +524,6 @@ void main() {
524524
});
525525
});
526526

527-
group('chainStackTraces', () {
528-
test(
529-
'if disabled, directs users to run with the flag enabled when '
530-
'failures occur', () {
531-
expect(() async {
532-
var liveTest = _localTest(() {
533-
expect(true, isFalse);
534-
}, metadata: Metadata(chainStackTraces: false))
535-
.load(suite);
536-
liveTest.onError.listen(expectAsync1((_) {}, count: 1));
537-
538-
await liveTest.run();
539-
},
540-
prints('Consider enabling the flag chain-stack-traces to '
541-
'receive more detailed exceptions.\n'
542-
"For example, 'dart test --chain-stack-traces'.\n"));
543-
});
544-
});
545-
546527
group('printOnFailure:', () {
547528
test("doesn't print anything if the test succeeds", () {
548529
expect(() async {

pkgs/test_core/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
## 0.4.8-dev
1+
## 0.4.8
2+
3+
* Add logging about enabling stack trace chaining to the compact and expanded
4+
reporters (moved from the invoker). This will now only be logged once after
5+
all tests have ran.
26

37
## 0.4.7
48

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ class CompactReporter implements Reporter {
9898
/// Whether the reporter is paused.
9999
var _paused = false;
100100

101+
// Whether a notice should be logged about enabling stack trace chaining at
102+
// the end of all tests running.
103+
var _shouldPrintStackTraceChainingNotice = false;
104+
101105
/// The set of all subscriptions to various streams.
102106
final _subscriptions = <StreamSubscription>{};
103107

@@ -231,6 +235,11 @@ class CompactReporter implements Reporter {
231235

232236
/// A callback called when [liveTest] throws [error].
233237
void _onError(LiveTest liveTest, error, StackTrace stackTrace) {
238+
if (!liveTest.test.metadata.chainStackTraces &&
239+
!liveTest.suite.isLoadSuite) {
240+
_shouldPrintStackTraceChainingNotice = true;
241+
}
242+
234243
if (liveTest.state.status != Status.complete) return;
235244

236245
_progressLine(_description(liveTest),
@@ -298,6 +307,14 @@ class CompactReporter implements Reporter {
298307
_progressLine('All tests passed!');
299308
_sink.writeln('');
300309
}
310+
311+
if (_shouldPrintStackTraceChainingNotice) {
312+
_sink
313+
..writeln('')
314+
..writeln('Consider enabling the flag chain-stack-traces to '
315+
'receive more detailed exceptions.\n'
316+
"For example, 'dart test --chain-stack-traces'.");
317+
}
301318
}
302319

303320
/// Prints a line representing the current state of the tests.

0 commit comments

Comments
 (0)