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

Unified Diff: runtime/vm/source_report_test.cc

Issue 1916243002: Fix getSourceReport's forceCompile option for unused classes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
« runtime/vm/source_report.cc ('K') | « runtime/vm/source_report.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/source_report_test.cc
diff --git a/runtime/vm/source_report_test.cc b/runtime/vm/source_report_test.cc
index ca02001b0f162bb70d0d9e16e62ddbda3a9e5d9f..0726c8a785c15f3ee9b6f6918e6f62e0295e4e50 100644
--- a/runtime/vm/source_report_test.cc
+++ b/runtime/vm/source_report_test.cc
@@ -143,6 +143,135 @@ TEST_CASE(SourceReport_Coverage_ForceCompile) {
}
+TEST_CASE(SourceReport_Coverage_UnusedClass_NoForceCompile) {
+ char buffer[1024];
+ const char* kScript =
+ "helper0() {}\n"
+ "class Unused {\n"
+ " helper1() { helper0(); }\n"
+ "}"
+ "main() {\n"
+ " helper0();\n"
+ "}";
+
+ Library& lib = Library::Handle();
+ lib ^= ExecuteScript(kScript);
+ ASSERT(!lib.IsNull());
+ const Script& script = Script::Handle(lib.LookupScript(
+ String::Handle(String::New("test-lib"))));
+
+ SourceReport report(SourceReport::kCoverage);
+ JSONStream js;
+ report.PrintJSON(&js, script);
+ ElideJSONSubstring("classes", js.ToCString(), buffer);
+ ElideJSONSubstring("libraries", buffer, buffer);
+ EXPECT_STREQ(
+ "{\"type\":\"SourceReport\",\"ranges\":["
+
+ // UnusedClass is not compiled.
+ "{\"scriptIndex\":0,\"startPos\":6,\"endPos\":20,\"compiled\":false},"
+
+ // helper0 is compiled.
+ "{\"scriptIndex\":0,\"startPos\":0,\"endPos\":4,\"compiled\":true,"
+ "\"coverage\":{\"hits\":[],\"misses\":[]}},"
+
+ // One range with a hit (main).
+ "{\"scriptIndex\":0,\"startPos\":21,\"endPos\":31,\"compiled\":true,"
+ "\"coverage\":{\"hits\":[26],\"misses\":[]}}],"
+
+ // Only one script in the script table.
+ "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\","
+ "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}",
+ buffer);
+}
+
+
+TEST_CASE(SourceReport_Coverage_UnusedClass_ForceCompile) {
+ char buffer[1024];
+ const char* kScript =
+ "helper0() {}\n"
+ "class Unused {\n"
+ " helper1() { helper0(); }\n"
+ "}"
+ "main() {\n"
+ " helper0();\n"
+ "}";
+
+ Library& lib = Library::Handle();
+ lib ^= ExecuteScript(kScript);
+ ASSERT(!lib.IsNull());
+ const Script& script = Script::Handle(lib.LookupScript(
+ String::Handle(String::New("test-lib"))));
+
+ SourceReport report(SourceReport::kCoverage, SourceReport::kForceCompile);
+ JSONStream js;
+ report.PrintJSON(&js, script);
+ ElideJSONSubstring("classes", js.ToCString(), buffer);
+ ElideJSONSubstring("libraries", buffer, buffer);
+ EXPECT_STREQ(
+ "{\"type\":\"SourceReport\",\"ranges\":["
+
+ // UnusedClass.helper1 is compiled.
+ "{\"scriptIndex\":0,\"startPos\":10,\"endPos\":18,\"compiled\":true,"
+ "\"coverage\":{\"hits\":[],\"misses\":[14]}},"
+
+ // helper0 is compiled.
+ "{\"scriptIndex\":0,\"startPos\":0,\"endPos\":4,\"compiled\":true,"
+ "\"coverage\":{\"hits\":[],\"misses\":[]}},"
+
+ // One range with a hit (main).
+ "{\"scriptIndex\":0,\"startPos\":21,\"endPos\":31,\"compiled\":true,"
+ "\"coverage\":{\"hits\":[26],\"misses\":[]}}],"
+
+ // Only one script in the script table.
+ "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\","
+ "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}",
+ buffer);
+}
+
+
+TEST_CASE(SourceReport_Coverage_UnusedClass_ForceCompileError) {
+ char buffer[1024];
+ const char* kScript =
+ "helper0() {}\n"
+ "class Unused {\n"
+ " helper1() { helper0()+ }\n" // syntax error
+ "}"
+ "main() {\n"
+ " helper0();\n"
+ "}";
+
+ Library& lib = Library::Handle();
+ lib ^= ExecuteScript(kScript);
+ ASSERT(!lib.IsNull());
+ const Script& script = Script::Handle(lib.LookupScript(
+ String::Handle(String::New("test-lib"))));
+
+ SourceReport report(SourceReport::kCoverage, SourceReport::kForceCompile);
+ JSONStream js;
+ report.PrintJSON(&js, script);
+ ElideJSONSubstring("classes", js.ToCString(), buffer);
+ ElideJSONSubstring("libraries", buffer, buffer);
+ EXPECT_STREQ(
+ "{\"type\":\"SourceReport\",\"ranges\":["
+
+ // UnusedClass is missing entirely due to syntax error.
+
+ // helper0 is compiled.
+ "{\"scriptIndex\":0,\"startPos\":0,\"endPos\":4,\"compiled\":true,"
+ "\"coverage\":{\"hits\":[],\"misses\":[]}},"
+
+ // One range with a hit (main).
+ "{\"scriptIndex\":0,\"startPos\":21,\"endPos\":31,\"compiled\":true,"
+ "\"coverage\":{\"hits\":[26],\"misses\":[]}}],"
+
+ // Only one script in the script table.
+ "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\","
+ "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}",
+ buffer);
+}
+
+
TEST_CASE(SourceReport_Coverage_NestedFunctions) {
char buffer[1024];
const char* kScript =
« runtime/vm/source_report.cc ('K') | « runtime/vm/source_report.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698