OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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:observatory/debugger.dart'; | 7 import 'package:observatory/debugger.dart'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 import 'service_test_common.dart'; | 9 import 'service_test_common.dart'; |
10 import 'test_helper.dart'; | 10 import 'test_helper.dart'; |
11 import 'dart:async'; | 11 import 'dart:async'; |
12 import 'dart:developer'; | 12 import 'dart:developer'; |
13 | 13 |
14 const int LINE_A = 22; | 14 const int LINE_A = 22; |
15 const int LINE_B = 110; | 15 const int LINE_B = 110; |
16 const int LINE_C = 12; | 16 const int LINE_C = 12; |
17 | 17 |
18 void testFunction() { | 18 void testFunction() { |
19 int i = 0; | 19 int i = 0; |
20 while (i == 0) { | 20 while (i == 0) { |
21 debugger(); | 21 debugger(); |
22 print('loop'); // Line A. | 22 print('loop'); // Line A. |
23 print('loop'); | 23 print('loop'); |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 class TestDebugger extends Debugger { | 27 class TestDebugger extends Debugger { |
28 TestDebugger(this.isolate, this.stack); | 28 TestDebugger(this.isolate, this.stack); |
29 | 29 |
30 VM get vm => isolate.vm; | 30 VM get vm => isolate.vm; |
31 Isolate isolate; | 31 Isolate isolate; |
32 ServiceMap stack; | 32 ServiceMap stack; |
33 int currentFrame = 0; | 33 int currentFrame = 0; |
34 } | 34 } |
35 | 35 |
36 void debugger_location_dummy_function() { | 36 void debugger_location_dummy_function() {} |
37 } | |
38 | 37 |
39 class DebuggerLocationTestFoo { | 38 class DebuggerLocationTestFoo { |
40 DebuggerLocationTestFoo(this.field); | 39 DebuggerLocationTestFoo(this.field); |
41 DebuggerLocationTestFoo.named(); | 40 DebuggerLocationTestFoo.named(); |
42 | 41 |
43 void method() {} | 42 void method() {} |
44 void madness() {} | 43 void madness() {} |
45 | 44 |
46 int field; | 45 int field; |
47 } | 46 } |
48 | 47 |
49 class DebuggerLocationTestBar { | 48 class DebuggerLocationTestBar {} |
50 } | |
51 | 49 |
52 Future<Debugger> initDebugger(Isolate isolate) { | 50 Future<Debugger> initDebugger(Isolate isolate) { |
53 return isolate.getStack().then((stack) { | 51 return isolate.getStack().then((stack) { |
54 return new TestDebugger(isolate, stack); | 52 return new TestDebugger(isolate, stack); |
55 }); | 53 }); |
56 } | 54 } |
57 | 55 |
58 var tests = [ | 56 var tests = [ |
59 | 57 hasStoppedAtBreakpoint, |
60 hasStoppedAtBreakpoint, | |
61 | 58 |
62 // Load the isolate's libraries | 59 // Load the isolate's libraries |
63 (Isolate isolate) async { | 60 (Isolate isolate) async { |
64 for (var lib in isolate.libraries) { | 61 for (var lib in isolate.libraries) { |
65 await lib.load(); | 62 await lib.load(); |
66 } | 63 } |
67 }, | 64 }, |
68 | 65 |
69 // Parse method | 66 // Parse method |
70 (Isolate isolate) async { | 67 (Isolate isolate) async { |
71 var debugger = await initDebugger(isolate); | 68 var debugger = await initDebugger(isolate); |
72 var loc = | 69 var loc = await DebuggerLocation.parse( |
73 await DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo.method'); | 70 debugger, 'DebuggerLocationTestFoo.method'); |
74 expect(loc.valid, isTrue); | 71 expect(loc.valid, isTrue); |
75 expect(loc.toString(), equals('DebuggerLocationTestFoo.method')); | 72 expect(loc.toString(), equals('DebuggerLocationTestFoo.method')); |
76 }, | 73 }, |
77 | 74 |
78 // Parse method | 75 // Parse method |
79 (Isolate isolate) async { | 76 (Isolate isolate) async { |
80 var debugger = await initDebugger(isolate); | 77 var debugger = await initDebugger(isolate); |
81 var loc = | 78 var loc = await DebuggerLocation.parse( |
82 await DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo.field='); | 79 debugger, 'DebuggerLocationTestFoo.field='); |
83 expect(loc.valid, isTrue); | 80 expect(loc.valid, isTrue); |
84 expect(loc.toString(), equals('DebuggerLocationTestFoo.field=')); | 81 expect(loc.toString(), equals('DebuggerLocationTestFoo.field=')); |
85 }, | 82 }, |
86 | 83 |
87 // Parse bad method | 84 // Parse bad method |
88 (Isolate isolate) async { | 85 (Isolate isolate) async { |
89 var debugger = await initDebugger(isolate); | 86 var debugger = await initDebugger(isolate); |
90 var loc = | 87 var loc = await DebuggerLocation.parse( |
91 await DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo.missing'); | 88 debugger, 'DebuggerLocationTestFoo.missing'); |
92 expect(loc.valid, isFalse); | 89 expect(loc.valid, isFalse); |
93 expect(loc.toString(), equals( | 90 expect( |
94 'invalid source location ' | 91 loc.toString(), |
95 '(Function \'DebuggerLocationTestFoo.missing\' not found)')); | 92 equals('invalid source location ' |
96 }, | 93 '(Function \'DebuggerLocationTestFoo.missing\' not found)')); |
| 94 }, |
97 | 95 |
98 // Complete function + script | 96 // Complete function + script |
99 (Isolate isolate) async { | 97 (Isolate isolate) async { |
100 var debugger = await initDebugger(isolate); | 98 var debugger = await initDebugger(isolate); |
101 var completions = await DebuggerLocation.complete(debugger, 'debugger_loc'); | 99 var completions = await DebuggerLocation.complete(debugger, 'debugger_loc'); |
102 expect(completions.toString(), equals( | 100 expect( |
103 '[debugger_location_dummy_function,' | 101 completions.toString(), |
104 ' debugger_location.dart:,' | 102 equals('[debugger_location_dummy_function,' |
105 ' debugger_location_second_test.dart:]')); | 103 ' debugger_location.dart:,' |
106 }, | 104 ' debugger_location_second_test.dart:]')); |
| 105 }, |
107 | 106 |
108 // Complete class | 107 // Complete class |
109 (Isolate isolate) async { | 108 (Isolate isolate) async { |
110 var debugger = await initDebugger(isolate); | 109 var debugger = await initDebugger(isolate); |
111 var completions = | 110 var completions = |
112 await DebuggerLocation.complete(debugger, 'DebuggerLocationTe'); | 111 await DebuggerLocation.complete(debugger, 'DebuggerLocationTe'); |
113 expect(completions.toString(), equals( | 112 expect( |
114 '[DebuggerLocationTestBar,' | 113 completions.toString(), |
115 ' DebuggerLocationTestFoo]')); | 114 equals('[DebuggerLocationTestBar,' |
116 }, | 115 ' DebuggerLocationTestFoo]')); |
| 116 }, |
117 | 117 |
118 // No completions: unqualified name | 118 // No completions: unqualified name |
119 (Isolate isolate) async { | 119 (Isolate isolate) async { |
120 var debugger = await initDebugger(isolate); | 120 var debugger = await initDebugger(isolate); |
121 var completions = | 121 var completions = |
122 await DebuggerLocation.complete(debugger, 'debugger_locXYZZY'); | 122 await DebuggerLocation.complete(debugger, 'debugger_locXYZZY'); |
123 expect(completions.toString(), equals('[]')); | 123 expect(completions.toString(), equals('[]')); |
124 }, | 124 }, |
125 | 125 |
126 // Complete method | 126 // Complete method |
127 (Isolate isolate) async { | 127 (Isolate isolate) async { |
128 var debugger = await initDebugger(isolate); | 128 var debugger = await initDebugger(isolate); |
129 var completions = | 129 var completions = |
130 await DebuggerLocation.complete(debugger, 'DebuggerLocationTestFoo.m'); | 130 await DebuggerLocation.complete(debugger, 'DebuggerLocationTestFoo.m'); |
131 expect(completions.toString(), equals( | 131 expect( |
132 '[DebuggerLocationTestFoo.madness,' | 132 completions.toString(), |
133 ' DebuggerLocationTestFoo.method]')); | 133 equals('[DebuggerLocationTestFoo.madness,' |
134 }, | 134 ' DebuggerLocationTestFoo.method]')); |
| 135 }, |
135 | 136 |
136 // No completions: qualified name | 137 // No completions: qualified name |
137 (Isolate isolate) async { | 138 (Isolate isolate) async { |
138 var debugger = await initDebugger(isolate); | 139 var debugger = await initDebugger(isolate); |
139 var completions = | 140 var completions = |
140 await DebuggerLocation.complete(debugger, 'DebuggerLocationTestFoo.q'); | 141 await DebuggerLocation.complete(debugger, 'DebuggerLocationTestFoo.q'); |
141 expect(completions.toString(), equals('[]')); | 142 expect(completions.toString(), equals('[]')); |
142 }, | 143 }, |
143 | 144 |
144 // Complete script | 145 // Complete script |
145 (Isolate isolate) async { | 146 (Isolate isolate) async { |
146 var debugger = await initDebugger(isolate); | 147 var debugger = await initDebugger(isolate); |
147 var completions = | 148 var completions = await DebuggerLocation.complete( |
148 await DebuggerLocation.complete(debugger, 'debugger_location_second_te'); | 149 debugger, 'debugger_location_second_te'); |
149 expect(completions.toString(), equals( | 150 expect(completions.toString(), |
150 '[debugger_location_second_test.dart:]')); | 151 equals('[debugger_location_second_test.dart:]')); |
151 }, | 152 }, |
152 | 153 |
153 // Complete script:line | 154 // Complete script:line |
154 (Isolate isolate) async { | 155 (Isolate isolate) async { |
155 var debugger = await initDebugger(isolate); | 156 var debugger = await initDebugger(isolate); |
156 var completions = | 157 var completions = await DebuggerLocation.complete( |
157 await DebuggerLocation.complete(debugger, | 158 debugger, 'debugger_location_second_test.dart:11'); |
158 'debugger_location_second_test.dart:11'); | 159 expect( |
159 expect(completions.toString(), equals( | 160 completions.toString(), |
160 '[debugger_location_second_test.dart:${LINE_B + 0} ,' | 161 equals('[debugger_location_second_test.dart:${LINE_B + 0} ,' |
161 ' debugger_location_second_test.dart:${LINE_B + 0}:,' | 162 ' debugger_location_second_test.dart:${LINE_B + 0}:,' |
162 ' debugger_location_second_test.dart:${LINE_B + 1} ,' | 163 ' debugger_location_second_test.dart:${LINE_B + 1} ,' |
163 ' debugger_location_second_test.dart:${LINE_B + 1}:,' | 164 ' debugger_location_second_test.dart:${LINE_B + 1}:,' |
164 ' debugger_location_second_test.dart:${LINE_B + 2} ,' | 165 ' debugger_location_second_test.dart:${LINE_B + 2} ,' |
165 ' debugger_location_second_test.dart:${LINE_B + 2}:,' | 166 ' debugger_location_second_test.dart:${LINE_B + 2}:,' |
166 ' debugger_location_second_test.dart:${LINE_B + 3} ,' | 167 ' debugger_location_second_test.dart:${LINE_B + 3} ,' |
167 ' debugger_location_second_test.dart:${LINE_B + 3}:,' | 168 ' debugger_location_second_test.dart:${LINE_B + 3}:,' |
168 ' debugger_location_second_test.dart:${LINE_B + 4} ,' | 169 ' debugger_location_second_test.dart:${LINE_B + 4} ,' |
169 ' debugger_location_second_test.dart:${LINE_B + 4}:,' | 170 ' debugger_location_second_test.dart:${LINE_B + 4}:,' |
170 ' debugger_location_second_test.dart:${LINE_B + 5} ,' | 171 ' debugger_location_second_test.dart:${LINE_B + 5} ,' |
171 ' debugger_location_second_test.dart:${LINE_B + 5}:,' | 172 ' debugger_location_second_test.dart:${LINE_B + 5}:,' |
172 ' debugger_location_second_test.dart:${LINE_B + 6} ,' | 173 ' debugger_location_second_test.dart:${LINE_B + 6} ,' |
173 ' debugger_location_second_test.dart:${LINE_B + 6}:,' | 174 ' debugger_location_second_test.dart:${LINE_B + 6}:,' |
174 ' debugger_location_second_test.dart:${LINE_B + 9} ,' | 175 ' debugger_location_second_test.dart:${LINE_B + 9} ,' |
175 ' debugger_location_second_test.dart:${LINE_B + 9}:]')); | 176 ' debugger_location_second_test.dart:${LINE_B + 9}:]')); |
176 }, | 177 }, |
177 | 178 |
178 // Complete script:line:col | 179 // Complete script:line:col |
179 (Isolate isolate) async { | 180 (Isolate isolate) async { |
180 var debugger = await initDebugger(isolate); | 181 var debugger = await initDebugger(isolate); |
181 var completions = | 182 var completions = await DebuggerLocation.complete( |
182 await DebuggerLocation.complete( | 183 debugger, 'debugger_location_second_test.dart:$LINE_C:2'); |
183 debugger, | 184 expect( |
184 'debugger_location_second_test.dart:$LINE_C:2'); | 185 completions.toString(), |
185 expect(completions.toString(), equals( | 186 equals('[debugger_location_second_test.dart:$LINE_C:2 ,' |
186 '[debugger_location_second_test.dart:$LINE_C:2 ,' | 187 ' debugger_location_second_test.dart:$LINE_C:20 ,' |
187 ' debugger_location_second_test.dart:$LINE_C:20 ,' | 188 ' debugger_location_second_test.dart:$LINE_C:21 ,' |
188 ' debugger_location_second_test.dart:$LINE_C:21 ,' | 189 ' debugger_location_second_test.dart:$LINE_C:22 ,' |
189 ' debugger_location_second_test.dart:$LINE_C:22 ,' | 190 ' debugger_location_second_test.dart:$LINE_C:23 ,' |
190 ' debugger_location_second_test.dart:$LINE_C:23 ,' | 191 ' debugger_location_second_test.dart:$LINE_C:24 ]')); |
191 ' debugger_location_second_test.dart:$LINE_C:24 ]')); | 192 }, |
192 }, | |
193 | 193 |
194 // Complete without the script name. | 194 // Complete without the script name. |
195 (Isolate isolate) async { | 195 (Isolate isolate) async { |
196 var debugger = await initDebugger(isolate); | 196 var debugger = await initDebugger(isolate); |
197 var completions = await DebuggerLocation.complete(debugger, '$LINE_C:2'); | 197 var completions = await DebuggerLocation.complete(debugger, '$LINE_C:2'); |
198 expect(completions.toString(), equals( | 198 expect( |
199 '[debugger_location_second_test.dart:$LINE_C:2 ,' | 199 completions.toString(), |
200 ' debugger_location_second_test.dart:$LINE_C:20 ,' | 200 equals('[debugger_location_second_test.dart:$LINE_C:2 ,' |
201 ' debugger_location_second_test.dart:$LINE_C:21 ,' | 201 ' debugger_location_second_test.dart:$LINE_C:20 ,' |
202 ' debugger_location_second_test.dart:$LINE_C:22 ,' | 202 ' debugger_location_second_test.dart:$LINE_C:21 ,' |
203 ' debugger_location_second_test.dart:$LINE_C:23 ,' | 203 ' debugger_location_second_test.dart:$LINE_C:22 ,' |
204 ' debugger_location_second_test.dart:$LINE_C:24 ]')); | 204 ' debugger_location_second_test.dart:$LINE_C:23 ,' |
205 }, | 205 ' debugger_location_second_test.dart:$LINE_C:24 ]')); |
206 | 206 }, |
207 ]; | 207 ]; |
208 | 208 |
209 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); | 209 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); |
OLD | NEW |