Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: pkg/stack_trace/test/chain_test.dart

Issue 344953002: Properly handle synchronous errors in Chain.capture. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/stack_trace/pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « pkg/stack_trace/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698