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

Side by Side Diff: runtime/observatory/tests/service/debugger_location_test.dart

Issue 1150303004: Switch to using SourceLocation universally in service protocol. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: post merge Created 5 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
OLDNEW
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=--compile-all --error_on_bad_type --error_on_bad_override 4 // VMOptions=--compile-all --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:observatory/debugger.dart'; 7 import 'package:observatory/debugger.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 import 'test_helper.dart'; 9 import 'test_helper.dart';
10 import 'dart:async'; 10 import 'dart:async';
11 11
12 void testFunction() { 12 void testFunction() {
13 int i = 0; 13 int i = 0;
14 while (true) { 14 while (true) {
15 if (++i % 100000000 == 0) { // line 15 15 if (++i % 100000000 == 0) { // line 15
16 print(i); 16 print(i);
17 } 17 }
18 } 18 }
19 } 19 }
20 20
21 class TestDebugger extends Debugger { 21 class TestDebugger extends Debugger {
22 TestDebugger(this.isolate, this.stack); 22 TestDebugger(this.isolate, this.stack);
23 23
24 VM get vm => isolate.vm; 24 VM get vm => isolate.vm;
25 Isolate isolate; 25 Isolate isolate;
26 ServiceMap stack; 26 ServiceMap stack;
27 int currentFrame = 0; 27 int currentFrame = 0;
28 } 28 }
29 29
30 void source_location_dummy_function() { 30 void debugger_location_dummy_function() {
31 } 31 }
32 32
33 class SourceLocationTestFoo { 33 class DebuggerLocationTestFoo {
34 SourceLocationTestFoo(this.field); 34 DebuggerLocationTestFoo(this.field);
35 SourceLocationTestFoo.named(); 35 DebuggerLocationTestFoo.named();
36 36
37 void method() {} 37 void method() {}
38 void madness() {} 38 void madness() {}
39 39
40 int field; 40 int field;
41 } 41 }
42 42
43 class SourceLocationTestBar { 43 class DebuggerLocationTestBar {
44 } 44 }
45 45
46 Future<Debugger> initDebugger(Isolate isolate) { 46 Future<Debugger> initDebugger(Isolate isolate) {
47 return isolate.getStack().then((stack) { 47 return isolate.getStack().then((stack) {
48 return new TestDebugger(isolate, stack); 48 return new TestDebugger(isolate, stack);
49 }); 49 });
50 } 50 }
51 51
52 var tests = [ 52 var tests = [
53 53
(...skipping 12 matching lines...) Expand all
66 var script = isolate.rootLibrary.scripts[0]; 66 var script = isolate.rootLibrary.scripts[0];
67 return isolate.addBreakpoint(script, 15).then((ServiceObject bpt) { 67 return isolate.addBreakpoint(script, 15).then((ServiceObject bpt) {
68 return completer.future; // Wait for breakpoint events. 68 return completer.future; // Wait for breakpoint events.
69 }); 69 });
70 }); 70 });
71 }, 71 },
72 72
73 // Parse '' => current position 73 // Parse '' => current position
74 (Isolate isolate) { 74 (Isolate isolate) {
75 return initDebugger(isolate).then((debugger) { 75 return initDebugger(isolate).then((debugger) {
76 return SourceLocation.parse(debugger, '').then((SourceLocation loc) { 76 return DebuggerLocation.parse(debugger, '').then((DebuggerLocation loc) {
77 expect(loc.valid, isTrue); 77 expect(loc.valid, isTrue);
78 expect(loc.toString(), equals('source_location_test.dart:15')); 78 expect(loc.toString(), equals('debugger_location_test.dart:15'));
79 }); 79 });
80 }); 80 });
81 }, 81 },
82 82
83 // Parse line 83 // Parse line
84 (Isolate isolate) { 84 (Isolate isolate) {
85 return initDebugger(isolate).then((debugger) { 85 return initDebugger(isolate).then((debugger) {
86 return SourceLocation.parse(debugger, '16').then((SourceLocation loc) { 86 return DebuggerLocation.parse(debugger, '16').then((DebuggerLocation loc) {
87 expect(loc.valid, isTrue); 87 expect(loc.valid, isTrue);
88 expect(loc.toString(), equals('source_location_test.dart:16')); 88 expect(loc.toString(), equals('debugger_location_test.dart:16'));
89 }); 89 });
90 }); 90 });
91 }, 91 },
92 92
93 // Parse line + col 93 // Parse line + col
94 (Isolate isolate) { 94 (Isolate isolate) {
95 return initDebugger(isolate).then((debugger) { 95 return initDebugger(isolate).then((debugger) {
96 return SourceLocation.parse(debugger, '16:11').then((SourceLocation loc) { 96 return DebuggerLocation.parse(debugger, '16:11').then((DebuggerLocation loc) {
97 expect(loc.valid, isTrue); 97 expect(loc.valid, isTrue);
98 expect(loc.toString(), equals('source_location_test.dart:16:11')); 98 expect(loc.toString(), equals('debugger_location_test.dart:16:11'));
99 }); 99 });
100 }); 100 });
101 }, 101 },
102 102
103 // Parse script + line 103 // Parse script + line
104 (Isolate isolate) { 104 (Isolate isolate) {
105 return initDebugger(isolate).then((debugger) { 105 return initDebugger(isolate).then((debugger) {
106 return SourceLocation.parse(debugger, 'unittest.dart:15') 106 return DebuggerLocation.parse(debugger, 'unittest.dart:15')
107 .then((SourceLocation loc) { 107 .then((DebuggerLocation loc) {
108 expect(loc.valid, isTrue); 108 expect(loc.valid, isTrue);
109 expect(loc.toString(), equals('unittest.dart:15')); 109 expect(loc.toString(), equals('unittest.dart:15'));
110 }); 110 });
111 }); 111 });
112 }, 112 },
113 113
114 // Parse script + line + col 114 // Parse script + line + col
115 (Isolate isolate) { 115 (Isolate isolate) {
116 return initDebugger(isolate).then((debugger) { 116 return initDebugger(isolate).then((debugger) {
117 return SourceLocation.parse(debugger, 'unittest.dart:15:10') 117 return DebuggerLocation.parse(debugger, 'unittest.dart:15:10')
118 .then((SourceLocation loc) { 118 .then((DebuggerLocation loc) {
119 expect(loc.valid, isTrue); 119 expect(loc.valid, isTrue);
120 expect(loc.toString(), equals('unittest.dart:15:10')); 120 expect(loc.toString(), equals('unittest.dart:15:10'));
121 }); 121 });
122 }); 122 });
123 }, 123 },
124 124
125 // Parse bad script 125 // Parse bad script
126 (Isolate isolate) { 126 (Isolate isolate) {
127 return initDebugger(isolate).then((debugger) { 127 return initDebugger(isolate).then((debugger) {
128 return SourceLocation.parse(debugger, 'bad.dart:15') 128 return DebuggerLocation.parse(debugger, 'bad.dart:15')
129 .then((SourceLocation loc) { 129 .then((DebuggerLocation loc) {
130 expect(loc.valid, isFalse); 130 expect(loc.valid, isFalse);
131 expect(loc.toString(), equals( 131 expect(loc.toString(), equals(
132 'invalid source location (Script \'bad.dart\' not found)')); 132 'invalid source location (Script \'bad.dart\' not found)'));
133 }); 133 });
134 }); 134 });
135 }, 135 },
136 136
137 // Parse function 137 // Parse function
138 (Isolate isolate) { 138 (Isolate isolate) {
139 return initDebugger(isolate).then((debugger) { 139 return initDebugger(isolate).then((debugger) {
140 return SourceLocation.parse(debugger, 'testFunction') 140 return DebuggerLocation.parse(debugger, 'testFunction')
141 .then((SourceLocation loc) { 141 .then((DebuggerLocation loc) {
142 expect(loc.valid, isTrue); 142 expect(loc.valid, isTrue);
143 expect(loc.toString(), equals('testFunction')); 143 expect(loc.toString(), equals('testFunction'));
144 }); 144 });
145 }); 145 });
146 }, 146 },
147 147
148 // Parse bad function 148 // Parse bad function
149 (Isolate isolate) { 149 (Isolate isolate) {
150 return initDebugger(isolate).then((debugger) { 150 return initDebugger(isolate).then((debugger) {
151 return SourceLocation.parse(debugger, 'doesNotReallyExit') 151 return DebuggerLocation.parse(debugger, 'doesNotReallyExit')
152 .then((SourceLocation loc) { 152 .then((DebuggerLocation loc) {
153 expect(loc.valid, isFalse); 153 expect(loc.valid, isFalse);
154 expect(loc.toString(), equals( 154 expect(loc.toString(), equals(
155 'invalid source location (Function \'doesNotReallyExit\' not found)' )); 155 'invalid source location (Function \'doesNotReallyExit\' not found)' ));
156 }); 156 });
157 }); 157 });
158 }, 158 },
159 159
160 // Parse constructor 160 // Parse constructor
161 (Isolate isolate) { 161 (Isolate isolate) {
162 return initDebugger(isolate).then((debugger) { 162 return initDebugger(isolate).then((debugger) {
163 return SourceLocation.parse(debugger, 'SourceLocationTestFoo') 163 return DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo')
164 .then((SourceLocation loc) { 164 .then((DebuggerLocation loc) {
165 expect(loc.valid, isTrue); 165 expect(loc.valid, isTrue);
166 // TODO(turnidge): Printing a constructor currently adds 166 // TODO(turnidge): Printing a constructor currently adds
167 // another class qualifier at the front. Do we want to change 167 // another class qualifier at the front. Do we want to change
168 // this to be more consistent? 168 // this to be more consistent?
169 expect(loc.toString(), equals( 169 expect(loc.toString(), equals(
170 'SourceLocationTestFoo.SourceLocationTestFoo')); 170 'DebuggerLocationTestFoo.DebuggerLocationTestFoo'));
171 }); 171 });
172 }); 172 });
173 }, 173 },
174 174
175 // Parse named constructor 175 // Parse named constructor
176 (Isolate isolate) { 176 (Isolate isolate) {
177 return initDebugger(isolate).then((debugger) { 177 return initDebugger(isolate).then((debugger) {
178 return SourceLocation.parse(debugger, 'SourceLocationTestFoo.named') 178 return DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo.named')
179 .then((SourceLocation loc) { 179 .then((DebuggerLocation loc) {
180 expect(loc.valid, isTrue); 180 expect(loc.valid, isTrue);
181 // TODO(turnidge): Printing a constructor currently adds 181 // TODO(turnidge): Printing a constructor currently adds
182 // another class qualifier at the front. Do we want to change 182 // another class qualifier at the front. Do we want to change
183 // this to be more consistent? 183 // this to be more consistent?
184 expect(loc.toString(), equals( 184 expect(loc.toString(), equals(
185 'SourceLocationTestFoo.SourceLocationTestFoo.named')); 185 'DebuggerLocationTestFoo.DebuggerLocationTestFoo.named'));
186 }); 186 });
187 }); 187 });
188 }, 188 },
189 189
190 // Parse method 190 // Parse method
191 (Isolate isolate) { 191 (Isolate isolate) {
192 return initDebugger(isolate).then((debugger) { 192 return initDebugger(isolate).then((debugger) {
193 return SourceLocation.parse(debugger, 'SourceLocationTestFoo.method') 193 return DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo.method')
194 .then((SourceLocation loc) { 194 .then((DebuggerLocation loc) {
195 expect(loc.valid, isTrue); 195 expect(loc.valid, isTrue);
196 expect(loc.toString(), equals('SourceLocationTestFoo.method')); 196 expect(loc.toString(), equals('DebuggerLocationTestFoo.method'));
197 }); 197 });
198 }); 198 });
199 }, 199 },
200 200
201 // Parse method 201 // Parse method
202 (Isolate isolate) { 202 (Isolate isolate) {
203 return initDebugger(isolate).then((debugger) { 203 return initDebugger(isolate).then((debugger) {
204 return SourceLocation.parse(debugger, 'SourceLocationTestFoo.field=') 204 return DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo.field=')
205 .then((SourceLocation loc) { 205 .then((DebuggerLocation loc) {
206 expect(loc.valid, isTrue); 206 expect(loc.valid, isTrue);
207 expect(loc.toString(), equals('SourceLocationTestFoo.field=')); 207 expect(loc.toString(), equals('DebuggerLocationTestFoo.field='));
208 }); 208 });
209 }); 209 });
210 }, 210 },
211 211
212 // Parse bad method 212 // Parse bad method
213 (Isolate isolate) { 213 (Isolate isolate) {
214 return initDebugger(isolate).then((debugger) { 214 return initDebugger(isolate).then((debugger) {
215 return SourceLocation.parse(debugger, 'SourceLocationTestFoo.missing') 215 return DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo.missing')
216 .then((SourceLocation loc) { 216 .then((DebuggerLocation loc) {
217 expect(loc.valid, isFalse); 217 expect(loc.valid, isFalse);
218 expect(loc.toString(), equals( 218 expect(loc.toString(), equals(
219 'invalid source location ' 219 'invalid source location '
220 '(Function \'SourceLocationTestFoo.missing\' not found)')); 220 '(Function \'DebuggerLocationTestFoo.missing\' not found)'));
221 }); 221 });
222 }); 222 });
223 }, 223 },
224 224
225 // Complete function + script 225 // Complete function + script
226 (Isolate isolate) { 226 (Isolate isolate) {
227 return initDebugger(isolate).then((debugger) { 227 return initDebugger(isolate).then((debugger) {
228 return SourceLocation.complete(debugger, 'source_loc') 228 return DebuggerLocation.complete(debugger, 'debugger_loc')
229 .then((List<String> completions) { 229 .then((List<String> completions) {
230 expect(completions.toString(), equals( 230 expect(completions.toString(), equals(
231 '[source_location_dummy_function, ' 231 '[debugger_location_dummy_function, '
232 'source_location.dart:, source_location_test.dart:]')); 232 'debugger_location.dart:, debugger_location_test.dart:]'));
233 }); 233 });
234 }); 234 });
235 }, 235 },
236 236
237 // Complete class 237 // Complete class
238 (Isolate isolate) { 238 (Isolate isolate) {
239 return initDebugger(isolate).then((debugger) { 239 return initDebugger(isolate).then((debugger) {
240 return SourceLocation.complete(debugger, 'SourceLocationTe') 240 return DebuggerLocation.complete(debugger, 'DebuggerLocationTe')
241 .then((List<String> completions) { 241 .then((List<String> completions) {
242 expect(completions.toString(), equals( 242 expect(completions.toString(), equals(
243 '[SourceLocationTestBar, SourceLocationTestFoo]')); 243 '[DebuggerLocationTestBar, DebuggerLocationTestFoo]'));
244 }); 244 });
245 }); 245 });
246 }, 246 },
247 247
248 // No completions: unqualified name 248 // No completions: unqualified name
249 (Isolate isolate) { 249 (Isolate isolate) {
250 return initDebugger(isolate).then((debugger) { 250 return initDebugger(isolate).then((debugger) {
251 return SourceLocation.complete(debugger, 'source_locXYZZY') 251 return DebuggerLocation.complete(debugger, 'debugger_locXYZZY')
252 .then((List<String> completions) { 252 .then((List<String> completions) {
253 expect(completions.toString(), equals('[]')); 253 expect(completions.toString(), equals('[]'));
254 }); 254 });
255 }); 255 });
256 }, 256 },
257 257
258 // Complete method 258 // Complete method
259 (Isolate isolate) { 259 (Isolate isolate) {
260 return initDebugger(isolate).then((debugger) { 260 return initDebugger(isolate).then((debugger) {
261 return SourceLocation.complete(debugger, 'SourceLocationTestFoo.m') 261 return DebuggerLocation.complete(debugger, 'DebuggerLocationTestFoo.m')
262 .then((List<String> completions) { 262 .then((List<String> completions) {
263 expect(completions.toString(), equals( 263 expect(completions.toString(), equals(
264 '[SourceLocationTestFoo.madness, SourceLocationTestFoo.method]')); 264 '[DebuggerLocationTestFoo.madness, DebuggerLocationTestFoo.method]'));
265 }); 265 });
266 }); 266 });
267 }, 267 },
268 268
269 // No completions: qualified name 269 // No completions: qualified name
270 (Isolate isolate) { 270 (Isolate isolate) {
271 return initDebugger(isolate).then((debugger) { 271 return initDebugger(isolate).then((debugger) {
272 return SourceLocation.complete(debugger, 'SourceLocationTestFoo.q') 272 return DebuggerLocation.complete(debugger, 'DebuggerLocationTestFoo.q')
273 .then((List<String> completions) { 273 .then((List<String> completions) {
274 expect(completions.toString(), equals('[]')); 274 expect(completions.toString(), equals('[]'));
275 }); 275 });
276 }); 276 });
277 }, 277 },
278 278
279 ]; 279 ];
280 280
281 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); 281 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction);
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/coverage_test.dart ('k') | runtime/observatory/tests/service/debugging_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698