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