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

Side by Side Diff: runtime/vm/source_report_test.cc

Issue 1916243002: Fix getSourceReport's forceCompile option for unused classes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Report compilation errors 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/source_report.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/source_report.h" 5 #include "vm/source_report.h"
6 #include "vm/dart_api_impl.h" 6 #include "vm/dart_api_impl.h"
7 #include "vm/unit_test.h" 7 #include "vm/unit_test.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 "{\"scriptIndex\":0,\"startPos\":12,\"endPos\":39,\"compiled\":true," 136 "{\"scriptIndex\":0,\"startPos\":12,\"endPos\":39,\"compiled\":true,"
137 "\"coverage\":{\"hits\":[23],\"misses\":[32]}}]," 137 "\"coverage\":{\"hits\":[23],\"misses\":[32]}}],"
138 138
139 // Only one script in the script table. 139 // Only one script in the script table.
140 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\"," 140 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\","
141 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}", 141 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}",
142 buffer); 142 buffer);
143 } 143 }
144 144
145 145
146 TEST_CASE(SourceReport_Coverage_UnusedClass_NoForceCompile) {
147 char buffer[1024];
148 const char* kScript =
149 "helper0() {}\n"
150 "class Unused {\n"
151 " helper1() { helper0(); }\n"
152 "}"
rmacnak 2016/05/04 16:42:35 }\n
153 "main() {\n"
154 " helper0();\n"
155 "}";
156
157 Library& lib = Library::Handle();
158 lib ^= ExecuteScript(kScript);
159 ASSERT(!lib.IsNull());
160 const Script& script = Script::Handle(lib.LookupScript(
161 String::Handle(String::New("test-lib"))));
162
163 SourceReport report(SourceReport::kCoverage);
164 JSONStream js;
165 report.PrintJSON(&js, script);
166 ElideJSONSubstring("classes", js.ToCString(), buffer);
167 ElideJSONSubstring("libraries", buffer, buffer);
168 EXPECT_STREQ(
169 "{\"type\":\"SourceReport\",\"ranges\":["
170
171 // UnusedClass is not compiled.
172 "{\"scriptIndex\":0,\"startPos\":6,\"endPos\":20,\"compiled\":false},"
173
174 // helper0 is compiled.
175 "{\"scriptIndex\":0,\"startPos\":0,\"endPos\":4,\"compiled\":true,"
176 "\"coverage\":{\"hits\":[],\"misses\":[]}},"
177
178 // One range with a hit (main).
179 "{\"scriptIndex\":0,\"startPos\":21,\"endPos\":31,\"compiled\":true,"
180 "\"coverage\":{\"hits\":[26],\"misses\":[]}}],"
181
182 // Only one script in the script table.
183 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\","
184 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}",
185 buffer);
186 }
187
188
189 TEST_CASE(SourceReport_Coverage_UnusedClass_ForceCompile) {
190 char buffer[1024];
191 const char* kScript =
192 "helper0() {}\n"
193 "class Unused {\n"
194 " helper1() { helper0(); }\n"
195 "}"
rmacnak 2016/05/04 16:42:35 }\n
196 "main() {\n"
197 " helper0();\n"
198 "}";
199
200 Library& lib = Library::Handle();
201 lib ^= ExecuteScript(kScript);
202 ASSERT(!lib.IsNull());
203 const Script& script = Script::Handle(lib.LookupScript(
204 String::Handle(String::New("test-lib"))));
205
206 SourceReport report(SourceReport::kCoverage, SourceReport::kForceCompile);
207 JSONStream js;
208 report.PrintJSON(&js, script);
209 ElideJSONSubstring("classes", js.ToCString(), buffer);
210 ElideJSONSubstring("libraries", buffer, buffer);
211 EXPECT_STREQ(
212 "{\"type\":\"SourceReport\",\"ranges\":["
213
214 // UnusedClass.helper1 is compiled.
215 "{\"scriptIndex\":0,\"startPos\":10,\"endPos\":18,\"compiled\":true,"
216 "\"coverage\":{\"hits\":[],\"misses\":[14]}},"
217
218 // helper0 is compiled.
219 "{\"scriptIndex\":0,\"startPos\":0,\"endPos\":4,\"compiled\":true,"
220 "\"coverage\":{\"hits\":[],\"misses\":[]}},"
221
222 // One range with a hit (main).
223 "{\"scriptIndex\":0,\"startPos\":21,\"endPos\":31,\"compiled\":true,"
224 "\"coverage\":{\"hits\":[26],\"misses\":[]}}],"
225
226 // Only one script in the script table.
227 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\","
228 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}",
229 buffer);
230 }
231
232
233 TEST_CASE(SourceReport_Coverage_UnusedClass_ForceCompileError) {
234 char buffer[1024];
235 const char* kScript =
236 "helper0() {}\n"
237 "class Unused {\n"
238 " helper1() { helper0()+ }\n" // syntax error
239 "}"
rmacnak 2016/05/04 16:42:35 }\n
240 "main() {\n"
241 " helper0();\n"
242 "}";
243
244 Library& lib = Library::Handle();
245 lib ^= ExecuteScript(kScript);
246 ASSERT(!lib.IsNull());
247 const Script& script = Script::Handle(lib.LookupScript(
248 String::Handle(String::New("test-lib"))));
249
250 SourceReport report(SourceReport::kCoverage, SourceReport::kForceCompile);
251 JSONStream js;
252 report.PrintJSON(&js, script);
253 ElideJSONSubstring("classes", js.ToCString(), buffer);
254 ElideJSONSubstring("libraries", buffer, buffer);
255 EXPECT_STREQ(
256 "{\"type\":\"SourceReport\",\"ranges\":["
257
258 // UnusedClass has a syntax error.
259 "{\"scriptIndex\":0,\"startPos\":10,\"endPos\":18,\"compiled\":false,"
260 "\"error\":{\"type\":\"@Error\",\"_vmType\":\"LanguageError\","
261 "\"kind\":\"LanguageError\",\"id\":\"objects\\/0\","
262 "\"message\":\"'test-lib': error: line 3 pos 26: unexpected token '}'\\n"
263 " helper1() { helper0()+ }\\n ^\\n\"}},"
264
265 // helper0 is compiled.
266 "{\"scriptIndex\":0,\"startPos\":0,\"endPos\":4,\"compiled\":true,"
267 "\"coverage\":{\"hits\":[],\"misses\":[]}},"
268
269 // One range with a hit (main).
270 "{\"scriptIndex\":0,\"startPos\":21,\"endPos\":31,\"compiled\":true,"
271 "\"coverage\":{\"hits\":[26],\"misses\":[]}}],"
272
273 // Only one script in the script table.
274 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\","
275 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}",
276 buffer);
277 }
278
279
146 TEST_CASE(SourceReport_Coverage_NestedFunctions) { 280 TEST_CASE(SourceReport_Coverage_NestedFunctions) {
147 char buffer[1024]; 281 char buffer[1024];
148 const char* kScript = 282 const char* kScript =
149 "helper0() {\n" 283 "helper0() {\n"
150 " nestedHelper0() {}\n" 284 " nestedHelper0() {}\n"
151 " nestedHelper1() {}\n" 285 " nestedHelper1() {}\n"
152 " nestedHelper0();\n" 286 " nestedHelper0();\n"
153 "}\n" 287 "}\n"
154 "helper1() {}\n" 288 "helper1() {}\n"
155 "main() {\n" 289 "main() {\n"
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 635
502 // Only one script in the script table. 636 // Only one script in the script table.
503 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\"," 637 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\","
504 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}", 638 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}",
505 buffer); 639 buffer);
506 } 640 }
507 641
508 #endif // !PRODUCT 642 #endif // !PRODUCT
509 643
510 } // namespace dart 644 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/source_report.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698