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

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

Issue 376333002: vm/service/observatory: Add coverage for functions, some tests, and fix buggy filter (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add observatory deployed/ Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/coverage.cc ('k') | runtime/vm/service.cc » ('j') | 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) 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
11 static void ExecuteScript(const char* script) { 11 static RawObject* ExecuteScript(const char* script) {
12 Dart_Handle h_lib = TestCase::LoadTestScript(script, NULL); 12 Dart_Handle h_lib = TestCase::LoadTestScript(script, NULL);
13 EXPECT_VALID(h_lib); 13 EXPECT_VALID(h_lib);
14 Library& lib = Library::Handle(); 14 Library& lib = Library::Handle();
15 lib ^= Api::UnwrapHandle(h_lib); 15 lib ^= Api::UnwrapHandle(h_lib);
16 EXPECT(!lib.IsNull()); 16 EXPECT(!lib.IsNull());
17 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); 17 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
18 EXPECT_VALID(result); 18 EXPECT_VALID(result);
19 return Api::UnwrapHandle(h_lib);
19 } 20 }
20 21
21 22
23 class FunctionCoverageFilter : public CoverageFilter {
24 public:
25 explicit FunctionCoverageFilter(const Function& func) : func_(func) {}
26 bool ShouldOutputCoverageFor(const Library& lib,
27 const String& script_url,
28 const Class& cls,
29 const Function& func) const {
30 return func.raw() == func_.raw();
31 }
32 private:
33 const Function& func_;
34 };
35
36
22 TEST_CASE(Coverage_Empty) { 37 TEST_CASE(Coverage_Empty) {
23 const char* kScript = 38 const char* kScript =
24 "main() {\n" 39 "main() {\n"
25 "}"; 40 "}";
26 41
27 Isolate* isolate = Isolate::Current(); 42 Isolate* isolate = Isolate::Current();
28 ExecuteScript(kScript); 43 ExecuteScript(kScript);
29 44
30 JSONStream js; 45 JSONStream js;
31 CodeCoverage::PrintJSON(isolate, &js, NULL); 46 CodeCoverage::PrintJSON(isolate, &js, NULL);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 "\"kind\":\"script\"},\"hits\":[3,1,5,4,6,3]}", js.ToCString()); 85 "\"kind\":\"script\"},\"hits\":[3,1,5,4,6,3]}", js.ToCString());
71 86
72 // Data for the fake class containing main(). 87 // Data for the fake class containing main().
73 EXPECT_SUBSTRING( 88 EXPECT_SUBSTRING(
74 "{\"source\":\"test-lib\",\"script\":{" 89 "{\"source\":\"test-lib\",\"script\":{"
75 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," 90 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\","
76 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," 91 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
77 "\"kind\":\"script\"},\"hits\":[10,1,11,1]}", js.ToCString()); 92 "\"kind\":\"script\"},\"hits\":[10,1,11,1]}", js.ToCString());
78 } 93 }
79 94
95
96 TEST_CASE(Coverage_FilterFunction) {
97 const char* kScript =
98 "class Foo {\n"
99 " var x;\n"
100 " var y;\n"
101 " Foo(this.x);\n"
102 " Foo.other(this.x, this.y);\n"
103 " Foo.yetAnother();\n"
104 "}\n"
105 "main() {\n"
106 " var foo = new Foo(7);\n"
107 "}\n";
108
109 Isolate* isolate = Isolate::Current();
110 Library& lib = Library::Handle();
111 lib ^= ExecuteScript(kScript);
112 ASSERT(!lib.IsNull());
113 const Class& cls = Class::Handle(
114 lib.LookupClass(String::Handle(String::New("Foo"))));
115 ASSERT(!cls.IsNull());
116 const Function& func = Function::Handle(
117 cls.LookupFunction(String::Handle(String::New("Foo.yetAnother"))));
118 ASSERT(!func.IsNull());
119
120 JSONStream js;
121 FunctionCoverageFilter filter(func);
122 CodeCoverage::PrintJSON(isolate, &js, &filter);
123 // Only expect coverage data for Foo.yetAnother() on line 6.
124 EXPECT_SUBSTRING(
125 "{\"source\":\"test-lib\",\"script\":{"
126 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\","
127 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
128 "\"kind\":\"script\"},\"hits\":[6,0]}", js.ToCString());
129 }
130
80 } // namespace dart 131 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/coverage.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698