OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 | 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
5 | 5 |
6 import 'package:observatory/service_io.dart'; | 6 import 'package:observatory/service_io.dart'; |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'service_test_common.dart'; | 8 import 'service_test_common.dart'; |
9 import 'test_helper.dart'; | 9 import 'test_helper.dart'; |
10 import 'dart:developer'; | 10 import 'dart:developer'; |
11 | 11 |
12 const int LINE_A = 24; | 12 const int LINE_A = 24; |
13 const int LINE_B = 27; | 13 const int LINE_B = 27; |
14 const int LINE_C = 30; | 14 const int LINE_C = 30; |
15 | 15 |
16 testFunction() { | 16 testFunction() { |
17 debugger(); | 17 debugger(); |
18 var a; | 18 var a; |
19 try { | 19 try { |
20 var b; | 20 var b; |
21 try { | 21 try { |
22 for (int i = 0; i < 10; i++) { | 22 for (int i = 0; i < 10; i++) { |
23 var x = () => i + a + b; | 23 var x = () => i + a + b; |
24 return x; // LINE_A | 24 return x; // LINE_A |
25 } | 25 } |
26 } finally { | 26 } finally { |
27 b = 10; // LINE_B | 27 b = 10; // LINE_B |
28 } | 28 } |
29 } finally { | 29 } finally { |
30 a = 1; // LINE_C | 30 a = 1; // LINE_C |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 testMain() { | 34 testMain() { |
35 var f = testFunction(); | 35 var f = testFunction(); |
36 expect(f(), equals(11)); | 36 expect(f(), equals(11)); |
37 } | 37 } |
38 | 38 |
39 var tests = [ | 39 var tests = [ |
40 hasStoppedAtBreakpoint, | 40 |
| 41 hasStoppedAtBreakpoint, |
41 | 42 |
42 // Add breakpoint | 43 // Add breakpoint |
43 (Isolate isolate) async { | 44 (Isolate isolate) async { |
44 await isolate.rootLibrary.load(); | 45 await isolate.rootLibrary.load(); |
45 | 46 |
46 var script = isolate.rootLibrary.scripts[0]; | 47 var script = isolate.rootLibrary.scripts[0]; |
47 await script.load(); | 48 await script.load(); |
48 | 49 |
49 // Add 3 breakpoints. | 50 // Add 3 breakpoints. |
50 { | 51 { |
51 var result = await isolate.addBreakpoint(script, LINE_A); | 52 var result = await isolate.addBreakpoint(script, LINE_A); |
52 expect(result is Breakpoint, isTrue); | 53 expect(result is Breakpoint, isTrue); |
53 Breakpoint bpt = result; | 54 Breakpoint bpt = result; |
54 expect(bpt.type, equals('Breakpoint')); | 55 expect(bpt.type, equals('Breakpoint')); |
55 expect(bpt.location.script.id, equals(script.id)); | 56 expect(bpt.location.script.id, equals(script.id)); |
56 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), | 57 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), |
57 equals(LINE_A)); | 58 equals(LINE_A)); |
58 expect(isolate.breakpoints.length, equals(1)); | 59 expect(isolate.breakpoints.length, equals(1)); |
59 } | 60 } |
60 | 61 |
61 { | 62 { |
62 var result = await isolate.addBreakpoint(script, LINE_B); | 63 var result = await isolate.addBreakpoint(script, LINE_B); |
63 expect(result is Breakpoint, isTrue); | 64 expect(result is Breakpoint, isTrue); |
64 Breakpoint bpt = result; | 65 Breakpoint bpt = result; |
65 expect(bpt.type, equals('Breakpoint')); | 66 expect(bpt.type, equals('Breakpoint')); |
66 expect(bpt.location.script.id, equals(script.id)); | 67 expect(bpt.location.script.id, equals(script.id)); |
67 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), | 68 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), |
68 equals(LINE_B)); | 69 equals(LINE_B)); |
69 expect(isolate.breakpoints.length, equals(2)); | 70 expect(isolate.breakpoints.length, equals(2)); |
70 } | 71 } |
71 | 72 |
72 { | 73 { |
73 var result = await isolate.addBreakpoint(script, LINE_C); | 74 var result = await isolate.addBreakpoint(script, LINE_C); |
74 expect(result is Breakpoint, isTrue); | 75 expect(result is Breakpoint, isTrue); |
75 Breakpoint bpt = result; | 76 Breakpoint bpt = result; |
76 expect(bpt.type, equals('Breakpoint')); | 77 expect(bpt.type, equals('Breakpoint')); |
77 expect(bpt.location.script.id, equals(script.id)); | 78 expect(bpt.location.script.id, equals(script.id)); |
78 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), | 79 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), |
79 equals(LINE_C)); | 80 equals(LINE_C)); |
80 expect(isolate.breakpoints.length, equals(3)); | 81 expect(isolate.breakpoints.length, equals(3)); |
81 } | 82 } |
82 | 83 |
83 // Wait for breakpoint events. | 84 // Wait for breakpoint events. |
84 }, | 85 }, |
85 | 86 |
86 resumeIsolate, | 87 resumeIsolate, |
87 | 88 |
88 hasStoppedAtBreakpoint, | 89 hasStoppedAtBreakpoint, |
89 | 90 |
90 // We are at the breakpoint on line LINE_A. | 91 // We are at the breakpoint on line LINE_A. |
91 (Isolate isolate) async { | 92 (Isolate isolate) async { |
92 ServiceMap stack = await isolate.getStack(); | 93 ServiceMap stack = await isolate.getStack(); |
93 expect(stack.type, equals('Stack')); | 94 expect(stack.type, equals('Stack')); |
94 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 95 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
95 | 96 |
96 Script script = stack['frames'][0].location.script; | 97 Script script = stack['frames'][0].location.script; |
97 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), | 98 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), |
98 equals(LINE_A)); | 99 equals(LINE_A)); |
99 }, | 100 }, |
100 | 101 |
101 resumeIsolate, | 102 resumeIsolate, |
102 | 103 |
103 hasStoppedAtBreakpoint, | 104 hasStoppedAtBreakpoint, |
104 | 105 |
105 // We are at the breakpoint on line LINE_B. | 106 // We are at the breakpoint on line LINE_B. |
106 (Isolate isolate) async { | 107 (Isolate isolate) async { |
107 ServiceMap stack = await isolate.getStack(); | 108 ServiceMap stack = await isolate.getStack(); |
108 expect(stack.type, equals('Stack')); | 109 expect(stack.type, equals('Stack')); |
109 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 110 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
110 | 111 |
111 Script script = stack['frames'][0].location.script; | 112 Script script = stack['frames'][0].location.script; |
112 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), | 113 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), |
113 equals(LINE_B)); | 114 equals(LINE_B)); |
114 }, | 115 }, |
115 | 116 |
116 resumeIsolate, | 117 resumeIsolate, |
117 | 118 |
118 hasStoppedAtBreakpoint, | 119 hasStoppedAtBreakpoint, |
119 | 120 |
120 // We are at the breakpoint on line LINE_C. | 121 // We are at the breakpoint on line LINE_C. |
121 (Isolate isolate) async { | 122 (Isolate isolate) async { |
122 ServiceMap stack = await isolate.getStack(); | 123 ServiceMap stack = await isolate.getStack(); |
123 expect(stack.type, equals('Stack')); | 124 expect(stack.type, equals('Stack')); |
124 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 125 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
125 | 126 |
126 Script script = stack['frames'][0].location.script; | 127 Script script = stack['frames'][0].location.script; |
127 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), | 128 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), |
128 equals(LINE_C)); | 129 equals(LINE_C)); |
129 }, | 130 }, |
130 | 131 |
131 resumeIsolate, | 132 resumeIsolate, |
| 133 |
132 ]; | 134 ]; |
133 | 135 |
134 main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain); | 136 main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain); |
OLD | NEW |