OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override | |
5 | |
6 import 'package:observatory/service_io.dart'; | |
7 import 'package:unittest/unittest.dart'; | |
8 import 'test_helper.dart'; | |
9 import 'dart:async'; | |
10 | |
11 import 'dart:math' as math; | |
12 | |
13 breakHere() {} | |
14 | |
15 class C { | |
16 var instVar = 1; | |
17 static var classVar = 2; | |
18 | |
19 method(methodParam) { | |
20 var methodTemp = 4; | |
21 [5].forEach((outerParam) { | |
22 var outerTemp = 6; | |
23 [7].forEach((innerParam) { | |
24 var innerTemp = 8; | |
25 breakHere(); | |
26 }); | |
27 }); | |
28 } | |
29 | |
30 static method2(methodParam) { | |
31 var methodTemp = 4; | |
32 [5].forEach((outerParam) { | |
33 var outerTemp = 6; | |
34 [7].forEach((innerParam) { | |
35 var innerTemp = 8; | |
36 breakHere(); | |
37 }); | |
38 }); | |
39 } | |
40 | |
41 method3(methodParam) { | |
42 var methodTemp = 4; | |
43 breakHere(); | |
44 } | |
45 | |
46 static var closureWithReturnedHome; | |
47 method4(methodParam) { | |
48 var methodTemp = 4; | |
49 [5].forEach((outerParam) { | |
50 var outerTemp = 6; | |
51 closureWithReturnedHome = (innerParam) { | |
52 var innerTemp = 8; | |
53 breakHere(); | |
54 }; | |
55 }); | |
56 } | |
57 } | |
58 | |
59 testMethod(Isolate isolate) async { | |
60 Library rootLib = await isolate.rootLib.load(); | |
61 ServiceFunction function = | |
62 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); | |
63 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); | |
64 print("Breakpoint: $bpt"); | |
65 expect(bpt is Breakpoint, isTrue); // I.e, not null. | |
66 | |
67 bool hitBreakpoint = false; | |
68 var sub = isolate.vm.events.stream.listen((ServiceEvent event) async { | |
69 print("Event $event"); | |
70 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | |
71 var n = 1; | |
Cutch
2015/04/10 21:15:25
frameNum ?
rmacnak
2015/04/10 22:36:44
Done.
| |
72 expect((await isolate.evalFrame(n, '123')).valueAsString, /// bro keninstance: runtime error | |
Cutch
2015/04/10 21:15:25
column limits..
rmacnak
2015/04/10 22:36:44
Lots of reshuffling, still doesn't quite fit with
| |
73 equals('123')); /// bro keninstance: continued | |
74 expect((await isolate.evalFrame(n, 'this')).clazz.name, /// mis singscope: runtime error | |
75 equals('C')); /// mis singscope: continued | |
76 expect((await isolate.evalFrame(n, 'instVar')).valueAsString, /// mis singscope: continued | |
77 equals('1')); /// mis singscope: continued | |
78 expect((await isolate.evalFrame(n, 'classVar')).valueAsString, /// bro keninstance: continued | |
79 equals('2')); /// bro keninstance: continued | |
80 expect((await isolate.evalFrame(n, 'methodParam')).valueAsString, /// mis singscope: continued | |
81 equals('3')); /// mis singscope: continued | |
82 expect((await isolate.evalFrame(n, 'methodTemp')).valueAsString, /// mis singscope: continued | |
83 equals('4')); /// mis singscope: continued | |
84 expect((await isolate.evalFrame(n, 'outerParam')).valueAsString, /// mis singscope: continued | |
85 equals('5')); /// mis singscope: continued | |
86 expect((await isolate.evalFrame(n, 'outerTemp')).valueAsString, /// mis singscope: continued | |
87 equals('6')); /// mis singscope: continued | |
88 expect((await isolate.evalFrame(n, 'innerParam')).valueAsString, /// bro keninstance: continued | |
89 equals('7')); /// bro keninstance: continued | |
90 expect((await isolate.evalFrame(n, 'innerTemp')).valueAsString, /// bro keninstance: continued | |
91 equals('8')); /// bro keninstance: continued | |
92 expect((await isolate.evalFrame(n, 'math.sqrt')).isClosure, /// bro keninstance: continued | |
93 isTrue); /// bro keninstance: continued | |
94 | |
95 hitBreakpoint = true; | |
96 isolate.resume(); | |
97 } | |
98 }); | |
99 | |
100 var result = await isolate.eval(rootLib, 'new C().method(3);'); | |
101 print("Result $result"); | |
102 expect(hitBreakpoint, isTrue); | |
103 sub.cancel(); // So the next test gets the events. | |
104 } | |
105 | |
106 testMethod2(Isolate isolate) async { | |
107 Library rootLib = await isolate.rootLib.load(); | |
108 ServiceFunction function = | |
109 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); | |
110 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); | |
111 print("Breakpoint: $bpt"); | |
112 expect(bpt is Breakpoint, isTrue); // I.e, not null. | |
113 | |
114 bool hitBreakpoint = false; | |
115 var sub = isolate.vm.events.stream.listen((ServiceEvent event) async { | |
116 print("Event $event"); | |
117 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | |
118 var n = 1; | |
119 expect((await isolate.evalFrame(n, '123')).valueAsString, | |
120 equals('123')); | |
121 expect((await isolate.evalFrame(n, 'this')) is DartError, | |
122 isTrue); | |
123 expect((await isolate.evalFrame(n, 'instVar')) is DartError, | |
124 isTrue); | |
125 expect((await isolate.evalFrame(n, 'classVar')).valueAsString, | |
126 equals('2')); | |
127 expect((await isolate.evalFrame(n, 'methodParam')).valueAsString, /// miss ingscope: continued | |
128 equals('3')); /// miss ingscope: continued | |
129 expect((await isolate.evalFrame(n, 'methodTemp')).valueAsString, /// miss ingscope: continued | |
130 equals('4')); /// miss ingscope: continued | |
131 expect((await isolate.evalFrame(n, 'outerParam')).valueAsString, /// miss ingscope: continued | |
132 equals('5')); /// miss ingscope: continued | |
133 expect((await isolate.evalFrame(n, 'outerTemp')).valueAsString, /// miss ingscope: continued | |
134 equals('6')); /// miss ingscope: continued | |
135 expect((await isolate.evalFrame(n, 'innerParam')).valueAsString, | |
136 equals('7')); | |
137 expect((await isolate.evalFrame(n, 'innerTemp')).valueAsString, | |
138 equals('8')); | |
139 expect((await isolate.evalFrame(n, 'math.sqrt')).isClosure, | |
140 isTrue); | |
141 | |
142 hitBreakpoint = true; | |
143 isolate.resume(); | |
144 } | |
145 }); | |
146 | |
147 var result = await isolate.eval(rootLib, 'C.method2(3);'); | |
148 print("Result $result"); | |
149 expect(hitBreakpoint, isTrue); | |
150 sub.cancel(); // So the next test gets the events. | |
151 } | |
152 | |
153 testMethod3(Isolate isolate) async { | |
154 Library rootLib = await isolate.rootLib.load(); | |
155 ServiceFunction function = | |
156 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); | |
157 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); | |
158 print("Breakpoint: $bpt"); | |
159 expect(bpt is Breakpoint, isTrue); // I.e, not null. | |
160 | |
161 bool hitBreakpoint = false; | |
162 var sub = isolate.vm.events.stream.listen((ServiceEvent event) async { | |
163 print("Event $event"); | |
164 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | |
165 var n = 1; | |
166 expect((await isolate.evalFrame(n, '123')).valueAsString, | |
167 equals('123')); | |
168 expect((await isolate.evalFrame(n, 'this')).clazz.name, | |
169 equals('C')); | |
170 expect((await isolate.evalFrame(n, 'instVar')).valueAsString, | |
171 equals('1')); | |
172 expect((await isolate.evalFrame(n, 'classVar')).valueAsString, | |
173 equals('2')); | |
174 expect((await isolate.evalFrame(n, 'methodParam')).valueAsString, | |
175 equals('3')); | |
176 expect((await isolate.evalFrame(n, 'methodTemp')).valueAsString, | |
177 equals('4')); | |
178 expect((await isolate.evalFrame(n, 'math.sqrt')).isClosure, | |
179 isTrue); | |
180 | |
181 hitBreakpoint = true; | |
182 isolate.resume(); | |
183 } | |
184 }); | |
185 | |
186 var result = await isolate.eval(rootLib, 'new C().method3(3);'); | |
187 print("Result $result"); | |
188 expect(hitBreakpoint, isTrue); | |
189 sub.cancel(); // So the next test gets the events. | |
Cutch
2015/04/10 21:15:25
these tests should return a completer's future tha
rmacnak
2015/04/10 22:36:44
That's too soon because the result of the library
| |
190 } | |
191 | |
192 | |
193 testMethod4(Isolate isolate) async { | |
194 Library rootLib = await isolate.rootLib.load(); | |
195 ServiceFunction function = | |
196 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); | |
197 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); | |
198 print("Breakpoint: $bpt"); | |
199 expect(bpt is Breakpoint, isTrue); // I.e, not null. | |
200 | |
201 bool hitBreakpoint = false; | |
202 var sub = isolate.vm.events.stream.listen((ServiceEvent event) async { | |
203 print("Event $event"); | |
204 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | |
205 var n = 1; | |
206 expect((await isolate.evalFrame(n, '123')).valueAsString, /// bro keninstance: runtime error | |
207 equals('123')); /// bro keninstance: continued | |
208 expect((await isolate.evalFrame(n, 'this')).clazz.name, /// mis singscope: runtime error | |
209 equals('C')); /// mis singscope: continued | |
210 expect((await isolate.evalFrame(n, 'instVar')).valueAsString, /// mis singscope: continued | |
211 equals('1')); /// mis singscope: continued | |
212 expect((await isolate.evalFrame(n, 'classVar')).valueAsString, /// bro keninstance: continued | |
213 equals('2')); /// bro keninstance: continued | |
214 expect((await isolate.evalFrame(n, 'methodParam')).valueAsString, /// mis singscope: continued | |
215 equals('3')); /// mis singscope: continued | |
216 expect((await isolate.evalFrame(n, 'methodTemp')).valueAsString, /// mis singscope: continued | |
217 equals('4')); /// mis singscope: continued | |
218 expect((await isolate.evalFrame(n, 'outerParam')).valueAsString, /// mis singscope: continued | |
219 equals('5')); /// mis singscope: continued | |
220 expect((await isolate.evalFrame(n, 'outerTemp')).valueAsString, /// mis singscope: continued | |
221 equals('6')); /// mis singscope: continued | |
222 expect((await isolate.evalFrame(n, 'innerParam')).valueAsString, /// bro keninstance: continued | |
223 equals('7')); /// bro keninstance: continued | |
224 expect((await isolate.evalFrame(n, 'innerTemp')).valueAsString, /// bro keninstance: continued | |
225 equals('8')); /// bro keninstance: continued | |
226 expect((await isolate.evalFrame(n, 'math.sqrt')).isClosure, /// bro keninstance: continued | |
227 isTrue); /// bro keninstance: continued | |
228 | |
229 hitBreakpoint = true; | |
230 isolate.resume(); | |
231 } | |
232 }); | |
233 | |
234 var result = await isolate.eval(rootLib, | |
235 '(){ new C().method4(3); C.closureWithReturnedHome(7); }()'); | |
236 print("Result $result"); | |
237 expect(hitBreakpoint, isTrue); | |
238 sub.cancel(); // So the next test gets the events. | |
239 } | |
240 | |
241 var tests = [ | |
242 testMethod, | |
243 testMethod2, | |
244 testMethod3, | |
245 testMethod4, | |
246 ]; | |
247 | |
248 main(args) => runIsolateTests(args, tests); | |
OLD | NEW |