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

Unified Diff: runtime/vm/isolate_reload_test.cc

Issue 2186423002: Only reload libraries when they may have been modified. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Code review Created 4 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/isolate_reload.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/isolate_reload_test.cc
diff --git a/runtime/vm/isolate_reload_test.cc b/runtime/vm/isolate_reload_test.cc
index fe35bd82e9c937e153c681e146e692b32e1c72b8..bfa1fc4f6d5a267502180d2c9d14c3c2886fe01a 100644
--- a/runtime/vm/isolate_reload_test.cc
+++ b/runtime/vm/isolate_reload_test.cc
@@ -1905,6 +1905,168 @@ TEST_CASE(IsolateReload_DirectSubclasses_Failure) {
EXPECT_STREQ("AIterator", name.ToCString());
}
+
+static bool NothingModifiedCallback(const char* url, int64_t since) {
+ return false;
+}
+
+
+TEST_CASE(IsolateReload_NoLibsModified) {
+ const char* kImportScript =
+ "importedFunc() => 'fancy';";
+ TestCase::SetImportableTestLibScript(kImportScript);
+
+ const char* kScript =
+ "import 'test:importable_lib';\n"
+ "main() {\n"
+ " return importedFunc() + ' feast';\n"
+ "}\n";
+
+ Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
+ EXPECT_VALID(lib);
+ EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
+
+ const char* kReloadImportScript =
+ "importedFunc() => 'bossy';";
+ TestCase::SetImportableTestLibScript(kReloadImportScript);
+
+ const char* kReloadScript =
+ "import 'test:importable_lib';\n"
+ "main() {\n"
+ " return importedFunc() + ' pants';\n"
+ "}\n";
+
+ Dart_SetFileModifiedCallback(&NothingModifiedCallback);
+ lib = TestCase::ReloadTestScript(kReloadScript);
+ EXPECT_VALID(lib);
+ Dart_SetFileModifiedCallback(NULL);
+
+ // No reload occurred because no files were "modified".
+ EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
+}
+
+
+static bool MainModifiedCallback(const char* url, int64_t since) {
+ if (strcmp(url, "test-lib") == 0) {
+ return true;
+ }
+ return false;
+}
+
+
+TEST_CASE(IsolateReload_MainLibModified) {
+ const char* kImportScript =
+ "importedFunc() => 'fancy';";
+ TestCase::SetImportableTestLibScript(kImportScript);
+
+ const char* kScript =
+ "import 'test:importable_lib';\n"
+ "main() {\n"
+ " return importedFunc() + ' feast';\n"
+ "}\n";
+
+ Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
+ EXPECT_VALID(lib);
+ EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
+
+ const char* kReloadImportScript =
+ "importedFunc() => 'bossy';";
+ TestCase::SetImportableTestLibScript(kReloadImportScript);
+
+ const char* kReloadScript =
+ "import 'test:importable_lib';\n"
+ "main() {\n"
+ " return importedFunc() + ' pants';\n"
+ "}\n";
+
+ Dart_SetFileModifiedCallback(&MainModifiedCallback);
+ lib = TestCase::ReloadTestScript(kReloadScript);
+ EXPECT_VALID(lib);
+ Dart_SetFileModifiedCallback(NULL);
+
+ // Imported library is not reloaded.
+ EXPECT_STREQ("fancy pants", SimpleInvokeStr(lib, "main"));
+}
+
+
+static bool ImportModifiedCallback(const char* url, int64_t since) {
+ if (strcmp(url, "test:importable_lib") == 0) {
+ return true;
+ }
+ return false;
+}
+
+
+TEST_CASE(IsolateReload_ImportedLibModified) {
+ const char* kImportScript =
+ "importedFunc() => 'fancy';";
+ TestCase::SetImportableTestLibScript(kImportScript);
+
+ const char* kScript =
+ "import 'test:importable_lib';\n"
+ "main() {\n"
+ " return importedFunc() + ' feast';\n"
+ "}\n";
+
+ Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
+ EXPECT_VALID(lib);
+ EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
+
+ const char* kReloadImportScript =
+ "importedFunc() => 'bossy';";
+ TestCase::SetImportableTestLibScript(kReloadImportScript);
+
+ const char* kReloadScript =
+ "import 'test:importable_lib';\n"
+ "main() {\n"
+ " return importedFunc() + ' pants';\n"
+ "}\n";
+
+ Dart_SetFileModifiedCallback(&ImportModifiedCallback);
+ lib = TestCase::ReloadTestScript(kReloadScript);
+ EXPECT_VALID(lib);
+ Dart_SetFileModifiedCallback(NULL);
+
+ // Modification of an imported library propagates to the importing library.
+ EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main"));
+}
+
+
+TEST_CASE(IsolateReload_PrefixImportedLibModified) {
+ const char* kImportScript =
+ "importedFunc() => 'fancy';";
+ TestCase::SetImportableTestLibScript(kImportScript);
+
+ const char* kScript =
+ "import 'test:importable_lib' as cobra;\n"
+ "main() {\n"
+ " return cobra.importedFunc() + ' feast';\n"
+ "}\n";
+
+ Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
+ EXPECT_VALID(lib);
+ EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
+
+ const char* kReloadImportScript =
+ "importedFunc() => 'bossy';";
+ TestCase::SetImportableTestLibScript(kReloadImportScript);
+
+ const char* kReloadScript =
+ "import 'test:importable_lib' as cobra;\n"
+ "main() {\n"
+ " return cobra.importedFunc() + ' pants';\n"
+ "}\n";
+
+ Dart_SetFileModifiedCallback(&ImportModifiedCallback);
+ lib = TestCase::ReloadTestScript(kReloadScript);
+ EXPECT_VALID(lib);
+ Dart_SetFileModifiedCallback(NULL);
+
+ // Modification of an prefix-imported library propagates to the
+ // importing library.
+ EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main"));
+}
+
#endif // !PRODUCT
} // namespace dart
« no previous file with comments | « runtime/vm/isolate_reload.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698