OLD | NEW |
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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 "\"_native\":false}," | 402 "\"_native\":false}," |
403 | 403 |
404 "\"count\":1}]}]}]," | 404 "\"count\":1}]}]}]," |
405 | 405 |
406 // One script in the script table. | 406 // One script in the script table. |
407 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\"," | 407 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\"," |
408 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}", | 408 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}", |
409 buffer); | 409 buffer); |
410 } | 410 } |
411 | 411 |
| 412 |
| 413 TEST_CASE(SourceReport_MultipleReports) { |
| 414 char buffer[1024]; |
| 415 const char* kScript = |
| 416 "helper0() {}\n" |
| 417 "helper1() {}\n" |
| 418 "main() {\n" |
| 419 " helper0();\n" |
| 420 "}"; |
| 421 |
| 422 Library& lib = Library::Handle(); |
| 423 lib ^= ExecuteScript(kScript); |
| 424 ASSERT(!lib.IsNull()); |
| 425 const Script& script = Script::Handle(lib.LookupScript( |
| 426 String::Handle(String::New("test-lib")))); |
| 427 |
| 428 SourceReport report(SourceReport::kCallSites|SourceReport::kCoverage); |
| 429 JSONStream js; |
| 430 report.PrintJSON(&js, script); |
| 431 ElideJSONSubstring("classes", js.ToCString(), buffer); |
| 432 ElideJSONSubstring("libraries", buffer, buffer); |
| 433 EXPECT_STREQ( |
| 434 "{\"type\":\"SourceReport\",\"ranges\":[" |
| 435 |
| 436 // One range compiled with no callsites (helper0). |
| 437 "{\"scriptIndex\":0,\"startPos\":0,\"endPos\":4,\"compiled\":true," |
| 438 "\"callSites\":[]," |
| 439 "\"coverage\":{\"hits\":[],\"misses\":[]}}," |
| 440 |
| 441 // One range not compiled (helper1). |
| 442 "{\"scriptIndex\":0,\"startPos\":6,\"endPos\":10,\"compiled\":false}," |
| 443 |
| 444 // One range compiled with one callsite (main). |
| 445 "{\"scriptIndex\":0,\"startPos\":12,\"endPos\":22,\"compiled\":true," |
| 446 "\"callSites\":[" |
| 447 "{\"name\":\"helper0\",\"tokenPos\":17,\"cacheEntries\":[" |
| 448 "{\"target\":{\"type\":\"@Function\",\"fixedId\":true,\"id\":\"\"," |
| 449 "\"name\":\"helper0\",\"owner\":{\"type\":\"@Library\",\"fixedId\":true," |
| 450 "\"id\":\"\",\"name\":\"\",\"uri\":\"test-lib\"}," |
| 451 "\"_kind\":\"RegularFunction\",\"static\":true,\"const\":false," |
| 452 "\"_intrinsic\":false,\"_native\":false},\"count\":1}]}]," |
| 453 "\"coverage\":{\"hits\":[17],\"misses\":[]}}]," |
| 454 |
| 455 // One script in the script table. |
| 456 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\"," |
| 457 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}", |
| 458 buffer); |
| 459 } |
| 460 |
412 } // namespace dart | 461 } // namespace dart |
OLD | NEW |