| 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)) {
|
|
|