Chromium Code Reviews| Index: runtime/vm/unit_test.h |
| diff --git a/runtime/vm/unit_test.h b/runtime/vm/unit_test.h |
| index 22860023b95e9cecd72b702f37df5b014735ae6d..ef4386f089a85c326ba421802de1b74008494953 100644 |
| --- a/runtime/vm/unit_test.h |
| +++ b/runtime/vm/unit_test.h |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| @@ -17,6 +17,30 @@ |
| #include "vm/object_store.h" |
| #include "vm/zone.h" |
| +#define EXPECT_VALID(handle) \ |
| + do { \ |
| + Dart_Handle tmp_handle = (handle); \ |
| + if (Dart_IsError(tmp_handle)) { \ |
| + dart::Expect(__FILE__, __LINE__).Fail( \ |
| + "expected '%s' to be a valid handle but found an error handle:\n" \ |
| + " '%s'\n", \ |
| + #handle, Dart_GetError(tmp_handle)); \ |
| + } \ |
| + } while (0) |
| + |
| +#define EXPECT_ERROR(handle, substring) \ |
| + do { \ |
| + Dart_Handle tmp_handle = (handle); \ |
| + if (Dart_IsError(tmp_handle)) { \ |
| + dart::Expect(__FILE__, __LINE__).IsSubstring((substring), \ |
| + Dart_GetError(tmp_handle)); \ |
| + } else { \ |
| + dart::Expect(__FILE__, __LINE__).Fail( \ |
| + "expected '%s' to be an error handle but found a valid handle.\n", \ |
| + #handle); \ |
| + } \ |
| + } while (0) |
| + |
| // The UNIT_TEST_CASE macro is used for tests that do not need any |
| // default isolate or zone functionality. |
| #define UNIT_TEST_CASE(name) \ |
| @@ -211,6 +235,18 @@ class TestIsolateScope { |
| TestIsolateScope() { |
| isolate_ = reinterpret_cast<Isolate*>(TestCase::CreateTestIsolate()); |
| Dart_EnterScope(); // Create a Dart API scope for unit tests. |
| + // Setup dummy builtin library for 'print'. |
|
Anders Johnsen
2012/08/28 13:53:10
Just so I get this right, these test depends on 'p
Mads Ager (google)
2012/08/28 13:57:29
Some of these tests use the CompileAll call that w
Anders Johnsen
2012/08/28 14:01:09
Thank you, I understand now.
|
| + const char* builtin_source = |
| + "#library('dart:builtin');\n" |
| + "void print(Object o) { }"; |
| + Dart_Handle coreimpl = Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); |
| + EXPECT_VALID(coreimpl); |
| + Dart_Handle builtin = Dart_LoadLibrary(Dart_NewString("dart:builtin"), |
| + Dart_NewString(builtin_source)); |
| + EXPECT_VALID(builtin); |
| + Dart_Handle imported = |
| + Dart_LibraryImportLibrary(coreimpl, builtin, Dart_NewString("builtin")); |
| + EXPECT_VALID(imported); |
| } |
| ~TestIsolateScope() { |
| Dart_ExitScope(); // Exit the Dart API scope created for unit tests. |
| @@ -289,30 +325,6 @@ class CompilerTest : public AllStatic { |
| static bool TestCompileFunction(const Function& function); |
| }; |
| -#define EXPECT_VALID(handle) \ |
| - do { \ |
| - Dart_Handle tmp_handle = (handle); \ |
| - if (Dart_IsError(tmp_handle)) { \ |
| - dart::Expect(__FILE__, __LINE__).Fail( \ |
| - "expected '%s' to be a valid handle but found an error handle:\n" \ |
| - " '%s'\n", \ |
| - #handle, Dart_GetError(tmp_handle)); \ |
| - } \ |
| - } while (0) |
| - |
| -#define EXPECT_ERROR(handle, substring) \ |
| - do { \ |
| - Dart_Handle tmp_handle = (handle); \ |
| - if (Dart_IsError(tmp_handle)) { \ |
| - dart::Expect(__FILE__, __LINE__).IsSubstring((substring), \ |
| - Dart_GetError(tmp_handle)); \ |
| - } else { \ |
| - dart::Expect(__FILE__, __LINE__).Fail( \ |
| - "expected '%s' to be an error handle but found a valid handle.\n", \ |
| - #handle); \ |
| - } \ |
| - } while (0) |
| - |
| } // namespace dart |
| #endif // VM_UNIT_TEST_H_ |