Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(713)

Unified Diff: test/source_report_test.dart

Issue 1929063002: pkg/vm_service_client: add getSourceReport to VMServiceReference (Closed) Base URL: https://github.com/dart-lang/vm_service_client.git@master
Patch Set: tweak Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« lib/src/source_report.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/source_report_test.dart
diff --git a/test/source_report_test.dart b/test/source_report_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1d8b90682469a8f211736fa4916ddc703acb57bf
--- /dev/null
+++ b/test/source_report_test.dart
@@ -0,0 +1,229 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:source_span/source_span.dart';
+import 'package:test/test.dart';
+import 'package:vm_service_client/vm_service_client.dart';
+
+import 'utils.dart';
+
+const _mainContent = r"""
+ print("one");
+ print("two");
+
+ if (false) {
+ print("three");
+ print("four");
+ }
+
+ Isolate.current.kill();
+""";
+
+void main() {
+ VMServiceClient client;
+ VMIsolateRef isolate;
+
+ tearDown(() {
+ if (client != null) client.close();
+ });
+
+ group('calling getSourceReport for a script with one range', () {
+ setUp(() async {
+ client = await runAndConnect(main: _mainContent);
+
+ isolate = (await client.getVM()).isolates.single;
+
+ await isolate.waitUntilPaused();
+ });
+
+ test("behaves correctly with options off", () async {
nweiz 2016/05/11 23:03:32 The bulk of this test case isn't about the lack of
kevmoo 2016/05/12 05:22:35 Done.
+ var report = await isolate.getSourceReport(
+ includeCoverageReport: false, includePossibleBreakpoints: false);
+
+ expect(report.ranges, hasLength(greaterThan(1)));
+
+ var range = report.ranges.singleWhere((range) =>
+ range.script.uri.toString().startsWith('data:application/dart'));
+
+ expect(range.compiled, isTrue);
+
+ var script = await range.script.load();
+
+ var runnableIsolate = await isolate.loadRunnable();
+
+ var rootLib = await runnableIsolate.rootLibrary.load();
+ var mainFunction = await rootLib.functions['main'].load();
+
+ var mainLocation = script.sourceSpan(mainFunction.location);
+
+ var startLocation = script.sourceLocation(range.location.token);
+ expect(startLocation, mainLocation.start);
+
+ var endLocation = script.sourceLocation(range.location.end);
+ expect(endLocation, mainLocation.end);
+
+ expect(range.hits, isNull);
+ expect(range.misses, isNull);
+ expect(range.possibleBreakpoints, isNull);
+ });
+
+ test("behaves correctly without breakpoints", () async {
nweiz 2016/05/11 23:03:32 This test case is primarily making assertions abou
kevmoo 2016/05/12 05:22:35 Done.
+ var report =
+ await isolate.getSourceReport(includePossibleBreakpoints: false);
+
+ var range = report.ranges.singleWhere((range) =>
+ range.script.uri.toString().startsWith('data:application/dart'));
+ expect(range.possibleBreakpoints, isNull);
+
+ var script = await range.script.load();
+
+ // represents the unique set of lines that are executed
nweiz 2016/05/11 23:03:31 https://www.dartlang.org/effective-dart/documentat
kevmoo 2016/05/12 05:22:35 Acknowledged.
+ var hitLines =
+ range.hits.map((token) => script.sourceLocation(token).line).toSet();
+ expect(hitLines, [6, 7, 8, 15, 17]);
+
+ // represents the unique set of lines that are not executed
+ var missedLines =
+ range.misses.map((token) => script.sourceLocation(token).line);
+ expect(missedLines, [11, 12]);
+ });
+
+ test("behaves correctly without coverage", () async {
+ var report = await isolate.getSourceReport(includeCoverageReport: false);
+
+ var range = report.ranges.singleWhere((range) =>
+ range.script.uri.toString().startsWith('data:application/dart'));
+
+ expect(range.hits, isNull);
+ expect(range.misses, isNull);
+
+ var script = await range.script.load();
+ expect(range.possibleBreakpoints, isNotEmpty);
+
+ // represents the unique set of lines that can have breakpoints
+ var breakPointLines = range.possibleBreakpoints
+ .map((token) => script.sourceLocation(token).line)
+ .toSet();
+ expect(breakPointLines, [4, 6, 7, 8, 11, 12, 15, 17]);
+ });
+
+ test("behaves correctly including coverage and breakpoints", () async {
+ var report = await isolate.getSourceReport(
+ includeCoverageReport: true, includePossibleBreakpoints: true);
+
+ var range = report.ranges.singleWhere((range) =>
+ range.script.uri.toString().startsWith('data:application/dart'));
+
+ expect(range.hits, isNotEmpty);
+ expect(range.misses, isNotEmpty);
+ expect(range.possibleBreakpoints, isNotEmpty);
+ });
+ });
+
+ group('a script with multiple ranges', () {
+ VMScript script;
+ VMLibrary rootLib;
+ VMSourceLocation mainLocation;
+ FileSpan mainFunctionSpan;
+ VMSourceLocation unusedFunction2Location;
+
+ setUp(() async {
+ client = await runAndConnect(
+ topLevel: r'''final unusedField = 5;
+
+int unusedFunction(a, b) {
+ return a + b;
+}
+
+void unusedFunction2(value) {
+ print(value);
+}''',
+ main: _mainContent);
+
+ isolate = (await client.getVM()).isolates.single;
+
+ await isolate.waitUntilPaused();
+
+ var runnableIsolate = await isolate.loadRunnable();
+ rootLib = await runnableIsolate.rootLibrary.load();
+ script = await rootLib.scripts.single.load();
+
+ var mainFunction = await rootLib.functions['main'].load();
+ mainLocation = mainFunction.location;
+ mainFunctionSpan = script.sourceSpan(mainLocation);
+
+ var unusedFunction2 = await rootLib.functions['unusedFunction2'].load();
+ unusedFunction2Location = unusedFunction2.location;
+ });
+
+ test("not force compiled", () async {
nweiz 2016/05/11 23:03:32 You didn't update this test name, or any others in
kevmoo 2016/05/12 05:22:35 Acknowledged.
+ var report = await script.getSourceReport(
+ includeCoverageReport: true, includePossibleBreakpoints: true);
nweiz 2016/05/11 23:03:31 You don't need to set these to true anymore, here
kevmoo 2016/05/12 05:22:35 Acknowledged.
+
+ expect(report.ranges, hasLength(3));
+
+ var firstRange = report.ranges.first;
+ expect(firstRange.compiled, isFalse);
+ expect(firstRange.hits, isNull);
+ expect(firstRange.misses, isNull);
+ expect(firstRange.possibleBreakpoints, isNull);
+
+ // TODO(kevmoo): use lessThan in matcher when
+ // https://github.com/dart-lang/matcher/issues/33 is fixed
+ expect(script.sourceSpan(firstRange.location).compareTo(mainFunctionSpan),
+ isNegative);
+
+ var lastRange = report.ranges.last;
+ expect(lastRange.compiled, isTrue);
+ expect(script.sourceSpan(lastRange.location), mainFunctionSpan);
nweiz 2016/05/11 23:03:31 "equals(mainFunctionSpan)" Also below
kevmoo 2016/05/12 05:22:35 Done.
+ });
+
+ test("force compiled", () async {
+ var report = await script.getSourceReport(
+ includeCoverageReport: true,
+ includePossibleBreakpoints: true,
+ forceCompile: true);
+
+ expect(report.ranges, hasLength(3));
+
+ var firstRange = report.ranges.first;
+ expect(firstRange.compiled, isTrue);
+
+ var secondRange = report.ranges.last;
+ expect(secondRange.compiled, isTrue);
+ });
+
+ test("with start set", () async {
+ var report = await script.getSourceReport(
+ includeCoverageReport: true,
+ includePossibleBreakpoints: true,
+ start: mainLocation.token);
+
+ expect(
+ script.sourceSpan(report.ranges.single.location), mainFunctionSpan);
+ });
+
+ test("with end set", () async {
+ var report = await script.getSourceReport(
+ includeCoverageReport: true,
+ includePossibleBreakpoints: true,
+ end: unusedFunction2Location.token);
+
+ expect(report.ranges, hasLength(2),
+ reason: 'Includes the range containing only unusedFunction2, main.');
+ });
+
+ test("with an empty token range", () async {
+ var report = await script.getSourceReport(
+ includeCoverageReport: true,
+ includePossibleBreakpoints: true,
+ start: unusedFunction2Location.token,
+ end: unusedFunction2Location.end);
+
+ expect(report.ranges, hasLength(1));
+ expect(script.sourceSpan(report.ranges.single.location),
+ script.sourceSpan(unusedFunction2Location));
+ });
+ });
+}
« lib/src/source_report.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698