| 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 | 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:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 import 'test_helper.dart'; | 8 import 'test_helper.dart'; |
| 9 import 'dart:async'; | |
| 10 import 'dart:developer'; | 9 import 'dart:developer'; |
| 11 | 10 |
| 12 testFunction() { | 11 testFunction() { |
| 13 debugger(); | 12 debugger(); |
| 14 var a; | 13 var a; |
| 15 try { | 14 try { |
| 16 var b; | 15 var b; |
| 17 try { | 16 try { |
| 18 for (int i = 0; i < 10; i++) { | 17 for (int i = 0; i < 10; i++) { |
| 19 var x = () => i + a + b; | 18 var x = () => i + a + b; |
| 20 return x; // line 20 | 19 return x; // line 19 |
| 21 } | 20 } |
| 22 } finally { | 21 } finally { |
| 23 b = 10; // line 23 | 22 b = 10; // line 22 |
| 24 } | 23 } |
| 25 } finally { | 24 } finally { |
| 26 a = 1; // line 26 | 25 a = 1; // line 25 |
| 27 } | 26 } |
| 28 } | 27 } |
| 29 | 28 |
| 30 testMain() { | 29 testMain() { |
| 31 var f = testFunction(); | 30 var f = testFunction(); |
| 32 expect(f(), equals(11)); | 31 expect(f(), equals(11)); |
| 33 } | 32 } |
| 34 | 33 |
| 35 var tests = [ | 34 var tests = [ |
| 36 | 35 |
| 37 hasStoppedAtBreakpoint, | 36 hasStoppedAtBreakpoint, |
| 38 | 37 |
| 39 // Add breakpoint | 38 // Add breakpoint |
| 40 (Isolate isolate) async { | 39 (Isolate isolate) async { |
| 41 await isolate.rootLibrary.load(); | 40 await isolate.rootLibrary.load(); |
| 42 | 41 |
| 43 var script = isolate.rootLibrary.scripts[0]; | 42 var script = isolate.rootLibrary.scripts[0]; |
| 44 await script.load(); | 43 await script.load(); |
| 45 | 44 |
| 46 // Add 3 breakpoints. | 45 // Add 3 breakpoints. |
| 47 { | 46 { |
| 48 var result = await isolate.addBreakpoint(script, 20); | 47 var result = await isolate.addBreakpoint(script, 19); |
| 49 expect(result is Breakpoint, isTrue); | 48 expect(result is Breakpoint, isTrue); |
| 50 Breakpoint bpt = result; | 49 Breakpoint bpt = result; |
| 51 expect(bpt.type, equals('Breakpoint')); | 50 expect(bpt.type, equals('Breakpoint')); |
| 52 expect(bpt.location.script.id, equals(script.id)); | 51 expect(bpt.location.script.id, equals(script.id)); |
| 53 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), equals(20)); | 52 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), equals(19)); |
| 54 expect(isolate.breakpoints.length, equals(1)); | 53 expect(isolate.breakpoints.length, equals(1)); |
| 55 } | 54 } |
| 56 | 55 |
| 57 { | 56 { |
| 58 var result = await isolate.addBreakpoint(script, 23); | 57 var result = await isolate.addBreakpoint(script, 22); |
| 59 expect(result is Breakpoint, isTrue); | 58 expect(result is Breakpoint, isTrue); |
| 60 Breakpoint bpt = result; | 59 Breakpoint bpt = result; |
| 61 expect(bpt.type, equals('Breakpoint')); | 60 expect(bpt.type, equals('Breakpoint')); |
| 62 expect(bpt.location.script.id, equals(script.id)); | 61 expect(bpt.location.script.id, equals(script.id)); |
| 63 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), equals(23)); | 62 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), equals(22)); |
| 64 expect(isolate.breakpoints.length, equals(2)); | 63 expect(isolate.breakpoints.length, equals(2)); |
| 65 } | 64 } |
| 66 | 65 |
| 67 { | 66 { |
| 68 var result = await isolate.addBreakpoint(script, 26); | 67 var result = await isolate.addBreakpoint(script, 25); |
| 69 expect(result is Breakpoint, isTrue); | 68 expect(result is Breakpoint, isTrue); |
| 70 Breakpoint bpt = result; | 69 Breakpoint bpt = result; |
| 71 expect(bpt.type, equals('Breakpoint')); | 70 expect(bpt.type, equals('Breakpoint')); |
| 72 expect(bpt.location.script.id, equals(script.id)); | 71 expect(bpt.location.script.id, equals(script.id)); |
| 73 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), equals(26)); | 72 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), equals(25)); |
| 74 expect(isolate.breakpoints.length, equals(3)); | 73 expect(isolate.breakpoints.length, equals(3)); |
| 75 } | 74 } |
| 76 | 75 |
| 77 // Wait for breakpoint events. | 76 // Wait for breakpoint events. |
| 78 }, | 77 }, |
| 79 | 78 |
| 80 resumeIsolate, | 79 resumeIsolate, |
| 81 | 80 |
| 82 hasStoppedAtBreakpoint, | 81 hasStoppedAtBreakpoint, |
| 83 | 82 |
| 84 // We are at the breakpoint on line 20. | 83 // We are at the breakpoint on line 19. |
| 85 (Isolate isolate) async { | 84 (Isolate isolate) async { |
| 86 ServiceMap stack = await isolate.getStack(); | 85 ServiceMap stack = await isolate.getStack(); |
| 87 expect(stack.type, equals('Stack')); | 86 expect(stack.type, equals('Stack')); |
| 88 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 87 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
| 89 | 88 |
| 90 Script script = stack['frames'][0].location.script; | 89 Script script = stack['frames'][0].location.script; |
| 91 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), equals(20)); | 90 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), equals(19)); |
| 92 }, | 91 }, |
| 93 | 92 |
| 94 resumeIsolate, | 93 resumeIsolate, |
| 95 | 94 |
| 96 hasStoppedAtBreakpoint, | 95 hasStoppedAtBreakpoint, |
| 97 | 96 |
| 98 // We are at the breakpoint on line 23. | 97 // We are at the breakpoint on line 22. |
| 99 (Isolate isolate) async { | 98 (Isolate isolate) async { |
| 100 ServiceMap stack = await isolate.getStack(); | 99 ServiceMap stack = await isolate.getStack(); |
| 101 expect(stack.type, equals('Stack')); | 100 expect(stack.type, equals('Stack')); |
| 102 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 101 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
| 103 | 102 |
| 104 Script script = stack['frames'][0].location.script; | 103 Script script = stack['frames'][0].location.script; |
| 105 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), equals(23)); | 104 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), equals(22)); |
| 106 }, | 105 }, |
| 107 | 106 |
| 108 resumeIsolate, | 107 resumeIsolate, |
| 109 | 108 |
| 110 hasStoppedAtBreakpoint, | 109 hasStoppedAtBreakpoint, |
| 111 | 110 |
| 112 // We are at the breakpoint on line 26. | 111 // We are at the breakpoint on line 25. |
| 113 (Isolate isolate) async { | 112 (Isolate isolate) async { |
| 114 ServiceMap stack = await isolate.getStack(); | 113 ServiceMap stack = await isolate.getStack(); |
| 115 expect(stack.type, equals('Stack')); | 114 expect(stack.type, equals('Stack')); |
| 116 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 115 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
| 117 | 116 |
| 118 Script script = stack['frames'][0].location.script; | 117 Script script = stack['frames'][0].location.script; |
| 119 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), equals(26)); | 118 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), equals(25)); |
| 120 }, | 119 }, |
| 121 | 120 |
| 122 resumeIsolate, | 121 resumeIsolate, |
| 123 | 122 |
| 124 ]; | 123 ]; |
| 125 | 124 |
| 126 main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain); | 125 main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain); |
| OLD | NEW |