|
| 1 | +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 | + |
| 5 | +import 'dart:developer'; |
| 6 | +import 'package:observatory/service_io.dart'; |
| 7 | +import 'package:unittest/unittest.dart'; |
| 8 | +import 'service_test_common.dart'; |
| 9 | +import 'test_helper.dart'; |
| 10 | + |
| 11 | +const int LINE = 14; |
| 12 | + |
| 13 | +class Bar { |
| 14 | + static const String field = "field"; // LINE |
| 15 | +} |
| 16 | + |
| 17 | +void testFunction() { |
| 18 | + debugger(); |
| 19 | +} |
| 20 | + |
| 21 | +var tests = <IsolateTest>[ |
| 22 | + hasStoppedAtBreakpoint, |
| 23 | + (Isolate isolate) async { |
| 24 | + var stack = await isolate.getStack(); |
| 25 | + |
| 26 | + // Make sure we are in the right place. |
| 27 | + expect(stack.type, 'Stack'); |
| 28 | + expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
| 29 | + expect(stack['frames'][0].function.name, 'testFunction'); |
| 30 | + |
| 31 | + var root = isolate.rootLibrary; |
| 32 | + await root.load(); |
| 33 | + Script script = root.scripts.first; |
| 34 | + await script.load(); |
| 35 | + |
| 36 | + var params = { |
| 37 | + 'reports': ['Coverage'], |
| 38 | + 'scriptId': script.id, |
| 39 | + 'forceCompile': true |
| 40 | + }; |
| 41 | + var report = await isolate.invokeRpcNoUpgrade('getSourceReport', params); |
| 42 | + List<dynamic> ranges = report['ranges']; |
| 43 | + |
| 44 | + int match = 0; |
| 45 | + for (var range in ranges) { |
| 46 | + for (int i in range["coverage"]["hits"]) { |
| 47 | + int line = script.tokenToLine(i); |
| 48 | + if (line == null) { |
| 49 | + throw FormatException('token ${i} was missing source location'); |
| 50 | + } |
| 51 | + // Check LINE. |
| 52 | + if (line == LINE) { |
| 53 | + match = (match | 1); |
| 54 | + } else if (line == LINE - 3) { |
| 55 | + // static const field LINE is defined at LINE - 3. |
| 56 | + match = (match | 2); |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + // Neither LINE nor Bar.field should be added into coverage. |
| 61 | + expect(match, 0); |
| 62 | + }, |
| 63 | + resumeIsolate |
| 64 | +]; |
| 65 | + |
| 66 | +main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); |
0 commit comments