| 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 'test_helper.dart'; | 8 import 'test_helper.dart'; |
| 9 import 'service_test_common.dart'; |
| 9 import 'dart:developer'; | 10 import 'dart:developer'; |
| 10 | 11 |
| 12 const int LINE_A = 20; |
| 13 const int LINE_B = 38; |
| 14 const int LINE_C = 136; |
| 15 |
| 11 int globalVar = 100; | 16 int globalVar = 100; |
| 12 | 17 |
| 13 class MyClass { | 18 class MyClass { |
| 14 static void myFunction(int value) { | 19 static void myFunction(int value) { |
| 15 if (value < 0) { | 20 if (value < 0) { // Line A. |
| 16 print("negative"); | 21 print("negative"); |
| 17 } else { | 22 } else { |
| 18 print("positive"); | 23 print("positive"); |
| 19 } | 24 } |
| 20 debugger(); | 25 debugger(); |
| 21 } | 26 } |
| 22 | 27 |
| 23 static void otherFunction(int value) { | 28 static void otherFunction(int value) { |
| 24 if (value < 0) { | 29 if (value < 0) { |
| 25 print("otherFunction <"); | 30 print("otherFunction <"); |
| 26 } else { | 31 } else { |
| 27 print("otherFunction >="); | 32 print("otherFunction >="); |
| 28 } | 33 } |
| 29 } | 34 } |
| 30 } | 35 } |
| 31 | 36 |
| 32 void testFunction() { | 37 void testFunction() { |
| 33 MyClass.otherFunction(-100); | 38 MyClass.otherFunction(-100); // Line B. |
| 34 MyClass.myFunction(10000); | 39 MyClass.myFunction(10000); |
| 35 } | 40 } |
| 36 | 41 |
| 37 var tests = [ | 42 var tests = [ |
| 38 | 43 |
| 39 hasStoppedAtBreakpoint, | 44 hasStoppedAtBreakpoint, |
| 40 | 45 |
| 41 // Get coverage for function, class, library, script, and isolate. | 46 // Get coverage for function, class, library, script, and isolate. |
| 42 (Isolate isolate) async { | 47 (Isolate isolate) async { |
| 43 var stack = await isolate.getStack(); | 48 var stack = await isolate.getStack(); |
| 44 | 49 |
| 45 // Make sure we are in the right place. | 50 // Make sure we are in the right place. |
| 46 expect(stack.type, equals('Stack')); | 51 expect(stack.type, equals('Stack')); |
| 47 expect(stack['frames'].length, greaterThanOrEqualTo(2)); | 52 expect(stack['frames'].length, greaterThanOrEqualTo(2)); |
| 48 expect(stack['frames'][0].function.name, equals('myFunction')); | 53 expect(stack['frames'][0].function.name, equals('myFunction')); |
| 49 expect(stack['frames'][0].function.dartOwner.name, equals('MyClass')); | 54 expect(stack['frames'][0].function.dartOwner.name, equals('MyClass')); |
| 50 | 55 |
| 51 var lib = isolate.rootLibrary; | 56 var lib = isolate.rootLibrary; |
| 52 var func = stack['frames'][0].function; | 57 var func = stack['frames'][0].function; |
| 53 expect(func.name, equals('myFunction')); | 58 expect(func.name, equals('myFunction')); |
| 54 var cls = func.dartOwner; | 59 var cls = func.dartOwner; |
| 55 expect(cls.name, equals('MyClass')); | 60 expect(cls.name, equals('MyClass')); |
| 56 | 61 |
| 57 // Function | 62 // Function |
| 58 var coverage = await isolate.invokeRpcNoUpgrade('_getCoverage', | 63 var coverage = await isolate.invokeRpcNoUpgrade('_getCoverage', |
| 59 { 'targetId': func.id }); | 64 { 'targetId': func.id }); |
| 60 expect(coverage['type'], equals('CodeCoverage')); | 65 expect(coverage['type'], equals('CodeCoverage')); |
| 61 expect(coverage['coverage'].length, equals(1)); | 66 expect(coverage['coverage'].length, equals(1)); |
| 62 expect(coverage['coverage'][0]['hits'], | 67 expect(coverage['coverage'][0]['hits'], |
| 63 equals([15, 1, 16, 0, 18, 1, 20, 1])); | 68 equals([LINE_A, 1, |
| 69 LINE_A + 1, 0, |
| 70 LINE_A + 3, 1, |
| 71 LINE_A + 5, 1])); |
| 64 | 72 |
| 65 // Class | 73 // Class |
| 66 coverage = await isolate.invokeRpcNoUpgrade('_getCoverage', | 74 coverage = await isolate.invokeRpcNoUpgrade('_getCoverage', |
| 67 { 'targetId': cls.id }); | 75 { 'targetId': cls.id }); |
| 68 expect(coverage['type'], equals('CodeCoverage')); | 76 expect(coverage['type'], equals('CodeCoverage')); |
| 69 expect(coverage['coverage'].length, equals(1)); | 77 expect(coverage['coverage'].length, equals(1)); |
| 70 expect(coverage['coverage'][0]['hits'], | 78 expect(coverage['coverage'][0]['hits'], |
| 71 equals([15, 1, 16, 0, 18, 1, 20, 1, | 79 equals([LINE_A, 1, |
| 72 24, 1, 25, 1, 27, 0, 13, 0])); | 80 LINE_A + 1, 0, |
| 81 LINE_A + 3, 1, |
| 82 LINE_A + 5, 1, |
| 83 LINE_A + 9, 1, |
| 84 LINE_A + 10, 1, |
| 85 LINE_A + 12, 0, |
| 86 LINE_A - 2, 0])); |
| 73 | 87 |
| 74 // Library | 88 // Library |
| 75 coverage = await isolate.invokeRpcNoUpgrade('_getCoverage', | 89 coverage = await isolate.invokeRpcNoUpgrade('_getCoverage', |
| 76 { 'targetId': lib.id }); | 90 { 'targetId': lib.id }); |
| 77 expect(coverage['type'], equals('CodeCoverage')); | 91 expect(coverage['type'], equals('CodeCoverage')); |
| 78 expect(coverage['coverage'].length, equals(4)); | 92 expect(coverage['coverage'].length, equals(4)); |
| 79 expect(coverage['coverage'][0]['hits'], | 93 expect(coverage['coverage'][0]['hits'], |
| 80 equals([15, 1, 16, 0, 18, 1, 20, 1, | 94 equals([LINE_A, 1, |
| 81 24, 1, 25, 1, 27, 0, 13, 0])); | 95 LINE_A + 1, 0, |
| 96 LINE_A + 3, 1, |
| 97 LINE_A + 5, 1, |
| 98 LINE_A + 9, 1, |
| 99 LINE_A + 10, 1, |
| 100 LINE_A + 12, 0, |
| 101 LINE_A - 2, 0])); |
| 82 expect(coverage['coverage'][1]['hits'], | 102 expect(coverage['coverage'][1]['hits'], |
| 83 equals([33, 1, 34, 1, 106, 2])); | 103 equals([LINE_B, 1, |
| 104 LINE_B + 1, 1, |
| 105 LINE_C, 2])); |
| 84 | 106 |
| 85 // Script | 107 // Script |
| 86 await cls.load(); | 108 await cls.load(); |
| 87 coverage = await isolate.invokeRpcNoUpgrade('_getCoverage', | 109 coverage = await isolate.invokeRpcNoUpgrade('_getCoverage', |
| 88 { 'targetId': cls.location.script.id }); | 110 { 'targetId': cls.location.script.id }); |
| 89 expect(coverage['type'], equals('CodeCoverage')); | 111 expect(coverage['type'], equals('CodeCoverage')); |
| 90 expect(coverage['coverage'].length, equals(4)); | 112 expect(coverage['coverage'].length, equals(4)); |
| 91 expect(coverage['coverage'][0]['hits'], | 113 expect(coverage['coverage'][0]['hits'], |
| 92 equals([15, 1, 16, 0, 18, 1, 20, 1, | 114 equals([LINE_A, 1, |
| 93 24, 1, 25, 1, 27, 0, 13, 0])); | 115 LINE_A + 1, 0, |
| 116 LINE_A + 3, 1, |
| 117 LINE_A + 5, 1, |
| 118 LINE_A + 9, 1, |
| 119 LINE_A + 10, 1, |
| 120 LINE_A + 12, 0, |
| 121 LINE_A - 2, 0])); |
| 94 expect(coverage['coverage'][1]['hits'], | 122 expect(coverage['coverage'][1]['hits'], |
| 95 equals([33, 1, 34, 1, 106, 2])); | 123 equals([LINE_B, 1, |
| 124 LINE_B + 1, 1, |
| 125 LINE_C, 2])); |
| 96 | 126 |
| 97 // Isolate | 127 // Isolate |
| 98 coverage = await isolate.invokeRpcNoUpgrade('_getCoverage', {}); | 128 coverage = await isolate.invokeRpcNoUpgrade('_getCoverage', {}); |
| 99 print('Done processing _getCoverage for full isolate'); | 129 print('Done processing _getCoverage for full isolate'); |
| 100 expect(coverage['type'], equals('CodeCoverage')); | 130 expect(coverage['type'], equals('CodeCoverage')); |
| 101 expect(coverage['coverage'].length, greaterThan(100)); | 131 expect(coverage['coverage'].length, greaterThan(100)); |
| 102 }, | 132 }, |
| 103 | 133 |
| 104 ]; | 134 ]; |
| 105 | 135 |
| 106 main(args) => runIsolateTests(args, tests, | 136 main(args) => runIsolateTests(args, tests, // Line C. |
| 107 testeeConcurrent: testFunction, | 137 testeeConcurrent: testFunction, |
| 108 trace_service: true); | 138 trace_service: true); |
| OLD | NEW |