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

Unified Diff: runtime/vm/unit_test.cc

Issue 2205513002: Pay attention to exports when determine which libraries to reload. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Pay attention to exports when determine which libraries to reload. 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/unit_test.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/unit_test.cc
diff --git a/runtime/vm/unit_test.cc b/runtime/vm/unit_test.cc
index 9c89d9c7d8bde2be03b5d08a71fa437a2bbb370c..1462abbfc427104b9f73cdb3c8b06a246f3407d1 100644
--- a/runtime/vm/unit_test.cc
+++ b/runtime/vm/unit_test.cc
@@ -74,37 +74,45 @@ static bool IsPackageSchemeURL(const char* url_name) {
}
-static bool IsImportableTestLib(const char* url_name) {
- const char* kImportTestLibUri = "test:importable_lib";
- static const intptr_t kImportTestLibUriLen = strlen(kImportTestLibUri);
- return (strncmp(url_name, kImportTestLibUri, kImportTestLibUriLen) == 0);
-}
-
-
-const char* kDefaultImportableTestLibScript =
- "importedFunc() => 'a';\n"
- "importedIntFunc() => 4;\n"
- "class ImportedMixin {\n"
- " mixinFunc() => 'mixin';\n"
- "}\n";
-const char* importable_test_lib_script = kDefaultImportableTestLibScript;
+struct TestLibEntry {
+ const char* url;
+ const char* source;
+};
-void TestCase::SetImportableTestLibScript(const char* source) {
- importable_test_lib_script = source;
-}
+static MallocGrowableArray<TestLibEntry>* test_libs_ = NULL;
-void TestCase::RestoreImportableTestLibScript() {
- importable_test_lib_script = kDefaultImportableTestLibScript;
+void TestCase::AddTestLib(const char* url, const char* source) {
+ if (test_libs_ == NULL) {
+ test_libs_ = new MallocGrowableArray<TestLibEntry>();
+ }
+ // If the test lib is already added, replace the source.
+ for (intptr_t i = 0; i < test_libs_->length(); i++) {
+ if (strcmp(url, (*test_libs_)[i].url) == 0) {
+ (*test_libs_)[i].source = source;
+ return;
+ }
+ }
+ TestLibEntry entry;
+ entry.url = url;
+ entry.source = source;
+ test_libs_->Add(entry);
}
-static Dart_Handle ImportableTestLibSource() {
- return DartUtils::NewString(importable_test_lib_script);
+const char* TestCase::GetTestLib(const char* url) {
+ if (test_libs_ == NULL) {
+ return NULL;
+ }
+ for (intptr_t i = 0; i < test_libs_->length(); i++) {
+ if (strcmp(url, (*test_libs_)[i].url) == 0) {
+ return (*test_libs_)[i].source;
+ }
+ }
+ return NULL;
}
-
#ifndef PRODUCT
static bool IsIsolateReloadTestLib(const char* url_name) {
const char* kIsolateReloadTestLibUri = "test:isolate_reload_helper";
@@ -204,8 +212,10 @@ static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
return DartUtils::NewError("Do not know how to load '%s'", url_chars);
}
}
- if (IsImportableTestLib(url_chars)) {
- return Dart_LoadLibrary(url, Dart_Null(), ImportableTestLibSource(), 0, 0);
+ const char* lib_source = TestCase::GetTestLib(url_chars);
+ if (lib_source != NULL) {
+ Dart_Handle source = Dart_NewStringFromCString(lib_source);
+ return Dart_LoadLibrary(url, Dart_Null(), source, 0, 0);
}
NOT_IN_PRODUCT(
if (IsIsolateReloadTestLib(url_chars)) {
« no previous file with comments | « runtime/vm/unit_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698