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 genRepeater(value) { | |
12 return () => print(value); | |
13 } | |
14 | |
15 genRepeaterNamed(value) { | |
16 return ({x, y}) => print(value); | |
17 } | |
18 | |
19 var r1; | |
20 var r2; | |
21 var r3; | |
22 | |
23 var r1_named; | |
24 var r2_named; | |
25 var r3_named; | |
26 | |
27 void testeeSetup() { | |
28 // These closures have the same function. | |
29 r1 = genRepeater('r1'); | |
30 r2 = genRepeater('r2'); | |
31 r3 = genRepeater('r3'); | |
32 | |
33 // These closures have the same function. | |
34 r1_named = genRepeaterNamed('r1_named'); | |
35 r2_named = genRepeaterNamed('r2_named'); | |
36 r3_named = genRepeaterNamed('r3_named'); | |
37 } | |
38 | |
39 void testeeDo() { | |
40 r1(); | |
41 r2(); | |
42 r3(); | |
43 } | |
44 | |
45 void testeeDoNamed() { | |
46 r1_named(y: 'Not a closure', x: 'Not a closure'); | |
47 r2_named(y: 'Not a closure', x: 'Not a closure'); | |
48 r3_named(y: 'Not a closure', x: 'Not a closure'); | |
49 } | |
50 | |
51 | |
52 var tests = [ | |
53 (Isolate isolate) async { | |
54 var rootLib = await isolate.rootLibrary.load(); | |
55 | |
56 var breaksHit = 0; | |
57 | |
58 var subscription; | |
59 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | |
60 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | |
61 print("Hit breakpoint ${event.breakpoint}"); | |
62 breaksHit++; | |
63 isolate.resume(); | |
64 } | |
65 }); | |
66 | |
67 valueOfField(String name) { | |
68 return rootLib.variables.singleWhere((v) => v.name == name).value; | |
69 } | |
70 var r1Ref = valueOfField('r1'); | |
71 var r2Ref = valueOfField('r2'); | |
72 var r3Ref = valueOfField('r3'); | |
73 | |
74 var bpt1 = await isolate.addBreakOnActivation(r1Ref); | |
75 print("Added breakpoint $bpt1"); | |
76 expect(bpt1 is Breakpoint, isTrue); | |
77 expect(breaksHit, equals(0)); | |
78 print("testeeDo()"); | |
79 var res = await rootLib.evaluate("testeeDo()"); | |
80 expect(res is Instance, isTrue); // Not error. | |
81 expect(breaksHit, equals(1)); | |
82 | |
83 await isolate.removeBreakpoint(bpt1); | |
84 print("Removed breakpoint $bpt1"); | |
85 print("testeeDo()"); | |
86 res = await rootLib.evaluate("testeeDo()"); | |
87 expect(res is Instance, isTrue); // Not error. | |
88 expect(breaksHit, equals(1)); | |
89 | |
90 await subscription.cancel(); | |
91 }, | |
92 | |
93 (Isolate isolate) async { | |
94 var rootLib = await isolate.rootLibrary.load(); | |
95 | |
96 var breaksHit = 0; | |
97 | |
98 var subscription; | |
99 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | |
100 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | |
101 print("Hit breakpoint ${event.breakpoint}"); | |
102 breaksHit++; | |
103 isolate.resume(); | |
104 } | |
105 }); | |
106 | |
107 valueOfField(String name) { | |
108 return rootLib.variables.singleWhere((v) => v.name == name).value; | |
109 } | |
110 var r1Ref = valueOfField('r1_named'); | |
111 var r2Ref = valueOfField('r2_named'); | |
112 var r3Ref = valueOfField('r3_named'); | |
113 | |
114 var bpt1 = await isolate.addBreakOnActivation(r1Ref); | |
115 print("Added breakpoint $bpt1"); | |
116 expect(bpt1 is Breakpoint, isTrue); | |
117 expect(breaksHit, equals(0)); | |
118 print("testeeDoNamed()"); | |
119 var res = await rootLib.evaluate("testeeDoNamed()"); | |
120 expect(res is Instance, isTrue); // Not error. | |
121 expect(breaksHit, equals(1)); | |
122 | |
123 await isolate.removeBreakpoint(bpt1); | |
124 print("Removed breakpoint $bpt1"); | |
125 print("testeeDoNamed()"); | |
126 res = await rootLib.evaluate("testeeDoNamed()"); | |
127 expect(res is Instance, isTrue); // Not error. | |
128 expect(breaksHit, equals(1)); | |
129 | |
130 await subscription.cancel(); | |
131 }, | |
132 | |
133 (Isolate isolate) async { | |
134 var rootLib = await isolate.rootLibrary.load(); | |
135 | |
136 var breaksHit = 0; | |
137 | |
138 var subscription; | |
139 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | |
140 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | |
141 print("Hit breakpoint ${event.breakpoint}"); | |
142 breaksHit++; | |
143 isolate.resume(); | |
144 } | |
145 }); | |
146 | |
147 valueOfField(String name) { | |
148 return rootLib.variables.singleWhere((v) => v.name == name).value; | |
149 } | |
150 var r1Ref = valueOfField('r1'); | |
151 var r2Ref = valueOfField('r2'); | |
152 var r3Ref = valueOfField('r3'); | |
153 | |
154 var bpt1 = await isolate.addBreakOnActivation(r1Ref); | |
155 print("Added breakpoint $bpt1"); | |
156 expect(bpt1 is Breakpoint, isTrue); | |
157 expect(breaksHit, equals(0)); | |
158 print("testeeDo()"); | |
159 var res = await rootLib.evaluate("testeeDo()"); | |
160 expect(res is Instance, isTrue); // Not error. | |
161 expect(breaksHit, equals(1)); | |
162 | |
163 var bpt2 = await isolate.addBreakOnActivation(r2Ref); | |
164 print("Added breakpoint $bpt2"); | |
165 expect(bpt2 is Breakpoint, isTrue); | |
166 expect(breaksHit, equals(1)); | |
167 print("testeeDo()"); | |
168 res = await rootLib.evaluate("testeeDo()"); | |
169 expect(res is Instance, isTrue); // Not error. | |
170 expect(breaksHit, equals(3)); | |
171 | |
172 await isolate.removeBreakpoint(bpt1); | |
173 print("Removed breakpoint $bpt1"); | |
174 print("testeeDo()"); | |
175 res = await rootLib.evaluate("testeeDo()"); | |
176 expect(res is Instance, isTrue); // Not error. | |
177 expect(breaksHit, equals(4)); | |
178 | |
179 await isolate.removeBreakpoint(bpt2); | |
180 print("Removed breakpoint $bpt2"); | |
181 print("testeeDo()"); | |
182 res = await rootLib.evaluate("testeeDo()"); | |
183 expect(res is Instance, isTrue); // Not error. | |
184 expect(breaksHit, equals(4)); | |
185 | |
186 await subscription.cancel(); | |
187 }, | |
188 | |
189 ]; | |
190 | |
191 main(args) => runIsolateTests(args, tests, testeeBefore: testeeSetup); | |
OLD | NEW |