| 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=--compile-all --error_on_bad_type --error_on_bad_override --checked |
| 4 | 5 |
| 5 import 'package:observatory/service_io.dart'; | 6 import 'package:observatory/service_io.dart'; |
| 6 import 'package:observatory/debugger.dart'; | 7 import 'package:observatory/debugger.dart'; |
| 7 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 8 import 'test_helper.dart'; | 9 import 'test_helper.dart'; |
| 9 import 'dart:async'; | 10 import 'dart:async'; |
| 10 | 11 |
| 11 void testFunction() { | 12 void testFunction() { |
| 12 int i = 0; | 13 int i = 0; |
| 13 while (true) { | 14 while (true) { |
| 14 if (++i % 100000000 == 0) { // line 14 | 15 if (++i % 100000000 == 0) { // line 15 |
| 15 print(i); | 16 print(i); |
| 16 } | 17 } |
| 17 } | 18 } |
| 18 } | 19 } |
| 19 | 20 |
| 20 class TestDebugger extends Debugger { | 21 class TestDebugger extends Debugger { |
| 21 TestDebugger(this.isolate, this.stack); | 22 TestDebugger(this.isolate, this.stack); |
| 22 | 23 |
| 23 Isolate isolate; | 24 Isolate isolate; |
| 24 ServiceMap stack; | 25 ServiceMap stack; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 42 } | 43 } |
| 43 | 44 |
| 44 Future<Debugger> initDebugger(Isolate isolate) { | 45 Future<Debugger> initDebugger(Isolate isolate) { |
| 45 return isolate.getStack().then((stack) { | 46 return isolate.getStack().then((stack) { |
| 46 return new TestDebugger(isolate, stack); | 47 return new TestDebugger(isolate, stack); |
| 47 }); | 48 }); |
| 48 } | 49 } |
| 49 | 50 |
| 50 var tests = [ | 51 var tests = [ |
| 51 | 52 |
| 52 // Bring the isolate to a breakpoint at line 14. | 53 // Bring the isolate to a breakpoint at line 15. |
| 53 (Isolate isolate) { | 54 (Isolate isolate) { |
| 54 return isolate.rootLib.load().then((_) { | 55 return isolate.rootLib.load().then((_) { |
| 55 // Listen for breakpoint event. | 56 // Listen for breakpoint event. |
| 56 Completer completer = new Completer(); | 57 Completer completer = new Completer(); |
| 57 isolate.vm.events.stream.listen((ServiceEvent event) { | 58 isolate.vm.events.stream.listen((ServiceEvent event) { |
| 58 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | 59 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
| 59 completer.complete(); | 60 completer.complete(); |
| 60 } | 61 } |
| 61 }); | 62 }); |
| 62 | 63 |
| 63 // Add the breakpoint. | 64 // Add the breakpoint. |
| 64 var script = isolate.rootLib.scripts[0]; | 65 var script = isolate.rootLib.scripts[0]; |
| 65 return isolate.addBreakpoint(script, 14).then((ServiceObject bpt) { | 66 return isolate.addBreakpoint(script, 15).then((ServiceObject bpt) { |
| 66 return completer.future; // Wait for breakpoint events. | 67 return completer.future; // Wait for breakpoint events. |
| 67 }); | 68 }); |
| 68 }); | 69 }); |
| 69 }, | 70 }, |
| 70 | 71 |
| 71 // Parse '' => current position | 72 // Parse '' => current position |
| 72 (Isolate isolate) { | 73 (Isolate isolate) { |
| 73 return initDebugger(isolate).then((debugger) { | 74 return initDebugger(isolate).then((debugger) { |
| 74 return SourceLocation.parse(debugger, '').then((SourceLocation loc) { | 75 return SourceLocation.parse(debugger, '').then((SourceLocation loc) { |
| 75 expect(loc.valid, isTrue); | 76 expect(loc.valid, isTrue); |
| 76 expect(loc.toString(), equals('source_location_test.dart:14')); | 77 expect(loc.toString(), equals('source_location_test.dart:15')); |
| 77 }); | 78 }); |
| 78 }); | 79 }); |
| 79 }, | 80 }, |
| 80 | 81 |
| 81 // Parse line | 82 // Parse line |
| 82 (Isolate isolate) { | 83 (Isolate isolate) { |
| 83 return initDebugger(isolate).then((debugger) { | 84 return initDebugger(isolate).then((debugger) { |
| 84 return SourceLocation.parse(debugger, '15').then((SourceLocation loc) { | 85 return SourceLocation.parse(debugger, '16').then((SourceLocation loc) { |
| 85 expect(loc.valid, isTrue); | 86 expect(loc.valid, isTrue); |
| 86 expect(loc.toString(), equals('source_location_test.dart:15')); | 87 expect(loc.toString(), equals('source_location_test.dart:16')); |
| 87 }); | 88 }); |
| 88 }); | 89 }); |
| 89 }, | 90 }, |
| 90 | 91 |
| 91 // Parse line + col | 92 // Parse line + col |
| 92 (Isolate isolate) { | 93 (Isolate isolate) { |
| 93 return initDebugger(isolate).then((debugger) { | 94 return initDebugger(isolate).then((debugger) { |
| 94 return SourceLocation.parse(debugger, '15:11').then((SourceLocation loc) { | 95 return SourceLocation.parse(debugger, '16:11').then((SourceLocation loc) { |
| 95 expect(loc.valid, isTrue); | 96 expect(loc.valid, isTrue); |
| 96 expect(loc.toString(), equals('source_location_test.dart:15:11')); | 97 expect(loc.toString(), equals('source_location_test.dart:16:11')); |
| 97 }); | 98 }); |
| 98 }); | 99 }); |
| 99 }, | 100 }, |
| 100 | 101 |
| 101 // Parse script + line | 102 // Parse script + line |
| 102 (Isolate isolate) { | 103 (Isolate isolate) { |
| 103 return initDebugger(isolate).then((debugger) { | 104 return initDebugger(isolate).then((debugger) { |
| 104 return SourceLocation.parse(debugger, 'unittest.dart:15') | 105 return SourceLocation.parse(debugger, 'unittest.dart:15') |
| 105 .then((SourceLocation loc) { | 106 .then((SourceLocation loc) { |
| 106 expect(loc.valid, isTrue); | 107 expect(loc.valid, isTrue); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 return SourceLocation.complete(debugger, 'SourceLocationTestFoo.q') | 271 return SourceLocation.complete(debugger, 'SourceLocationTestFoo.q') |
| 271 .then((List<String> completions) { | 272 .then((List<String> completions) { |
| 272 expect(completions.toString(), equals('[]')); | 273 expect(completions.toString(), equals('[]')); |
| 273 }); | 274 }); |
| 274 }); | 275 }); |
| 275 }, | 276 }, |
| 276 | 277 |
| 277 ]; | 278 ]; |
| 278 | 279 |
| 279 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); | 280 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); |
| OLD | NEW |