Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkgs/test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 20 additions & 3 deletions pkgs/test/test/runner/compact_reporter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.<fn>
+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<void> _expectReport(String tests, String expected,
{List<String> args = const []}) async {
{List<String> args = const [], bool chainStackTraces = true}) async {
await d.file('test.dart', '''
import 'dart:async';

Expand All @@ -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();
Expand Down
23 changes: 21 additions & 2 deletions pkgs/test/test/runner/expanded_reporter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.<fn>

+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<void> _expectReport(String tests, String expected,
{List<String> args = const []}) async {
{List<String> args = const [], bool chainStackTraces = true}) async {
await d.file('test.dart', '''
import 'dart:async';

Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions pkgs/test_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 0 additions & 7 deletions pkgs/test_api/lib/src/backend/invoker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test_api/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
19 changes: 0 additions & 19 deletions pkgs/test_api/test/backend/invoker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
17 changes: 17 additions & 0 deletions pkgs/test_core/lib/src/runner/reporter/compact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <StreamSubscription>{};

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions pkgs/test_core/lib/src/runner/reporter/expanded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <StreamSubscription>{};

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkgs/test_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down