| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "vm/coverage.h" |
| 6 #include "vm/dart_api_impl.h" |
| 7 #include "vm/unit_test.h" |
| 8 |
| 9 namespace dart { |
| 10 |
| 11 static void ExecuteScript(const char* script) { |
| 12 Dart_Handle h_lib = TestCase::LoadTestScript(script, NULL); |
| 13 EXPECT_VALID(h_lib); |
| 14 Library& lib = Library::Handle(); |
| 15 lib ^= Api::UnwrapHandle(h_lib); |
| 16 EXPECT(!lib.IsNull()); |
| 17 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
| 18 EXPECT_VALID(result); |
| 19 } |
| 20 |
| 21 |
| 22 TEST_CASE(Coverage_Empty) { |
| 23 const char* kScript = |
| 24 "main() {\n" |
| 25 "}"; |
| 26 |
| 27 Isolate* isolate = Isolate::Current(); |
| 28 ExecuteScript(kScript); |
| 29 |
| 30 JSONStream js; |
| 31 CodeCoverage::PrintJSON(isolate, &js); |
| 32 |
| 33 EXPECT_SUBSTRING( |
| 34 "{\"source\":\"test-lib\",\"script\":{" |
| 35 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," |
| 36 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," |
| 37 "\"kind\":\"script\"},\"hits\":[]}", js.ToCString()); |
| 38 } |
| 39 |
| 40 |
| 41 TEST_CASE(Coverage_MainWithClass) { |
| 42 const char* kScript = |
| 43 "class Foo {\n" |
| 44 " var x;\n" |
| 45 " Foo(this.x);\n" |
| 46 " bar() {\n" |
| 47 " x = x * x;\n" |
| 48 " x = x / 13;\n" |
| 49 " }\n" |
| 50 "}\n" |
| 51 "main() {\n" |
| 52 " var foo = new Foo(7);\n" |
| 53 " foo.bar();\n" |
| 54 "}\n"; |
| 55 |
| 56 Isolate* isolate = Isolate::Current(); |
| 57 ExecuteScript(kScript); |
| 58 |
| 59 JSONStream js; |
| 60 CodeCoverage::PrintJSON(isolate, &js); |
| 61 |
| 62 // Coverage data is printed per class, i.e., there should be two sections |
| 63 // for test-lib in the JSON data. |
| 64 |
| 65 // Data for the actual class Foo. |
| 66 EXPECT_SUBSTRING( |
| 67 "{\"source\":\"test-lib\",\"script\":{" |
| 68 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," |
| 69 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," |
| 70 "\"kind\":\"script\"},\"hits\":[3,1,5,4,6,3]}", js.ToCString()); |
| 71 |
| 72 // Data for the fake class containing main(). |
| 73 EXPECT_SUBSTRING( |
| 74 "{\"source\":\"test-lib\",\"script\":{" |
| 75 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," |
| 76 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," |
| 77 "\"kind\":\"script\"},\"hits\":[10,1,11,1]}", js.ToCString()); |
| 78 } |
| 79 |
| 80 } // namespace dart |
| OLD | NEW |