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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/coverage.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/coverage_test.cc
diff --git a/runtime/vm/coverage_test.cc b/runtime/vm/coverage_test.cc
index 6219212f8c74ab80dd6d9c10107b1dc775438fd9..e37cf67f6f870cd6e163a7be7e08df2ffb52dd1c 100644
--- a/runtime/vm/coverage_test.cc
+++ b/runtime/vm/coverage_test.cc
@@ -8,7 +8,7 @@
namespace dart {
-static void ExecuteScript(const char* script) {
+static RawObject* ExecuteScript(const char* script) {
Dart_Handle h_lib = TestCase::LoadTestScript(script, NULL);
EXPECT_VALID(h_lib);
Library& lib = Library::Handle();
@@ -16,9 +16,24 @@ static void ExecuteScript(const char* script) {
EXPECT(!lib.IsNull());
Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
EXPECT_VALID(result);
+ return Api::UnwrapHandle(h_lib);
}
+class FunctionCoverageFilter : public CoverageFilter {
+ public:
+ explicit FunctionCoverageFilter(const Function& func) : func_(func) {}
+ bool ShouldOutputCoverageFor(const Library& lib,
+ const String& script_url,
+ const Class& cls,
+ const Function& func) const {
+ return func.raw() == func_.raw();
+ }
+ private:
+ const Function& func_;
+};
+
+
TEST_CASE(Coverage_Empty) {
const char* kScript =
"main() {\n"
@@ -77,4 +92,40 @@ TEST_CASE(Coverage_MainWithClass) {
"\"kind\":\"script\"},\"hits\":[10,1,11,1]}", js.ToCString());
}
+
+TEST_CASE(Coverage_FilterFunction) {
+ const char* kScript =
+ "class Foo {\n"
+ " var x;\n"
+ " var y;\n"
+ " Foo(this.x);\n"
+ " Foo.other(this.x, this.y);\n"
+ " Foo.yetAnother();\n"
+ "}\n"
+ "main() {\n"
+ " var foo = new Foo(7);\n"
+ "}\n";
+
+ Isolate* isolate = Isolate::Current();
+ Library& lib = Library::Handle();
+ lib ^= ExecuteScript(kScript);
+ ASSERT(!lib.IsNull());
+ const Class& cls = Class::Handle(
+ lib.LookupClass(String::Handle(String::New("Foo"))));
+ ASSERT(!cls.IsNull());
+ const Function& func = Function::Handle(
+ cls.LookupFunction(String::Handle(String::New("Foo.yetAnother"))));
+ ASSERT(!func.IsNull());
+
+ JSONStream js;
+ FunctionCoverageFilter filter(func);
+ CodeCoverage::PrintJSON(isolate, &js, &filter);
+ // Only expect coverage data for Foo.yetAnother() on line 6.
+ EXPECT_SUBSTRING(
+ "{\"source\":\"test-lib\",\"script\":{"
+ "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\","
+ "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
+ "\"kind\":\"script\"},\"hits\":[6,0]}", js.ToCString());
+}
+
} // namespace dart
« 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