Index: pkg/scheduled_test/lib/src/task.dart |
diff --git a/pkg/scheduled_test/lib/src/task.dart b/pkg/scheduled_test/lib/src/task.dart |
index 4ccb201f5fbe85af5f5f3ac19a7fe26021075cea..aabdbbaea7e830a5b8bc0894bba81b464e6da5f2 100644 |
--- a/pkg/scheduled_test/lib/src/task.dart |
+++ b/pkg/scheduled_test/lib/src/task.dart |
@@ -9,6 +9,7 @@ import 'dart:collection'; |
import 'package:stack_trace/stack_trace.dart'; |
+import '../scheduled_test.dart' show currentSchedule; |
import 'future_group.dart'; |
import 'schedule.dart'; |
import 'utils.dart'; |
@@ -61,7 +62,7 @@ class Task { |
Future get result => _resultCompleter.future; |
final _resultCompleter = new Completer(); |
- final stackTrace = new Trace.current(); |
+ final Trace stackTrace; |
Task(fn(), String description, TaskQueue queue) |
: this._(fn, description, queue, null, queue.contents.length); |
@@ -69,7 +70,9 @@ class Task { |
Task._child(fn(), String description, Task parent) |
: this._(fn, description, parent.queue, parent, parent.children.length); |
- Task._(fn(), this.description, this.queue, this.parent, this._id) { |
+ Task._(fn(), this.description, TaskQueue queue, this.parent, this._id) |
+ : queue = queue, |
+ stackTrace = queue.captureStackTraces ? new Trace.current() : null { |
this.fn = () { |
if (state != TaskState.WAITING) { |
throw new StateError("Can't run $state task '$this'."); |
@@ -121,8 +124,12 @@ class Task { |
String toString() => description == null ? "#$_id" : description; |
String toStringWithStackTrace() { |
- var stackString = prefixLines(terseTraceString(stackTrace)); |
- return "$this\n\nStack trace:\n$stackString"; |
+ var result = toString(); |
+ if (stackTrace != null) { |
+ var stackString = prefixLines(terseTraceString(stackTrace)); |
+ result += "\n\nStack trace:\n$stackString"; |
+ } |
+ return result; |
} |
/// Returns a detailed representation of [queue] with this task highlighted. |