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: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 = 112; | 15 const int LINE_B = 112; |
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 // Parse '' => current position | 59 // Parse '' => current position |
63 (Isolate isolate) async { | 60 (Isolate isolate) async { |
64 var debugger = await initDebugger(isolate); | 61 var debugger = await initDebugger(isolate); |
65 var loc = await DebuggerLocation.parse(debugger, ''); | 62 var loc = await DebuggerLocation.parse(debugger, ''); |
66 expect(loc.valid, isTrue); | 63 expect(loc.valid, isTrue); |
67 expect(loc.toString(), equals('debugger_location_test.dart:$LINE_A:5')); | 64 expect(loc.toString(), equals('debugger_location_test.dart:$LINE_A:5')); |
68 }, | 65 }, |
69 | 66 |
70 // Parse line | 67 // Parse line |
71 (Isolate isolate) async { | 68 (Isolate isolate) async { |
72 var debugger = await initDebugger(isolate); | 69 var debugger = await initDebugger(isolate); |
73 var loc = await DebuggerLocation.parse(debugger, '18'); | 70 var loc = await DebuggerLocation.parse(debugger, '18'); |
74 expect(loc.valid, isTrue); | 71 expect(loc.valid, isTrue); |
75 expect(loc.toString(), equals('debugger_location_test.dart:18')); | 72 expect(loc.toString(), equals('debugger_location_test.dart:18')); |
76 }, | 73 }, |
77 | 74 |
78 // Parse line + col | 75 // Parse line + col |
79 (Isolate isolate) async { | 76 (Isolate isolate) async { |
80 var debugger = await initDebugger(isolate); | 77 var debugger = await initDebugger(isolate); |
81 var loc = await DebuggerLocation.parse(debugger, '16:11'); | 78 var loc = await DebuggerLocation.parse(debugger, '16:11'); |
82 expect(loc.valid, isTrue); | 79 expect(loc.valid, isTrue); |
83 expect(loc.toString(), equals('debugger_location_test.dart:16:11')); | 80 expect(loc.toString(), equals('debugger_location_test.dart:16:11')); |
84 }, | 81 }, |
85 | 82 |
86 // Parse script + line | 83 // Parse script + line |
87 (Isolate isolate) async { | 84 (Isolate isolate) async { |
88 var debugger = await initDebugger(isolate); | 85 var debugger = await initDebugger(isolate); |
89 var loc = await DebuggerLocation.parse(debugger, 'unittest.dart:15'); | 86 var loc = await DebuggerLocation.parse(debugger, 'unittest.dart:15'); |
90 expect(loc.valid, isTrue); | 87 expect(loc.valid, isTrue); |
91 expect(loc.toString(), equals('unittest.dart:15')); | 88 expect(loc.toString(), equals('unittest.dart:15')); |
92 }, | 89 }, |
93 | 90 |
94 // Parse script + line + col | 91 // Parse script + line + col |
95 (Isolate isolate) async { | 92 (Isolate isolate) async { |
96 var debugger = await initDebugger(isolate); | 93 var debugger = await initDebugger(isolate); |
97 var loc = await DebuggerLocation.parse(debugger, 'unittest.dart:15:10'); | 94 var loc = await DebuggerLocation.parse(debugger, 'unittest.dart:15:10'); |
98 expect(loc.valid, isTrue); | 95 expect(loc.valid, isTrue); |
99 expect(loc.toString(), equals('unittest.dart:15:10')); | 96 expect(loc.toString(), equals('unittest.dart:15:10')); |
100 }, | 97 }, |
101 | 98 |
102 // Parse bad script | 99 // Parse bad script |
103 (Isolate isolate) async { | 100 (Isolate isolate) async { |
104 var debugger = await initDebugger(isolate); | 101 var debugger = await initDebugger(isolate); |
105 var loc = await DebuggerLocation.parse(debugger, 'bad.dart:15'); | 102 var loc = await DebuggerLocation.parse(debugger, 'bad.dart:15'); |
106 expect(loc.valid, isFalse); | 103 expect(loc.valid, isFalse); |
107 expect(loc.toString(), equals( | 104 expect(loc.toString(), |
108 'invalid source location (Script \'bad.dart\' not found)')); | 105 equals('invalid source location (Script \'bad.dart\' not found)')); |
109 }, | 106 }, |
110 | 107 |
111 // Parse function | 108 // Parse function |
112 (Isolate isolate) async { | 109 (Isolate isolate) async { |
113 var debugger = await initDebugger(isolate); | 110 var debugger = await initDebugger(isolate); |
114 var loc = await DebuggerLocation.parse(debugger, 'testFunction'); | 111 var loc = await DebuggerLocation.parse(debugger, 'testFunction'); |
115 expect(loc.valid, isTrue); | 112 expect(loc.valid, isTrue); |
116 expect(loc.toString(), equals('testFunction')); | 113 expect(loc.toString(), equals('testFunction')); |
117 }, | 114 }, |
118 | 115 |
119 // Parse bad function | 116 // Parse bad function |
120 (Isolate isolate) async { | 117 (Isolate isolate) async { |
121 var debugger = await initDebugger(isolate); | 118 var debugger = await initDebugger(isolate); |
122 var loc = await DebuggerLocation.parse(debugger, 'doesNotReallyExist'); | 119 var loc = await DebuggerLocation.parse(debugger, 'doesNotReallyExist'); |
123 expect(loc.valid, isFalse); | 120 expect(loc.valid, isFalse); |
124 expect(loc.toString(), equals( | 121 expect( |
125 'invalid source location (Function \'doesNotReallyExist\' not found)')); | 122 loc.toString(), |
126 }, | 123 equals( |
| 124 'invalid source location (Function \'doesNotReallyExist\' not found)
')); |
| 125 }, |
127 | 126 |
128 // Parse constructor | 127 // Parse constructor |
129 (Isolate isolate) async { | 128 (Isolate isolate) async { |
130 var debugger = await initDebugger(isolate); | 129 var debugger = await initDebugger(isolate); |
131 var loc = await DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo'); | 130 var loc = await DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo'); |
132 expect(loc.valid, isTrue); | 131 expect(loc.valid, isTrue); |
133 // TODO(turnidge): Printing a constructor currently adds | 132 // TODO(turnidge): Printing a constructor currently adds |
134 // another class qualifier at the front. Do we want to change | 133 // another class qualifier at the front. Do we want to change |
135 // this to be more consistent? | 134 // this to be more consistent? |
136 expect(loc.toString(), equals( | 135 expect(loc.toString(), |
137 'DebuggerLocationTestFoo.DebuggerLocationTestFoo')); | 136 equals('DebuggerLocationTestFoo.DebuggerLocationTestFoo')); |
138 }, | 137 }, |
139 | 138 |
140 // Parse named constructor | 139 // Parse named constructor |
141 (Isolate isolate) async { | 140 (Isolate isolate) async { |
142 var debugger = await initDebugger(isolate); | 141 var debugger = await initDebugger(isolate); |
143 var loc = | 142 var loc = |
144 await DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo.named'); | 143 await DebuggerLocation.parse(debugger, 'DebuggerLocationTestFoo.named'); |
145 expect(loc.valid, isTrue); | 144 expect(loc.valid, isTrue); |
146 // TODO(turnidge): Printing a constructor currently adds | 145 // TODO(turnidge): Printing a constructor currently adds |
147 // another class qualifier at the front. Do we want to change | 146 // another class qualifier at the front. Do we want to change |
148 // this to be more consistent? | 147 // this to be more consistent? |
149 expect(loc.toString(), equals( | 148 expect(loc.toString(), |
150 'DebuggerLocationTestFoo.DebuggerLocationTestFoo.named')); | 149 equals('DebuggerLocationTestFoo.DebuggerLocationTestFoo.named')); |
151 }, | 150 }, |
152 | |
153 ]; | 151 ]; |
154 | 152 |
155 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); | 153 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); |
OLD | NEW |