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

Side by Side Diff: runtime/vm/unit_test.h

Issue 10868043: Move print to corelib. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make it pass all tests. Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_UNIT_TEST_H_ 5 #ifndef VM_UNIT_TEST_H_
6 #define VM_UNIT_TEST_H_ 6 #define VM_UNIT_TEST_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 #include "vm/ast.h" 10 #include "vm/ast.h"
11 #include "vm/dart.h" 11 #include "vm/dart.h"
12 #include "vm/globals.h" 12 #include "vm/globals.h"
13 #include "vm/heap.h" 13 #include "vm/heap.h"
14 #include "vm/isolate.h" 14 #include "vm/isolate.h"
15 #include "vm/longjump.h" 15 #include "vm/longjump.h"
16 #include "vm/object.h" 16 #include "vm/object.h"
17 #include "vm/object_store.h" 17 #include "vm/object_store.h"
18 #include "vm/zone.h" 18 #include "vm/zone.h"
19 19
20 #define EXPECT_VALID(handle) \
21 do { \
22 Dart_Handle tmp_handle = (handle); \
23 if (Dart_IsError(tmp_handle)) { \
24 dart::Expect(__FILE__, __LINE__).Fail( \
25 "expected '%s' to be a valid handle but found an error handle:\n" \
26 " '%s'\n", \
27 #handle, Dart_GetError(tmp_handle)); \
28 } \
29 } while (0)
30
31 #define EXPECT_ERROR(handle, substring) \
32 do { \
33 Dart_Handle tmp_handle = (handle); \
34 if (Dart_IsError(tmp_handle)) { \
35 dart::Expect(__FILE__, __LINE__).IsSubstring((substring), \
36 Dart_GetError(tmp_handle)); \
37 } else { \
38 dart::Expect(__FILE__, __LINE__).Fail( \
39 "expected '%s' to be an error handle but found a valid handle.\n", \
40 #handle); \
41 } \
42 } while (0)
43
20 // The UNIT_TEST_CASE macro is used for tests that do not need any 44 // The UNIT_TEST_CASE macro is used for tests that do not need any
21 // default isolate or zone functionality. 45 // default isolate or zone functionality.
22 #define UNIT_TEST_CASE(name) \ 46 #define UNIT_TEST_CASE(name) \
23 void Dart_Test##name(); \ 47 void Dart_Test##name(); \
24 static const dart::TestCase kRegister##name(Dart_Test##name, #name); \ 48 static const dart::TestCase kRegister##name(Dart_Test##name, #name); \
25 void Dart_Test##name() 49 void Dart_Test##name()
26 50
27 // The TEST_CASE macro is used for tests that need an isolate and zone 51 // The TEST_CASE macro is used for tests that need an isolate and zone
28 // in order to test its functionality. 52 // in order to test its functionality.
29 #define TEST_CASE(name) \ 53 #define TEST_CASE(name) \
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 228
205 RunEntry* const run_; 229 RunEntry* const run_;
206 }; 230 };
207 231
208 232
209 class TestIsolateScope { 233 class TestIsolateScope {
210 public: 234 public:
211 TestIsolateScope() { 235 TestIsolateScope() {
212 isolate_ = reinterpret_cast<Isolate*>(TestCase::CreateTestIsolate()); 236 isolate_ = reinterpret_cast<Isolate*>(TestCase::CreateTestIsolate());
213 Dart_EnterScope(); // Create a Dart API scope for unit tests. 237 Dart_EnterScope(); // Create a Dart API scope for unit tests.
238 // 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.
239 const char* builtin_source =
240 "#library('dart:builtin');\n"
241 "void print(Object o) { }";
242 Dart_Handle coreimpl = Dart_LookupLibrary(Dart_NewString("dart:coreimpl"));
243 EXPECT_VALID(coreimpl);
244 Dart_Handle builtin = Dart_LoadLibrary(Dart_NewString("dart:builtin"),
245 Dart_NewString(builtin_source));
246 EXPECT_VALID(builtin);
247 Dart_Handle imported =
248 Dart_LibraryImportLibrary(coreimpl, builtin, Dart_NewString("builtin"));
249 EXPECT_VALID(imported);
214 } 250 }
215 ~TestIsolateScope() { 251 ~TestIsolateScope() {
216 Dart_ExitScope(); // Exit the Dart API scope created for unit tests. 252 Dart_ExitScope(); // Exit the Dart API scope created for unit tests.
217 ASSERT(isolate_ == Isolate::Current()); 253 ASSERT(isolate_ == Isolate::Current());
218 Dart_ShutdownIsolate(); 254 Dart_ShutdownIsolate();
219 isolate_ = NULL; 255 isolate_ = NULL;
220 } 256 }
221 Isolate* isolate() const { return isolate_; } 257 Isolate* isolate() const { return isolate_; }
222 258
223 private: 259 private:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 public: 318 public:
283 // Test the Compiler::CompileScript functionality by checking the return 319 // Test the Compiler::CompileScript functionality by checking the return
284 // value to see if no parse errors were reported. 320 // value to see if no parse errors were reported.
285 static bool TestCompileScript(const Library& library, const Script& script); 321 static bool TestCompileScript(const Library& library, const Script& script);
286 322
287 // Test the Compiler::CompileFunction functionality by checking the return 323 // Test the Compiler::CompileFunction functionality by checking the return
288 // value to see if no parse errors were reported. 324 // value to see if no parse errors were reported.
289 static bool TestCompileFunction(const Function& function); 325 static bool TestCompileFunction(const Function& function);
290 }; 326 };
291 327
292 #define EXPECT_VALID(handle) \
293 do { \
294 Dart_Handle tmp_handle = (handle); \
295 if (Dart_IsError(tmp_handle)) { \
296 dart::Expect(__FILE__, __LINE__).Fail( \
297 "expected '%s' to be a valid handle but found an error handle:\n" \
298 " '%s'\n", \
299 #handle, Dart_GetError(tmp_handle)); \
300 } \
301 } while (0)
302
303 #define EXPECT_ERROR(handle, substring) \
304 do { \
305 Dart_Handle tmp_handle = (handle); \
306 if (Dart_IsError(tmp_handle)) { \
307 dart::Expect(__FILE__, __LINE__).IsSubstring((substring), \
308 Dart_GetError(tmp_handle)); \
309 } else { \
310 dart::Expect(__FILE__, __LINE__).Fail( \
311 "expected '%s' to be an error handle but found a valid handle.\n", \
312 #handle); \
313 } \
314 } while (0)
315
316 } // namespace dart 328 } // namespace dart
317 329
318 #endif // VM_UNIT_TEST_H_ 330 #endif // VM_UNIT_TEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698