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"); | |
nweiz
2016/05/04 23:05:52
What is going on with this indentation? Why are th
kevmoo
2016/05/05 20:46:27
Right?
| |
13 print("two"); | |
14 | |
15 if (false) { | |
16 print("three"); | |
17 print("four"); | |
18 }"""; | |
19 | |
20 void main() { | |
21 VMServiceClient client; | |
22 VMIsolateRef isolate; | |
23 | |
24 tearDown(() { | |
25 if (client != null) client.close(); | |
26 }); | |
27 | |
28 group('a script with one range', () { | |
29 setUp(() async { | |
30 client = await runAndConnect(main: _mainContent); | |
31 | |
32 isolate = (await client.getVM()).isolates.single; | |
33 | |
34 await isolate.pause(); | |
35 }); | |
36 | |
37 test("and no options", () async { | |
nweiz
2016/05/04 23:05:52
The group name plus the test name should be a sent
kevmoo
2016/05/05 20:46:28
Done.
nweiz
2016/05/11 23:03:31
"behaves correctly" doesn't actually describe any
| |
38 var report = await isolate.getSourceReport(); | |
39 | |
40 expect(report.ranges, hasLength(greaterThan(1))); | |
41 | |
42 var range = report.ranges.singleWhere((range) => | |
43 range.script.uri.toString().startsWith('data:application/dart')); | |
44 | |
45 expect(range.compiled, isTrue); | |
46 | |
47 var script = await range.script.load(); | |
48 | |
49 var startLocation = script.sourceLocation(range.location.token); | |
50 expect(startLocation.line, 4); | |
51 expect(startLocation.column, 0); | |
nweiz
2016/05/04 23:05:52
Testing the explicit line and column is brittle, a
kevmoo
2016/05/05 20:46:27
Done.
| |
52 | |
53 var endLocation = script.sourceLocation(range.location.end); | |
54 expect(endLocation.line, 14); | |
55 expect(endLocation.column, 0); | |
56 | |
57 expect(range.hits, isNull); | |
58 expect(range.misses, isNull); | |
59 expect(range.possibleBreakpoints, isNull); | |
60 }); | |
61 | |
62 test("including coverage", () async { | |
63 var report = await isolate.getSourceReport(includeCoverageReport: true); | |
64 | |
65 var range = report.ranges.singleWhere((range) => | |
66 range.script.uri.toString().startsWith('data:application/dart')); | |
67 expect(range.possibleBreakpoints, isNull); | |
68 | |
69 var script = await range.script.load(); | |
70 | |
71 var hitLocations = | |
72 range.hits.map((token) => script.sourceLocation(token).line); | |
73 | |
74 expect(hitLocations, [6, 7, 8, 14]); | |
nweiz
2016/05/04 23:05:52
Add a comment explaining what actual lines these r
kevmoo
2016/05/05 20:46:27
Done.
| |
75 | |
76 var missLocations = | |
77 range.misses.map((token) => script.sourceLocation(token).line); | |
78 | |
79 expect(missLocations, [11, 12]); | |
80 }); | |
81 | |
82 test("including possible breakpoints", () async { | |
83 var report = | |
84 await isolate.getSourceReport(includePossibleBreakpoints: true); | |
85 | |
86 var range = report.ranges.singleWhere((range) => | |
87 range.script.uri.toString().startsWith('data:application/dart')); | |
88 | |
89 expect(range.hits, isNull); | |
90 expect(range.misses, isNull); | |
91 | |
92 var script = await range.script.load(); | |
93 | |
94 expect(range.possibleBreakpoints, isNotEmpty); | |
95 | |
96 var breakPointLines = range.possibleBreakpoints | |
97 .map((token) => script.sourceLocation(token).line); | |
98 | |
99 expect(breakPointLines, [4, 6, 7, 8, 11, 12, 14]); | |
100 }); | |
101 | |
102 test("including coverage and possible breakpoints", () async { | |
103 var report = await isolate.getSourceReport( | |
104 includeCoverageReport: true, includePossibleBreakpoints: true); | |
105 | |
106 var range = report.ranges.singleWhere((range) => | |
107 range.script.uri.toString().startsWith('data:application/dart')); | |
108 | |
109 expect(range.hits, isNotEmpty); | |
110 expect(range.misses, isNotEmpty); | |
111 expect(range.possibleBreakpoints, isNotEmpty); | |
112 }); | |
113 }); | |
114 | |
115 group('a script with multiple ranges', () { | |
116 VMScript script; | |
117 VMLibrary rootLib; | |
118 VMSourceLocation mainFunctionLocation; | |
nweiz
2016/05/04 23:05:52
I think just "mainLocation" would be fine here.
kevmoo
2016/05/05 20:46:28
Done.
nweiz
2016/05/11 23:03:31
This comment was intended to also apply to other s
| |
119 FileSpan mainFunctionSpan; | |
120 VMSourceLocation unusedFunc2Location; | |
nweiz
2016/05/04 23:05:52
"Func" -> "Function"
kevmoo
2016/05/05 20:46:27
Done.
| |
121 | |
122 setUp(() async { | |
123 client = await runAndConnect( | |
124 topLevel: r'''final unusedField = 5; | |
125 | |
126 int unusedFunction(a, b) { | |
127 return a + b; | |
128 } | |
129 | |
130 void unusedFunction2(value) { | |
131 print(value); | |
132 }''', | |
133 main: _mainContent); | |
134 | |
135 isolate = (await client.getVM()).isolates.single; | |
136 | |
137 await isolate.pause(); | |
138 | |
139 var runnableIsolate = await isolate.loadRunnable(); | |
140 rootLib = await runnableIsolate.rootLibrary.load(); | |
141 script = await rootLib.scripts.single.load(); | |
142 | |
143 var mainFunc = await rootLib.functions['main'].load(); | |
nweiz
2016/05/04 23:05:53
"Func" -> "Function"
kevmoo
2016/05/05 20:46:27
Done.
| |
144 mainFunctionLocation = mainFunc.location; | |
145 mainFunctionSpan = script.sourceSpan(mainFunctionLocation); | |
146 | |
147 var unusedFunction2 = await rootLib.functions['unusedFunction2'].load(); | |
148 unusedFunc2Location = unusedFunc2Location = unusedFunction2.location; | |
nweiz
2016/05/04 23:05:52
Extra assignment.
kevmoo
2016/05/05 20:46:28
Done.
| |
149 }); | |
150 | |
151 test("not force compiled", () async { | |
152 var report = await script.getSourceReport( | |
153 includeCoverageReport: true, includePossibleBreakpoints: true); | |
154 | |
155 expect(report.ranges, hasLength(3)); | |
156 | |
157 var firstRange = report.ranges.first; | |
158 expect(firstRange.compiled, isFalse); | |
nweiz
2016/05/04 23:05:53
Make assertions about the other properties as well
kevmoo
2016/05/05 20:46:28
Done.
| |
159 var firstRangeLocation = | |
nweiz
2016/05/04 23:05:53
Why is this called "Location" if it's an offset?
kevmoo
2016/05/05 20:46:27
Acknowledged.
| |
160 script.sourceLocation(firstRange.location.end).offset; | |
161 expect(firstRangeLocation, lessThan(mainFunctionSpan.start.offset)); | |
nweiz
2016/05/04 23:05:53
You can just do
expect(script.sourceSpan(firstR
kevmoo
2016/05/05 20:46:27
Sadly, `lessThan` only uses the `>` operator.
We
| |
162 | |
163 var lastRange = report.ranges.last; | |
164 expect(lastRange.compiled, isTrue); | |
165 var lastRangeOffset = | |
166 script.sourceLocation(lastRange.location.token).offset; | |
167 expect(lastRangeOffset, mainFunctionSpan.start.offset); | |
168 }); | |
169 | |
170 test("force compiled", () async { | |
171 var report = await script.getSourceReport( | |
172 includeCoverageReport: true, | |
173 includePossibleBreakpoints: true, | |
174 forceCompile: true); | |
175 | |
176 expect(report.ranges, hasLength(3)); | |
177 | |
178 var firstRange = report.ranges.first; | |
179 expect(firstRange.compiled, isTrue); | |
180 | |
181 var secondRange = report.ranges.last; | |
182 expect(secondRange.compiled, isTrue); | |
183 }); | |
184 | |
185 test("with tokenPos set", () async { | |
nweiz
2016/05/04 23:05:52
It's not called "tokenPos" (or "endTokenPos") anym
kevmoo
2016/05/05 20:46:27
Acknowledged.
| |
186 var report = await script.getSourceReport( | |
187 includeCoverageReport: true, | |
188 includePossibleBreakpoints: true, | |
189 start: mainFunctionLocation.token); | |
190 | |
191 var rangeOffset = | |
192 script.sourceLocation(report.ranges.single.location.token).offset; | |
193 | |
194 expect(rangeOffset, mainFunctionSpan.start.offset); | |
195 }); | |
196 | |
197 test("with endTokenPos set", () async { | |
198 var report = await script.getSourceReport( | |
199 includeCoverageReport: true, | |
200 includePossibleBreakpoints: true, | |
201 end: unusedFunc2Location.token); | |
202 | |
203 expect(report.ranges, hasLength(2), | |
204 reason: 'Includes the range containing only unusedFunction2, main.'); | |
205 }); | |
206 | |
207 test("with an empty token range", () async { | |
208 var report = await script.getSourceReport( | |
209 includeCoverageReport: true, | |
210 includePossibleBreakpoints: true, | |
211 start: unusedFunc2Location.token, | |
212 end: unusedFunc2Location.end); | |
213 | |
214 expect(report.ranges, hasLength(1), | |
215 reason: 'Includes the range containing only unusedFunction2.'); | |
nweiz
2016/05/04 23:05:52
Assert that this is in fact the range it contains.
kevmoo
2016/05/05 20:46:28
Done.
| |
216 }); | |
217 }); | |
218 } | |
OLD | NEW |