diff --git a/pkgs/test/CHANGELOG.md b/pkgs/test/CHANGELOG.md index e913f18ac..8c4465e1a 100644 --- a/pkgs/test/CHANGELOG.md +++ b/pkgs/test/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.19.3 + +* Remove duplicate logging of suggestion to enable the `chain-stack-traces` + flag, a single log will now appear at the end. + ## 1.19.2 * Republish with missing JS file for browser tests. diff --git a/pkgs/test/pubspec.yaml b/pkgs/test/pubspec.yaml index c5db5dbd3..e70e82b5c 100644 --- a/pkgs/test/pubspec.yaml +++ b/pkgs/test/pubspec.yaml @@ -1,5 +1,5 @@ name: test -version: 1.19.2 +version: 1.19.3 description: >- A full featured library for writing and running Dart tests across platforms. repository: https://github.com/dart-lang/test/blob/master/pkgs/test @@ -32,7 +32,7 @@ dependencies: webkit_inspection_protocol: ^1.0.0 yaml: ^3.0.0 # Use an exact version until the test_api and test_core package are stable. - test_api: 0.4.6 + test_api: 0.4.7 test_core: 0.4.8 dev_dependencies: diff --git a/pkgs/test/test/runner/compact_reporter_test.dart b/pkgs/test/test/runner/compact_reporter_test.dart index 92b5c67cd..f5c0ffdab 100644 --- a/pkgs/test/test/runner/compact_reporter_test.dart +++ b/pkgs/test/test/runner/compact_reporter_test.dart @@ -413,10 +413,24 @@ void main() { +2: All tests passed!''', args: ['--run-skipped']); }); }); + + test('Directs users to enable stack trace chaining if disabled', () async { + await _expectReport( + '''test('failure 1', () => throw TestFailure('oh no'));''', ''' + +0: loading test.dart + +0: failure 1 + +0 -1: failure 1 [E] + oh no + test.dart 6:25 main. + +0 -1: Some tests failed. + Consider enabling the flag chain-stack-traces to receive more detailed exceptions. + For example, 'dart test --chain-stack-traces'.''', + chainStackTraces: false); + }); } Future _expectReport(String tests, String expected, - {List args = const []}) async { + {List args = const [], bool chainStackTraces = true}) async { await d.file('test.dart', ''' import 'dart:async'; @@ -427,8 +441,11 @@ $tests } ''').create(); - var test = await runTest(['test.dart', '--chain-stack-traces', ...args], - reporter: 'compact'); + var test = await runTest([ + 'test.dart', + if (chainStackTraces) '--chain-stack-traces', + ...args, + ], reporter: 'compact'); await test.shouldExit(); var stdoutLines = await test.stdout.rest.toList(); diff --git a/pkgs/test/test/runner/expanded_reporter_test.dart b/pkgs/test/test/runner/expanded_reporter_test.dart index b14b676ec..b137d553e 100644 --- a/pkgs/test/test/runner/expanded_reporter_test.dart +++ b/pkgs/test/test/runner/expanded_reporter_test.dart @@ -316,10 +316,25 @@ void main() { +2: All tests passed!''', args: ['--run-skipped']); }); }); + + test('Directs users to enable stack trace chaining if disabled', () async { + await _expectReport( + '''test('failure 1', () => throw TestFailure('oh no'));''', ''' + +0: failure 1 + +0 -1: failure 1 [E] + oh no + test.dart 6:25 main. + + +0 -1: Some tests failed. + + Consider enabling the flag chain-stack-traces to receive more detailed exceptions. + For example, 'dart test --chain-stack-traces'.''', + chainStackTraces: false); + }); } Future _expectReport(String tests, String expected, - {List args = const []}) async { + {List args = const [], bool chainStackTraces = true}) async { await d.file('test.dart', ''' import 'dart:async'; @@ -330,7 +345,11 @@ $tests } ''').create(); - var test = await runTest(['test.dart', '--chain-stack-traces', ...args]); + var test = await runTest([ + 'test.dart', + if (chainStackTraces) '--chain-stack-traces', + ...args, + ]); await test.shouldExit(); var stdoutLines = await test.stdoutStream().toList(); diff --git a/pkgs/test_api/CHANGELOG.md b/pkgs/test_api/CHANGELOG.md index 5e901298d..7933b6a39 100644 --- a/pkgs/test_api/CHANGELOG.md +++ b/pkgs/test_api/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.7 + +* Remove logging about enabling the chain-stack-traces flag from the invoker. + ## 0.4.6 * Give a better exception when using `markTestSkipped` outside of a test. diff --git a/pkgs/test_api/lib/src/backend/invoker.dart b/pkgs/test_api/lib/src/backend/invoker.dart index 54e3c0323..dfc67fe85 100644 --- a/pkgs/test_api/lib/src/backend/invoker.dart +++ b/pkgs/test_api/lib/src/backend/invoker.dart @@ -348,13 +348,6 @@ class Invoker { _controller.addError(error, stackTrace!); zone.run(() => _outstandingCallbacks.complete()); - if (!liveTest.test.metadata.chainStackTraces && - !liveTest.suite.isLoadSuite) { - _printsOnFailure.add('Consider enabling the flag chain-stack-traces to ' - 'receive more detailed exceptions.\n' - "For example, 'dart test --chain-stack-traces'."); - } - if (_printsOnFailure.isNotEmpty) { print(_printsOnFailure.join('\n\n')); _printsOnFailure.clear(); diff --git a/pkgs/test_api/pubspec.yaml b/pkgs/test_api/pubspec.yaml index c12d68c08..5c916d877 100644 --- a/pkgs/test_api/pubspec.yaml +++ b/pkgs/test_api/pubspec.yaml @@ -1,5 +1,5 @@ name: test_api -version: 0.4.6 +version: 0.4.7 description: A library for writing Dart tests. homepage: https://github.com/dart-lang/test/blob/master/pkgs/test_api diff --git a/pkgs/test_api/test/backend/invoker_test.dart b/pkgs/test_api/test/backend/invoker_test.dart index 255f5c0e5..d30c25030 100644 --- a/pkgs/test_api/test/backend/invoker_test.dart +++ b/pkgs/test_api/test/backend/invoker_test.dart @@ -524,25 +524,6 @@ void main() { }); }); - group('chainStackTraces', () { - test( - 'if disabled, directs users to run with the flag enabled when ' - 'failures occur', () { - expect(() async { - var liveTest = _localTest(() { - expect(true, isFalse); - }, metadata: Metadata(chainStackTraces: false)) - .load(suite); - liveTest.onError.listen(expectAsync1((_) {}, count: 1)); - - await liveTest.run(); - }, - prints('Consider enabling the flag chain-stack-traces to ' - 'receive more detailed exceptions.\n' - "For example, 'dart test --chain-stack-traces'.\n")); - }); - }); - group('printOnFailure:', () { test("doesn't print anything if the test succeeds", () { expect(() async { diff --git a/pkgs/test_core/CHANGELOG.md b/pkgs/test_core/CHANGELOG.md index f0f7bcaeb..d8f91bbc9 100644 --- a/pkgs/test_core/CHANGELOG.md +++ b/pkgs/test_core/CHANGELOG.md @@ -1,4 +1,8 @@ -## 0.4.8-dev +## 0.4.8 + +* Add logging about enabling stack trace chaining to the compact and expanded + reporters (moved from the invoker). This will now only be logged once after + all tests have ran. ## 0.4.7 diff --git a/pkgs/test_core/lib/src/runner/reporter/compact.dart b/pkgs/test_core/lib/src/runner/reporter/compact.dart index eb3646f5e..68fd4960c 100644 --- a/pkgs/test_core/lib/src/runner/reporter/compact.dart +++ b/pkgs/test_core/lib/src/runner/reporter/compact.dart @@ -98,6 +98,10 @@ class CompactReporter implements Reporter { /// Whether the reporter is paused. var _paused = false; + // Whether a notice should be logged about enabling stack trace chaining at + // the end of all tests running. + var _shouldPrintStackTraceChainingNotice = false; + /// The set of all subscriptions to various streams. final _subscriptions = {}; @@ -231,6 +235,11 @@ class CompactReporter implements Reporter { /// A callback called when [liveTest] throws [error]. void _onError(LiveTest liveTest, error, StackTrace stackTrace) { + if (!liveTest.test.metadata.chainStackTraces && + !liveTest.suite.isLoadSuite) { + _shouldPrintStackTraceChainingNotice = true; + } + if (liveTest.state.status != Status.complete) return; _progressLine(_description(liveTest), @@ -298,6 +307,14 @@ class CompactReporter implements Reporter { _progressLine('All tests passed!'); _sink.writeln(''); } + + if (_shouldPrintStackTraceChainingNotice) { + _sink + ..writeln('') + ..writeln('Consider enabling the flag chain-stack-traces to ' + 'receive more detailed exceptions.\n' + "For example, 'dart test --chain-stack-traces'."); + } } /// Prints a line representing the current state of the tests. diff --git a/pkgs/test_core/lib/src/runner/reporter/expanded.dart b/pkgs/test_core/lib/src/runner/reporter/expanded.dart index cd6a49026..30f0f20f6 100644 --- a/pkgs/test_core/lib/src/runner/reporter/expanded.dart +++ b/pkgs/test_core/lib/src/runner/reporter/expanded.dart @@ -81,6 +81,10 @@ class ExpandedReporter implements Reporter { /// Whether the reporter is paused. var _paused = false; + // Whether a notice should be logged about enabling stack trace chaining at + // the end of all tests running. + var _shouldPrintStackTraceChainingNotice = false; + /// The set of all subscriptions to various streams. final _subscriptions = {}; @@ -197,6 +201,11 @@ class ExpandedReporter implements Reporter { /// A callback called when [liveTest] throws [error]. void _onError(LiveTest liveTest, error, StackTrace stackTrace) { + if (!liveTest.test.metadata.chainStackTraces && + !liveTest.suite.isLoadSuite) { + _shouldPrintStackTraceChainingNotice = true; + } + if (liveTest.state.status != Status.complete) return; _progressLine(_description(liveTest), suffix: ' $_bold$_red[E]$_noColor'); @@ -241,6 +250,14 @@ class ExpandedReporter implements Reporter { } else { _progressLine('All tests passed!'); } + + if (_shouldPrintStackTraceChainingNotice) { + _sink + ..writeln('') + ..writeln('Consider enabling the flag chain-stack-traces to ' + 'receive more detailed exceptions.\n' + "For example, 'dart test --chain-stack-traces'."); + } } /// Prints a line representing the current state of the tests. diff --git a/pkgs/test_core/pubspec.yaml b/pkgs/test_core/pubspec.yaml index bc544fcd4..59d3d5f4b 100644 --- a/pkgs/test_core/pubspec.yaml +++ b/pkgs/test_core/pubspec.yaml @@ -1,5 +1,5 @@ name: test_core -version: 0.4.8-dev +version: 0.4.8 description: A basic library for writing tests and running them on the VM. homepage: https://github.com/dart-lang/test/blob/master/pkgs/test_core @@ -30,7 +30,7 @@ dependencies: # matcher is tightly constrained by test_api matcher: any # Use an exact version until the test_api package is stable. - test_api: 0.4.6 + test_api: 0.4.7 dev_dependencies: lints: ^1.0.0