OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
nweiz
2016/04/29 00:52:45
2016
kevmoo
2016/04/29 23:36:55
Done.
| |
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:test/test.dart'; | |
6 import 'package:vm_service_client/vm_service_client.dart'; | |
7 | |
8 import 'utils.dart'; | |
9 | |
10 VMServiceClient client; | |
11 VMIsolateRef isolate; | |
nweiz
2016/04/29 00:52:44
There's no reason for this to be a top-level varia
kevmoo
2016/04/29 23:36:55
Done.
| |
12 | |
13 void main() { | |
14 tearDown(() { | |
15 if (client != null) { | |
16 client.close(); | |
17 client = null; | |
nweiz
2016/04/29 00:52:45
Don't bother nulling out the client. None of the o
kevmoo
2016/04/29 23:36:55
Done.
| |
18 } | |
19 isolate = null; | |
20 }); | |
21 | |
22 group('simple script', () { | |
nweiz
2016/04/29 00:52:44
The group name plus the test name should form a se
kevmoo
2016/04/29 23:36:55
Done.
| |
23 setUp(() async { | |
24 client = await runAndConnect(main: r""" | |
25 print("one"); | |
26 print("two"); | |
27 """); | |
nweiz
2016/04/29 00:52:44
Indent this correctly.
kevmoo
2016/04/29 23:36:55
this is copied from other tests that already exist
nweiz
2016/05/04 23:05:51
The same way it was indented in the tests you copi
kevmoo
2016/05/05 20:46:26
Please look at the latest code. This is changed qu
| |
28 | |
29 isolate = (await client.getVM()).isolates.single; | |
30 | |
31 await isolate.pause(); | |
nweiz
2016/04/29 00:52:45
I'm not sure what you're going for here, but this
kevmoo
2016/04/29 23:36:55
I tried that and it never gets hit – I think becau
nweiz
2016/05/04 23:05:51
The simplest solution would be to just add Isolate
kevmoo
2016/05/05 20:46:26
Done.
| |
32 }); | |
33 | |
34 test("no options", () async { | |
35 var report = await isolate.getSourceReport(); | |
36 | |
37 expect(report.scripts, hasLength(greaterThan(1))); | |
38 expect(report.ranges, hasLength(greaterThan(1))); | |
39 | |
40 var customScript = report.scripts.last; | |
41 | |
42 expect(customScript.uri.toString(), startsWith('data:application/dart')); | |
43 | |
44 var range = report.ranges.singleWhere( | |
45 (range) => range.scriptIndex == report.scripts.length - 1); | |
nweiz
2016/04/29 00:52:45
There shouldn't actually be multiple ranges in the
kevmoo
2016/04/29 23:36:55
Acknowledged.
| |
46 | |
47 expect(range.compiled, isTrue); | |
48 expect(range.startPos, lessThan(range.endPos)); | |
nweiz
2016/04/29 00:52:45
Assert that the source location is equal to the so
kevmoo
2016/04/29 23:36:55
Done.
| |
49 expect(range.coverage, isNull); | |
50 expect(range.possibleBreakpoints, isNull); | |
51 }); | |
52 | |
53 test("coverage", () async { | |
54 var report = await isolate.getSourceReport(includeCoverageReport: true); | |
55 | |
nweiz
2016/04/29 00:52:44
Nit: Having a newline between every statement isn'
kevmoo
2016/04/29 23:36:55
Acknowledged.
nweiz
2016/05/04 23:05:51
You deleted one newline :p.
kevmoo
2016/05/05 20:46:25
Acknowledged.
| |
56 var customScript = report.scripts.last; | |
57 | |
58 expect(customScript.uri.toString(), startsWith('data:application/dart')); | |
59 | |
60 var range = report.ranges.singleWhere( | |
61 (range) => range.scriptIndex == report.scripts.length - 1); | |
62 | |
63 expect(range.possibleBreakpoints, isNull); | |
64 | |
65 var coverage = range.coverage; | |
66 | |
67 expect(coverage.hits, isNotEmpty); | |
68 expect(coverage.misses, isEmpty); | |
nweiz
2016/04/29 00:52:44
These assertions are pretty loose—they don't asser
kevmoo
2016/04/29 23:36:55
Done.
| |
69 }); | |
70 | |
71 test("possible break points", () async { | |
72 var report = | |
73 await isolate.getSourceReport(includePossibleBreakpoints: true); | |
74 | |
75 var customScript = report.scripts.last; | |
76 | |
77 expect(customScript.uri.toString(), startsWith('data:application/dart')); | |
78 | |
79 var range = report.ranges.singleWhere( | |
80 (range) => range.scriptIndex == report.scripts.length - 1); | |
81 | |
82 expect(range.coverage, isNull); | |
83 | |
84 expect(range.possibleBreakpoints, isNotEmpty); | |
nweiz
2016/04/29 00:52:45
Actually assert what the breakpoints are. You can
kevmoo
2016/04/29 23:36:55
Done.
| |
85 }); | |
86 | |
87 test("both options", () async { | |
nweiz
2016/04/29 00:52:45
I don't think this is necessary.
kevmoo
2016/04/29 23:36:55
Eh, I like to make sure someone in the future does
nweiz
2016/05/04 23:05:51
If you're going to test the cross-product of all o
kevmoo
2016/05/05 20:46:25
Acknowledged.
| |
88 var report = await isolate.getSourceReport( | |
89 includeCoverageReport: true, includePossibleBreakpoints: true); | |
90 | |
91 var customScript = report.scripts.last; | |
92 | |
93 expect(customScript.uri.toString(), startsWith('data:application/dart')); | |
94 | |
95 var range = report.ranges.singleWhere( | |
96 (range) => range.scriptIndex == report.scripts.length - 1); | |
97 | |
98 expect(range.coverage, isNotNull); | |
99 expect(range.possibleBreakpoints, isNotNull); | |
100 }); | |
101 }); | |
nweiz
2016/04/29 00:52:45
Test forceCompile as well.
kevmoo
2016/04/29 23:36:56
Done.
| |
102 | |
103 test("script and ranges", () async { | |
104 client = await runAndConnect( | |
105 topLevel: r'''final foo = 5; | |
106 int add(a, b) => a + b; | |
107 ''', | |
108 main: r""" | |
109 print("one"); | |
110 print("two"); | |
111 """); | |
112 | |
113 isolate = (await client.getVM()).isolates.single; | |
114 | |
115 await isolate.pause(); | |
116 | |
117 var report = await isolate.getSourceReport(includeCoverageReport: true); | |
118 | |
119 var customScript = report.scripts.last; | |
120 | |
121 expect(customScript.uri.toString(), startsWith('data:application/dart')); | |
122 | |
123 report = await customScript.getSourceReport( | |
124 includeCoverageReport: true, includePossibleBreakpoints: true); | |
nweiz
2016/04/29 00:52:45
Rather than grabbing source locations from a previ
kevmoo
2016/04/29 23:36:55
Done.
| |
125 | |
126 expect(report.ranges, hasLength(2)); | |
127 | |
128 var firstRange = report.ranges.first; | |
129 var secondRange = report.ranges.last; | |
130 | |
131 expect(firstRange.endPos, lessThan(secondRange.startPos), | |
132 reason: 'The first range should come before the second range.'); | |
133 | |
134 // validate the start param | |
135 | |
136 report = await customScript.getSourceReport( | |
137 includeCoverageReport: true, | |
138 includePossibleBreakpoints: true, | |
139 tokenPos: firstRange.endPos + 1); | |
140 | |
141 expect(report.ranges.single.startPos, secondRange.startPos); | |
142 | |
143 // validate the end param | |
144 | |
145 report = await customScript.getSourceReport( | |
146 includeCoverageReport: true, | |
147 includePossibleBreakpoints: true, | |
148 endTokenPos: secondRange.startPos - 1); | |
149 | |
150 expect(report.ranges.single.endPos, firstRange.endPos); | |
151 | |
152 // validate both params | |
153 | |
154 report = await customScript.getSourceReport( | |
155 includeCoverageReport: true, | |
156 includePossibleBreakpoints: true, | |
157 tokenPos: firstRange.endPos + 1, | |
158 endTokenPos: secondRange.startPos - 1); | |
159 | |
160 expect(report.ranges, isEmpty); | |
161 }); | |
nweiz
2016/04/29 00:52:44
Split this up into multiple tests with a shared se
kevmoo
2016/04/29 23:36:55
Done.
| |
162 } | |
OLD | NEW |