OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 // VMOptions=--error_on_bad_type --error_on_bad_override --verbose_debug | 4 // VMOptions=--error_on_bad_type --error_on_bad_override --verbose_debug |
5 | 5 |
6 import 'dart:developer'; | 6 import 'dart:developer'; |
7 import 'package:observatory/models.dart' as M; | 7 import 'package:observatory/models.dart' as M; |
8 import 'package:observatory/service_io.dart'; | 8 import 'package:observatory/service_io.dart'; |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 import 'service_test_common.dart'; | 10 import 'service_test_common.dart'; |
11 import 'test_helper.dart'; | 11 import 'test_helper.dart'; |
12 | 12 |
13 const LINE_A = 26; | 13 const LINE_A = 26; |
14 const LINE_B = 19; | 14 const LINE_B = 19; |
15 const LINE_C = 21; | 15 const LINE_C = 21; |
16 | 16 |
17 foobar() async* { | 17 foobar() async* { |
18 debugger(); | 18 debugger(); |
19 yield 1; // LINE_B. | 19 yield 1; // LINE_B. |
20 debugger(); | 20 debugger(); |
21 yield 2; // LINE_C. | 21 yield 2; // LINE_C. |
22 } | 22 } |
23 | 23 |
24 helper() async { | 24 helper() async { |
25 debugger(); | 25 debugger(); |
26 print('helper'); // LINE_A. | 26 print('helper'); // LINE_A. |
27 await for (var i in foobar()) { | 27 await for (var i in foobar()) { |
28 print('helper $i'); | 28 print('helper $i'); |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 testMain() { | 32 testMain() { |
33 helper(); | 33 helper(); |
34 } | 34 } |
35 | 35 |
36 var tests = [ | 36 var tests = [ |
37 hasStoppedAtBreakpoint, | 37 hasStoppedAtBreakpoint, |
38 stoppedAtLine(LINE_A), | 38 stoppedAtLine(LINE_A), |
39 (Isolate isolate) async { | 39 (Isolate isolate) async { |
40 ServiceMap stack = await isolate.getStack(); | 40 ServiceMap stack = await isolate.getStack(); |
41 // No causal frames because we are in a completely synchronous stack. | 41 // No causal frames because we are in a completely synchronous stack. |
42 expect(stack['asyncCausalFrames'], isNotNull); | 42 expect(stack['asyncCausalFrames'], isNotNull); |
43 var asyncStack = stack['asyncCausalFrames']; | 43 var asyncStack = stack['asyncCausalFrames']; |
44 expect(asyncStack[0].toString(), contains('helper')); | 44 expect(asyncStack[0].toString(), contains('helper')); |
45 expect(asyncStack[1].kind, equals(M.FrameKind.asyncSuspensionMarker)); | 45 expect(asyncStack[1].kind, equals(M.FrameKind.asyncSuspensionMarker)); |
46 expect(asyncStack[2].toString(), contains('testMain')); | 46 expect(asyncStack[2].toString(), contains('testMain')); |
47 }, | 47 }, |
48 resumeIsolate, | 48 resumeIsolate, |
49 hasStoppedAtBreakpoint, | 49 hasStoppedAtBreakpoint, |
50 stoppedAtLine(LINE_B), | 50 stoppedAtLine(LINE_B), |
| 51 |
51 (Isolate isolate) async { | 52 (Isolate isolate) async { |
52 ServiceMap stack = await isolate.getStack(); | 53 ServiceMap stack = await isolate.getStack(); |
53 // Has causal frames (we are inside an async function) | 54 // Has causal frames (we are inside an async function) |
54 expect(stack['asyncCausalFrames'], isNotNull); | 55 expect(stack['asyncCausalFrames'], isNotNull); |
55 var asyncStack = stack['asyncCausalFrames']; | 56 var asyncStack = stack['asyncCausalFrames']; |
56 expect(asyncStack[0].toString(), contains('foobar')); | 57 expect(asyncStack[0].toString(), contains('foobar')); |
57 expect(asyncStack[1].kind, equals(M.FrameKind.asyncSuspensionMarker)); | 58 expect(asyncStack[1].kind, equals(M.FrameKind.asyncSuspensionMarker)); |
58 expect(asyncStack[2].toString(), contains('helper')); | 59 expect(asyncStack[2].toString(), contains('helper')); |
59 expect(asyncStack[3].kind, equals(M.FrameKind.asyncSuspensionMarker)); | 60 expect(asyncStack[3].kind, equals(M.FrameKind.asyncSuspensionMarker)); |
60 expect(asyncStack[4].toString(), contains('testMain')); | 61 expect(asyncStack[4].toString(), contains('testMain')); |
61 }, | 62 }, |
| 63 |
62 resumeIsolate, | 64 resumeIsolate, |
63 hasStoppedAtBreakpoint, | 65 hasStoppedAtBreakpoint, |
64 stoppedAtLine(LINE_C), | 66 stoppedAtLine(LINE_C), |
| 67 |
65 (Isolate isolate) async { | 68 (Isolate isolate) async { |
66 ServiceMap stack = await isolate.getStack(); | 69 ServiceMap stack = await isolate.getStack(); |
67 // Has causal frames (we are inside a function called by an async function) | 70 // Has causal frames (we are inside a function called by an async function) |
68 expect(stack['asyncCausalFrames'], isNotNull); | 71 expect(stack['asyncCausalFrames'], isNotNull); |
69 var asyncStack = stack['asyncCausalFrames']; | 72 var asyncStack = stack['asyncCausalFrames']; |
70 print('async:'); | 73 print('async:'); |
71 await printFrames(asyncStack); | 74 await printFrames(asyncStack); |
72 print('sync:'); | 75 print('sync:'); |
73 await printFrames(stack['frames']); | 76 await printFrames(stack['frames']); |
74 expect(asyncStack[0].toString(), contains('foobar')); | 77 expect(asyncStack[0].toString(), contains('foobar')); |
75 expect(asyncStack[1].kind, equals(M.FrameKind.asyncSuspensionMarker)); | 78 expect(asyncStack[1].kind, equals(M.FrameKind.asyncSuspensionMarker)); |
76 expect(asyncStack[2].toString(), contains('helper')); | 79 expect(asyncStack[2].toString(), contains('helper')); |
77 expect(asyncStack[3].kind, equals(M.FrameKind.asyncSuspensionMarker)); | 80 expect(asyncStack[3].kind, equals(M.FrameKind.asyncSuspensionMarker)); |
78 expect(asyncStack[4].toString(), contains('testMain')); | 81 expect(asyncStack[4].toString(), contains('testMain')); |
79 // Line 21. | 82 // Line 21. |
80 expect(await asyncStack[0].location.toUserString(), contains('.dart:21')); | 83 expect(await asyncStack[0].location.toUserString(), contains('.dart:21')); |
81 // Line 27. | 84 // Line 27. |
82 expect(await asyncStack[2].location.toUserString(), contains('.dart:27')); | 85 expect(await asyncStack[2].location.toUserString(), contains('.dart:27')); |
83 // Line 30. | 86 // Line 30. |
84 expect(await asyncStack[4].location.toUserString(), contains('.dart:33')); | 87 expect(await asyncStack[4].location.toUserString(), contains('.dart:33')); |
85 }, | 88 }, |
86 ]; | 89 ]; |
87 | 90 |
88 main(args) => | 91 main(args) => runIsolateTestsSynchronous(args, |
89 runIsolateTestsSynchronous(args, tests, testeeConcurrent: testMain); | 92 tests, |
| 93 testeeConcurrent: testMain); |
OLD | NEW |