| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library chain_test; | 5 library chain_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 | 12 |
| 13 import 'utils.dart'; | 13 import 'utils.dart'; |
| 14 | 14 |
| 15 void main() { | 15 void main() { |
| 16 group('capture() with onError catches exceptions', () { | 16 group('capture() with onError catches exceptions', () { |
| 17 test('thrown synchronously', () { |
| 18 return captureFuture(() => throw 'error') |
| 19 .then((chain) { |
| 20 expect(chain.traces, hasLength(1)); |
| 21 expect(chain.traces.single.frames.first, |
| 22 frameMember(startsWith('main'))); |
| 23 }); |
| 24 }); |
| 25 |
| 17 test('thrown in a microtask', () { | 26 test('thrown in a microtask', () { |
| 18 return captureFuture(() => inMicrotask(() => throw 'error')) | 27 return captureFuture(() => inMicrotask(() => throw 'error')) |
| 19 .then((chain) { | 28 .then((chain) { |
| 20 // Since there was only one asynchronous operation, there should be only | 29 // Since there was only one asynchronous operation, there should be only |
| 21 // two traces in the chain. | 30 // two traces in the chain. |
| 22 expect(chain.traces, hasLength(2)); | 31 expect(chain.traces, hasLength(2)); |
| 23 | 32 |
| 24 // The first frame of the first trace should be the line on which the | 33 // The first frame of the first trace should be the line on which the |
| 25 // actual error was thrown. | 34 // actual error was thrown. |
| 26 expect(chain.traces[0].frames.first, frameMember(startsWith('main'))); | 35 expect(chain.traces[0].frames.first, frameMember(startsWith('main'))); |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 /// | 731 /// |
| 723 /// [callback] is expected to throw the string `"error"`. | 732 /// [callback] is expected to throw the string `"error"`. |
| 724 Future<Chain> captureFuture(callback()) { | 733 Future<Chain> captureFuture(callback()) { |
| 725 var completer = new Completer<Chain>(); | 734 var completer = new Completer<Chain>(); |
| 726 Chain.capture(callback, onError: (error, chain) { | 735 Chain.capture(callback, onError: (error, chain) { |
| 727 expect(error, equals('error')); | 736 expect(error, equals('error')); |
| 728 completer.complete(chain); | 737 completer.complete(chain); |
| 729 }); | 738 }); |
| 730 return completer.future; | 739 return completer.future; |
| 731 } | 740 } |
| OLD | NEW |