OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, 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 'package:source_span/source_span.dart'; | |
6 import 'package:test/test.dart'; | |
7 import 'package:vm_service_client/vm_service_client.dart'; | |
8 | |
9 import 'utils.dart'; | |
10 | |
11 const _mainContent = r""" | |
12 print("one"); | |
13 print("two"); | |
14 | |
15 if (false) { | |
16 print("three"); | |
17 print("four"); | |
18 } | |
19 | |
20 Isolate.current.kill(); | |
21 """; | |
22 | |
23 void main() { | |
24 VMServiceClient client; | |
25 VMIsolateRef isolate; | |
26 | |
27 tearDown(() { | |
28 if (client != null) client.close(); | |
29 }); | |
30 | |
31 group('calling getSourceReport for a script with one range', () { | |
32 setUp(() async { | |
33 client = await runAndConnect(main: _mainContent); | |
34 | |
35 isolate = (await client.getVM()).isolates.single; | |
36 | |
37 await isolate.waitUntilPaused(); | |
38 }); | |
39 | |
40 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.
| |
41 var report = await isolate.getSourceReport( | |
42 includeCoverageReport: false, includePossibleBreakpoints: false); | |
43 | |
44 expect(report.ranges, hasLength(greaterThan(1))); | |
45 | |
46 var range = report.ranges.singleWhere((range) => | |
47 range.script.uri.toString().startsWith('data:application/dart')); | |
48 | |
49 expect(range.compiled, isTrue); | |
50 | |
51 var script = await range.script.load(); | |
52 | |
53 var runnableIsolate = await isolate.loadRunnable(); | |
54 | |
55 var rootLib = await runnableIsolate.rootLibrary.load(); | |
56 var mainFunction = await rootLib.functions['main'].load(); | |
57 | |
58 var mainLocation = script.sourceSpan(mainFunction.location); | |
59 | |
60 var startLocation = script.sourceLocation(range.location.token); | |
61 expect(startLocation, mainLocation.start); | |
62 | |
63 var endLocation = script.sourceLocation(range.location.end); | |
64 expect(endLocation, mainLocation.end); | |
65 | |
66 expect(range.hits, isNull); | |
67 expect(range.misses, isNull); | |
68 expect(range.possibleBreakpoints, isNull); | |
69 }); | |
70 | |
71 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.
| |
72 var report = | |
73 await isolate.getSourceReport(includePossibleBreakpoints: false); | |
74 | |
75 var range = report.ranges.singleWhere((range) => | |
76 range.script.uri.toString().startsWith('data:application/dart')); | |
77 expect(range.possibleBreakpoints, isNull); | |
78 | |
79 var script = await range.script.load(); | |
80 | |
81 // 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.
| |
82 var hitLines = | |
83 range.hits.map((token) => script.sourceLocation(token).line).toSet(); | |
84 expect(hitLines, [6, 7, 8, 15, 17]); | |
85 | |
86 // represents the unique set of lines that are not executed | |
87 var missedLines = | |
88 range.misses.map((token) => script.sourceLocation(token).line); | |
89 expect(missedLines, [11, 12]); | |
90 }); | |
91 | |
92 test("behaves correctly without coverage", () async { | |
93 var report = await isolate.getSourceReport(includeCoverageReport: false); | |
94 | |
95 var range = report.ranges.singleWhere((range) => | |
96 range.script.uri.toString().startsWith('data:application/dart')); | |
97 | |
98 expect(range.hits, isNull); | |
99 expect(range.misses, isNull); | |
100 | |
101 var script = await range.script.load(); | |
102 expect(range.possibleBreakpoints, isNotEmpty); | |
103 | |
104 // represents the unique set of lines that can have breakpoints | |
105 var breakPointLines = range.possibleBreakpoints | |
106 .map((token) => script.sourceLocation(token).line) | |
107 .toSet(); | |
108 expect(breakPointLines, [4, 6, 7, 8, 11, 12, 15, 17]); | |
109 }); | |
110 | |
111 test("behaves correctly including coverage and breakpoints", () async { | |
112 var report = await isolate.getSourceReport( | |
113 includeCoverageReport: true, includePossibleBreakpoints: true); | |
114 | |
115 var range = report.ranges.singleWhere((range) => | |
116 range.script.uri.toString().startsWith('data:application/dart')); | |
117 | |
118 expect(range.hits, isNotEmpty); | |
119 expect(range.misses, isNotEmpty); | |
120 expect(range.possibleBreakpoints, isNotEmpty); | |
121 }); | |
122 }); | |
123 | |
124 group('a script with multiple ranges', () { | |
125 VMScript script; | |
126 VMLibrary rootLib; | |
127 VMSourceLocation mainLocation; | |
128 FileSpan mainFunctionSpan; | |
129 VMSourceLocation unusedFunction2Location; | |
130 | |
131 setUp(() async { | |
132 client = await runAndConnect( | |
133 topLevel: r'''final unusedField = 5; | |
134 | |
135 int unusedFunction(a, b) { | |
136 return a + b; | |
137 } | |
138 | |
139 void unusedFunction2(value) { | |
140 print(value); | |
141 }''', | |
142 main: _mainContent); | |
143 | |
144 isolate = (await client.getVM()).isolates.single; | |
145 | |
146 await isolate.waitUntilPaused(); | |
147 | |
148 var runnableIsolate = await isolate.loadRunnable(); | |
149 rootLib = await runnableIsolate.rootLibrary.load(); | |
150 script = await rootLib.scripts.single.load(); | |
151 | |
152 var mainFunction = await rootLib.functions['main'].load(); | |
153 mainLocation = mainFunction.location; | |
154 mainFunctionSpan = script.sourceSpan(mainLocation); | |
155 | |
156 var unusedFunction2 = await rootLib.functions['unusedFunction2'].load(); | |
157 unusedFunction2Location = unusedFunction2.location; | |
158 }); | |
159 | |
160 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.
| |
161 var report = await script.getSourceReport( | |
162 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.
| |
163 | |
164 expect(report.ranges, hasLength(3)); | |
165 | |
166 var firstRange = report.ranges.first; | |
167 expect(firstRange.compiled, isFalse); | |
168 expect(firstRange.hits, isNull); | |
169 expect(firstRange.misses, isNull); | |
170 expect(firstRange.possibleBreakpoints, isNull); | |
171 | |
172 // TODO(kevmoo): use lessThan in matcher when | |
173 // https://github.com/dart-lang/matcher/issues/33 is fixed | |
174 expect(script.sourceSpan(firstRange.location).compareTo(mainFunctionSpan), | |
175 isNegative); | |
176 | |
177 var lastRange = report.ranges.last; | |
178 expect(lastRange.compiled, isTrue); | |
179 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.
| |
180 }); | |
181 | |
182 test("force compiled", () async { | |
183 var report = await script.getSourceReport( | |
184 includeCoverageReport: true, | |
185 includePossibleBreakpoints: true, | |
186 forceCompile: true); | |
187 | |
188 expect(report.ranges, hasLength(3)); | |
189 | |
190 var firstRange = report.ranges.first; | |
191 expect(firstRange.compiled, isTrue); | |
192 | |
193 var secondRange = report.ranges.last; | |
194 expect(secondRange.compiled, isTrue); | |
195 }); | |
196 | |
197 test("with start set", () async { | |
198 var report = await script.getSourceReport( | |
199 includeCoverageReport: true, | |
200 includePossibleBreakpoints: true, | |
201 start: mainLocation.token); | |
202 | |
203 expect( | |
204 script.sourceSpan(report.ranges.single.location), mainFunctionSpan); | |
205 }); | |
206 | |
207 test("with end set", () async { | |
208 var report = await script.getSourceReport( | |
209 includeCoverageReport: true, | |
210 includePossibleBreakpoints: true, | |
211 end: unusedFunction2Location.token); | |
212 | |
213 expect(report.ranges, hasLength(2), | |
214 reason: 'Includes the range containing only unusedFunction2, main.'); | |
215 }); | |
216 | |
217 test("with an empty token range", () async { | |
218 var report = await script.getSourceReport( | |
219 includeCoverageReport: true, | |
220 includePossibleBreakpoints: true, | |
221 start: unusedFunction2Location.token, | |
222 end: unusedFunction2Location.end); | |
223 | |
224 expect(report.ranges, hasLength(1)); | |
225 expect(script.sourceSpan(report.ranges.single.location), | |
226 script.sourceSpan(unusedFunction2Location)); | |
227 }); | |
228 }); | |
229 } | |
OLD | NEW |