| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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/coverage.h" | 5 #include "vm/coverage.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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 Library& lib = Library::Handle(); | 43 Library& lib = Library::Handle(); |
| 44 lib ^= ExecuteScript(kScript); | 44 lib ^= ExecuteScript(kScript); |
| 45 ASSERT(!lib.IsNull()); | 45 ASSERT(!lib.IsNull()); |
| 46 | 46 |
| 47 JSONStream js; | 47 JSONStream js; |
| 48 CodeCoverage::PrintJSON(isolate, &js, NULL, false); | 48 CodeCoverage::PrintJSON(isolate, &js, NULL, false); |
| 49 | 49 |
| 50 char buf[1024]; | 50 char buf[1024]; |
| 51 OS::SNPrint(buf, sizeof(buf), | 51 OS::SNPrint(buf, sizeof(buf), |
| 52 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," | 52 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," |
| 53 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," | 53 "\"fixedId\":true,\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," |
| 54 "\"uri\":\"test-lib\"," | 54 "\"uri\":\"test-lib\"," |
| 55 "\"kind\":\"script\"},\"hits\":[]}", lib.index()); | 55 "\"kind\":\"script\"},\"hits\":[]}", lib.index()); |
| 56 EXPECT_SUBSTRING(buf, js.ToCString()); | 56 EXPECT_SUBSTRING(buf, js.ToCString()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 TEST_CASE(Coverage_MainWithClass) { | 60 TEST_CASE(Coverage_MainWithClass) { |
| 61 const char* kScript = | 61 const char* kScript = |
| 62 "class Foo {\n" | 62 "class Foo {\n" |
| 63 " var x;\n" | 63 " var x;\n" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 80 JSONStream js; | 80 JSONStream js; |
| 81 CodeCoverage::PrintJSON(isolate, &js, NULL, false); | 81 CodeCoverage::PrintJSON(isolate, &js, NULL, false); |
| 82 | 82 |
| 83 char buf[1024]; | 83 char buf[1024]; |
| 84 // Coverage data is printed per class, i.e., there should be two sections | 84 // Coverage data is printed per class, i.e., there should be two sections |
| 85 // for test-lib in the JSON data. | 85 // for test-lib in the JSON data. |
| 86 | 86 |
| 87 // Data for the actual class Foo. | 87 // Data for the actual class Foo. |
| 88 OS::SNPrint(buf, sizeof(buf), | 88 OS::SNPrint(buf, sizeof(buf), |
| 89 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," | 89 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," |
| 90 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," | 90 "\"fixedId\":true,\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," |
| 91 "\"uri\":\"test-lib\"," | 91 "\"uri\":\"test-lib\"," |
| 92 "\"kind\":\"script\"},\"hits\":[3,1,5,4,6,3]}", lib.index()); | 92 "\"kind\":\"script\"},\"hits\":[3,1,5,4,6,3]}", lib.index()); |
| 93 EXPECT_SUBSTRING(buf, js.ToCString()); | 93 EXPECT_SUBSTRING(buf, js.ToCString()); |
| 94 | 94 |
| 95 // Data for the fake class containing main(). | 95 // Data for the fake class containing main(). |
| 96 OS::SNPrint(buf, sizeof(buf), | 96 OS::SNPrint(buf, sizeof(buf), |
| 97 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," | 97 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," |
| 98 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," | 98 "\"fixedId\":true,\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," |
| 99 "\"uri\":\"test-lib\"," | 99 "\"uri\":\"test-lib\"," |
| 100 "\"kind\":\"script\"},\"hits\":[10,1,11,1]}", lib.index()); | 100 "\"kind\":\"script\"},\"hits\":[10,1,11,1]}", lib.index()); |
| 101 EXPECT_SUBSTRING(buf, js.ToCString()); | 101 EXPECT_SUBSTRING(buf, js.ToCString()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 TEST_CASE(Coverage_FilterFunction) { | 105 TEST_CASE(Coverage_FilterFunction) { |
| 106 const char* kScript = | 106 const char* kScript = |
| 107 "class Foo {\n" | 107 "class Foo {\n" |
| 108 " var x;\n" | 108 " var x;\n" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 126 cls.LookupFunction(String::Handle(String::New("Foo.yetAnother")))); | 126 cls.LookupFunction(String::Handle(String::New("Foo.yetAnother")))); |
| 127 ASSERT(!func.IsNull()); | 127 ASSERT(!func.IsNull()); |
| 128 | 128 |
| 129 JSONStream js; | 129 JSONStream js; |
| 130 FunctionCoverageFilter filter(func); | 130 FunctionCoverageFilter filter(func); |
| 131 CodeCoverage::PrintJSON(isolate, &js, &filter, false); | 131 CodeCoverage::PrintJSON(isolate, &js, &filter, false); |
| 132 // Only expect coverage data for Foo.yetAnother() on line 6. | 132 // Only expect coverage data for Foo.yetAnother() on line 6. |
| 133 char buf[1024]; | 133 char buf[1024]; |
| 134 OS::SNPrint(buf, sizeof(buf), | 134 OS::SNPrint(buf, sizeof(buf), |
| 135 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," | 135 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," |
| 136 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," | 136 "\"fixedId\":true,\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," |
| 137 "\"uri\":\"test-lib\"," | 137 "\"uri\":\"test-lib\"," |
| 138 "\"kind\":\"script\"},\"hits\":[6,0]}", lib.index()); | 138 "\"kind\":\"script\"},\"hits\":[6,0]}", lib.index()); |
| 139 EXPECT_SUBSTRING(buf, js.ToCString()); | 139 EXPECT_SUBSTRING(buf, js.ToCString()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace dart | 142 } // namespace dart |
| OLD | NEW |