| Index: test/chain/vm_test.dart
|
| diff --git a/test/chain_test.dart b/test/chain/vm_test.dart
|
| similarity index 58%
|
| rename from test/chain_test.dart
|
| rename to test/chain/vm_test.dart
|
| index 65d6790f9f9d39e5ef7c4c3b68ea43b2e202c2c4..70635b7540f0be7b3053e8a4163a4e5c148ae7dc 100644
|
| --- a/test/chain_test.dart
|
| +++ b/test/chain/vm_test.dart
|
| @@ -1,16 +1,17 @@
|
| -// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -// dart2js currently doesn't support chain-capturing. See sdk#15171.
|
| -@TestOn('vm')
|
| +// VM chain tests can rely on stronger guarantees about the contents of the
|
| +// stack traces than dart2js.
|
| +@TestOn('dart-vm')
|
|
|
| import 'dart:async';
|
|
|
| -import 'package:path/path.dart' as p;
|
| import 'package:stack_trace/stack_trace.dart';
|
| import 'package:test/test.dart';
|
|
|
| +import '../utils.dart';
|
| import 'utils.dart';
|
|
|
| void main() {
|
| @@ -477,356 +478,4 @@ void main() {
|
| expect(chain.traces.first.toString(),
|
| equals(new Trace.from(trace).toString()));
|
| });
|
| -
|
| - group('Chain.parse()', () {
|
| - test('parses a real Chain', () {
|
| - return captureFuture(() => inMicrotask(() => throw 'error'))
|
| - .then((chain) {
|
| - expect(new Chain.parse(chain.toString()).toString(),
|
| - equals(chain.toString()));
|
| - });
|
| - });
|
| -
|
| - test('parses an empty string', () {
|
| - var chain = new Chain.parse('');
|
| - expect(chain.traces, isEmpty);
|
| - });
|
| -
|
| - test('parses a chain containing empty traces', () {
|
| - var chain = new Chain.parse(
|
| - '===== asynchronous gap ===========================\n'
|
| - '===== asynchronous gap ===========================\n');
|
| - expect(chain.traces, hasLength(3));
|
| - expect(chain.traces[0].frames, isEmpty);
|
| - expect(chain.traces[1].frames, isEmpty);
|
| - expect(chain.traces[2].frames, isEmpty);
|
| - });
|
| - });
|
| -
|
| - test("toString() ensures that all traces are aligned", () {
|
| - var chain = new Chain([
|
| - new Trace.parse('short 10:11 Foo.bar\n'),
|
| - new Trace.parse('loooooooooooong 10:11 Zop.zoop')
|
| - ]);
|
| -
|
| - expect(chain.toString(), equals(
|
| - 'short 10:11 Foo.bar\n'
|
| - '===== asynchronous gap ===========================\n'
|
| - 'loooooooooooong 10:11 Zop.zoop\n'));
|
| - });
|
| -
|
| - var userSlashCode = p.join('user', 'code.dart');
|
| - group('Chain.terse', () {
|
| - test('makes each trace terse', () {
|
| - var chain = new Chain([
|
| - new Trace.parse(
|
| - 'dart:core 10:11 Foo.bar\n'
|
| - 'dart:core 10:11 Bar.baz\n'
|
| - 'user/code.dart 10:11 Bang.qux\n'
|
| - 'dart:core 10:11 Zip.zap\n'
|
| - 'dart:core 10:11 Zop.zoop'),
|
| - new Trace.parse(
|
| - 'user/code.dart 10:11 Bang.qux\n'
|
| - 'dart:core 10:11 Foo.bar\n'
|
| - 'package:stack_trace/stack_trace.dart 10:11 Bar.baz\n'
|
| - 'dart:core 10:11 Zip.zap\n'
|
| - 'user/code.dart 10:11 Zop.zoop')
|
| - ]);
|
| -
|
| - expect(chain.terse.toString(), equals(
|
| - 'dart:core Bar.baz\n'
|
| - '$userSlashCode 10:11 Bang.qux\n'
|
| - '===== asynchronous gap ===========================\n'
|
| - '$userSlashCode 10:11 Bang.qux\n'
|
| - 'dart:core Zip.zap\n'
|
| - '$userSlashCode 10:11 Zop.zoop\n'));
|
| - });
|
| -
|
| - test('eliminates internal-only traces', () {
|
| - var chain = new Chain([
|
| - new Trace.parse(
|
| - 'user/code.dart 10:11 Foo.bar\n'
|
| - 'dart:core 10:11 Bar.baz'),
|
| - new Trace.parse(
|
| - 'dart:core 10:11 Foo.bar\n'
|
| - 'package:stack_trace/stack_trace.dart 10:11 Bar.baz\n'
|
| - 'dart:core 10:11 Zip.zap'),
|
| - new Trace.parse(
|
| - 'user/code.dart 10:11 Foo.bar\n'
|
| - 'dart:core 10:11 Bar.baz')
|
| - ]);
|
| -
|
| - expect(chain.terse.toString(), equals(
|
| - '$userSlashCode 10:11 Foo.bar\n'
|
| - '===== asynchronous gap ===========================\n'
|
| - '$userSlashCode 10:11 Foo.bar\n'));
|
| - });
|
| -
|
| - test("doesn't return an empty chain", () {
|
| - var chain = new Chain([
|
| - new Trace.parse(
|
| - 'dart:core 10:11 Foo.bar\n'
|
| - 'package:stack_trace/stack_trace.dart 10:11 Bar.baz\n'
|
| - 'dart:core 10:11 Zip.zap'),
|
| - new Trace.parse(
|
| - 'dart:core 10:11 A.b\n'
|
| - 'package:stack_trace/stack_trace.dart 10:11 C.d\n'
|
| - 'dart:core 10:11 E.f')
|
| - ]);
|
| -
|
| - expect(chain.terse.toString(), equals('dart:core E.f\n'));
|
| - });
|
| - });
|
| -
|
| - group('Chain.foldFrames', () {
|
| - test('folds each trace', () {
|
| - var chain = new Chain([
|
| - new Trace.parse(
|
| - 'a.dart 10:11 Foo.bar\n'
|
| - 'a.dart 10:11 Bar.baz\n'
|
| - 'b.dart 10:11 Bang.qux\n'
|
| - 'a.dart 10:11 Zip.zap\n'
|
| - 'a.dart 10:11 Zop.zoop'),
|
| - new Trace.parse(
|
| - 'a.dart 10:11 Foo.bar\n'
|
| - 'a.dart 10:11 Bar.baz\n'
|
| - 'a.dart 10:11 Bang.qux\n'
|
| - 'a.dart 10:11 Zip.zap\n'
|
| - 'b.dart 10:11 Zop.zoop')
|
| - ]);
|
| -
|
| - var folded = chain.foldFrames((frame) => frame.library == 'a.dart');
|
| - expect(folded.toString(), equals(
|
| - 'a.dart 10:11 Bar.baz\n'
|
| - 'b.dart 10:11 Bang.qux\n'
|
| - 'a.dart 10:11 Zop.zoop\n'
|
| - '===== asynchronous gap ===========================\n'
|
| - 'a.dart 10:11 Zip.zap\n'
|
| - 'b.dart 10:11 Zop.zoop\n'));
|
| - });
|
| -
|
| - test('with terse: true, folds core frames as well', () {
|
| - var chain = new Chain([
|
| - new Trace.parse(
|
| - 'a.dart 10:11 Foo.bar\n'
|
| - 'dart:async-patch/future.dart 10:11 Zip.zap\n'
|
| - 'b.dart 10:11 Bang.qux\n'
|
| - 'dart:core 10:11 Bar.baz\n'
|
| - 'a.dart 10:11 Zop.zoop'),
|
| - new Trace.parse(
|
| - 'a.dart 10:11 Foo.bar\n'
|
| - 'a.dart 10:11 Bar.baz\n'
|
| - 'a.dart 10:11 Bang.qux\n'
|
| - 'a.dart 10:11 Zip.zap\n'
|
| - 'b.dart 10:11 Zop.zoop')
|
| - ]);
|
| -
|
| - var folded = chain.foldFrames((frame) => frame.library == 'a.dart',
|
| - terse: true);
|
| - expect(folded.toString(), equals(
|
| - 'dart:async Zip.zap\n'
|
| - 'b.dart 10:11 Bang.qux\n'
|
| - 'a.dart Zop.zoop\n'
|
| - '===== asynchronous gap ===========================\n'
|
| - 'a.dart Zip.zap\n'
|
| - 'b.dart 10:11 Zop.zoop\n'));
|
| - });
|
| -
|
| - test('eliminates completely-folded traces', () {
|
| - var chain = new Chain([
|
| - new Trace.parse(
|
| - 'a.dart 10:11 Foo.bar\n'
|
| - 'b.dart 10:11 Bang.qux'),
|
| - new Trace.parse(
|
| - 'a.dart 10:11 Foo.bar\n'
|
| - 'a.dart 10:11 Bang.qux'),
|
| - new Trace.parse(
|
| - 'a.dart 10:11 Zip.zap\n'
|
| - 'b.dart 10:11 Zop.zoop')
|
| - ]);
|
| -
|
| - var folded = chain.foldFrames((frame) => frame.library == 'a.dart');
|
| - expect(folded.toString(), equals(
|
| - 'a.dart 10:11 Foo.bar\n'
|
| - 'b.dart 10:11 Bang.qux\n'
|
| - '===== asynchronous gap ===========================\n'
|
| - 'a.dart 10:11 Zip.zap\n'
|
| - 'b.dart 10:11 Zop.zoop\n'));
|
| - });
|
| -
|
| - test("doesn't return an empty trace", () {
|
| - var chain = new Chain([
|
| - new Trace.parse(
|
| - 'a.dart 10:11 Foo.bar\n'
|
| - 'a.dart 10:11 Bang.qux')
|
| - ]);
|
| -
|
| - var folded = chain.foldFrames((frame) => frame.library == 'a.dart');
|
| - expect(folded.toString(), equals('a.dart 10:11 Bang.qux\n'));
|
| - });
|
| - });
|
| -
|
| - test('Chain.toTrace eliminates asynchronous gaps', () {
|
| - var trace = new Chain([
|
| - new Trace.parse(
|
| - 'user/code.dart 10:11 Foo.bar\n'
|
| - 'dart:core 10:11 Bar.baz'),
|
| - new Trace.parse(
|
| - 'user/code.dart 10:11 Foo.bar\n'
|
| - 'dart:core 10:11 Bar.baz')
|
| - ]).toTrace();
|
| -
|
| - expect(trace.toString(), equals(
|
| - '$userSlashCode 10:11 Foo.bar\n'
|
| - 'dart:core 10:11 Bar.baz\n'
|
| - '$userSlashCode 10:11 Foo.bar\n'
|
| - 'dart:core 10:11 Bar.baz\n'));
|
| - });
|
| -
|
| - group('Chain.track(Future)', () {
|
| - test('forwards the future value within Chain.capture()', () {
|
| - Chain.capture(() {
|
| - expect(Chain.track(new Future.value('value')),
|
| - completion(equals('value')));
|
| -
|
| - var trace = new Trace.current();
|
| - expect(Chain.track(new Future.error('error', trace))
|
| - .catchError((e, stackTrace) {
|
| - expect(e, equals('error'));
|
| - expect(stackTrace.toString(), equals(trace.toString()));
|
| - }), completes);
|
| - });
|
| - });
|
| -
|
| - test('forwards the future value outside of Chain.capture()', () {
|
| - expect(Chain.track(new Future.value('value')),
|
| - completion(equals('value')));
|
| -
|
| - var trace = new Trace.current();
|
| - expect(Chain.track(new Future.error('error', trace))
|
| - .catchError((e, stackTrace) {
|
| - expect(e, equals('error'));
|
| - expect(stackTrace.toString(), equals(trace.toString()));
|
| - }), completes);
|
| - });
|
| - });
|
| -
|
| - group('Chain.track(Stream)', () {
|
| - test('forwards stream values within Chain.capture()', () {
|
| - Chain.capture(() {
|
| - var controller = new StreamController()
|
| - ..add(1)..add(2)..add(3)..close();
|
| - expect(Chain.track(controller.stream).toList(),
|
| - completion(equals([1, 2, 3])));
|
| -
|
| - var trace = new Trace.current();
|
| - controller = new StreamController()..addError('error', trace);
|
| - expect(Chain.track(controller.stream).toList()
|
| - .catchError((e, stackTrace) {
|
| - expect(e, equals('error'));
|
| - expect(stackTrace.toString(), equals(trace.toString()));
|
| - }), completes);
|
| - });
|
| - });
|
| -
|
| - test('forwards stream values outside of Chain.capture()', () {
|
| - Chain.capture(() {
|
| - var controller = new StreamController()
|
| - ..add(1)..add(2)..add(3)..close();
|
| - expect(Chain.track(controller.stream).toList(),
|
| - completion(equals([1, 2, 3])));
|
| -
|
| - var trace = new Trace.current();
|
| - controller = new StreamController()..addError('error', trace);
|
| - expect(Chain.track(controller.stream).toList()
|
| - .catchError((e, stackTrace) {
|
| - expect(e, equals('error'));
|
| - expect(stackTrace.toString(), equals(trace.toString()));
|
| - }), completes);
|
| - });
|
| - });
|
| - });
|
| -}
|
| -
|
| -/// Runs [callback] in a microtask callback.
|
| -void inMicrotask(callback()) => scheduleMicrotask(callback);
|
| -
|
| -/// Runs [callback] in a one-shot timer callback.
|
| -void inOneShotTimer(callback()) => Timer.run(callback);
|
| -
|
| -/// Runs [callback] once in a periodic timer callback.
|
| -void inPeriodicTimer(callback()) {
|
| - var count = 0;
|
| - new Timer.periodic(new Duration(milliseconds: 1), (timer) {
|
| - count++;
|
| - if (count != 5) return;
|
| - timer.cancel();
|
| - callback();
|
| - });
|
| -}
|
| -
|
| -/// Runs [callback] within a long asynchronous Future chain.
|
| -void inFutureChain(callback()) {
|
| - new Future(() {})
|
| - .then((_) => new Future(() {}))
|
| - .then((_) => new Future(() {}))
|
| - .then((_) => new Future(() {}))
|
| - .then((_) => new Future(() {}))
|
| - .then((_) => callback())
|
| - .then((_) => new Future(() {}));
|
| -}
|
| -
|
| -void inNewFuture(callback()) {
|
| - new Future(callback);
|
| -}
|
| -
|
| -void inSyncFuture(callback()) {
|
| - new Future.sync(callback);
|
| -}
|
| -
|
| -/// Returns a Future that completes to an error using a completer.
|
| -///
|
| -/// If [trace] is passed, it's used as the stack trace for the error.
|
| -Future completerErrorFuture([StackTrace trace]) {
|
| - var completer = new Completer();
|
| - completer.completeError('error', trace);
|
| - return completer.future;
|
| -}
|
| -
|
| -/// Returns a Stream that emits an error using a controller.
|
| -///
|
| -/// If [trace] is passed, it's used as the stack trace for the error.
|
| -Stream controllerErrorStream([StackTrace trace]) {
|
| - var controller = new StreamController();
|
| - controller.addError('error', trace);
|
| - return controller.stream;
|
| -}
|
| -
|
| -/// Runs [callback] within [asyncFn], then converts any errors raised into a
|
| -/// [Chain] with [Chain.forTrace].
|
| -Future<Chain> chainForTrace(asyncFn(callback()), callback()) {
|
| - var completer = new Completer();
|
| - asyncFn(() {
|
| - // We use `new Future.value().then(...)` here as opposed to [new Future] or
|
| - // [new Future.sync] because those methods don't pass the exception through
|
| - // the zone specification before propagating it, so there's no chance to
|
| - // attach a chain to its stack trace. See issue 15105.
|
| - new Future.value().then((_) => callback())
|
| - .catchError(completer.completeError);
|
| - });
|
| - return completer.future
|
| - .catchError((_, stackTrace) => new Chain.forTrace(stackTrace));
|
| -}
|
| -
|
| -/// Runs [callback] in a [Chain.capture] zone and returns a Future that
|
| -/// completes to the stack chain for an error thrown by [callback].
|
| -///
|
| -/// [callback] is expected to throw the string `"error"`.
|
| -Future<Chain> captureFuture(callback()) {
|
| - var completer = new Completer<Chain>();
|
| - Chain.capture(callback, onError: (error, chain) {
|
| - expect(error, equals('error'));
|
| - completer.complete(chain);
|
| - });
|
| - return completer.future;
|
| }
|
|
|