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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 1569833003: Adds strict compilation flags to Dart_IsolateFlags (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, 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 #include "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "include/dart_api.h" 6 #include "include/dart_api.h"
7 #include "include/dart_mirrors_api.h" 7 #include "include/dart_mirrors_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "include/dart_tools_api.h" 9 #include "include/dart_tools_api.h"
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 3323 matching lines...) Expand 10 before | Expand all | Expand 10 after
3334 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, 3334 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL,
3335 reinterpret_cast<void*>(mydata), 3335 reinterpret_cast<void*>(mydata),
3336 &err); 3336 &err);
3337 EXPECT(isolate != NULL); 3337 EXPECT(isolate != NULL);
3338 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData())); 3338 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData()));
3339 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate))); 3339 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate)));
3340 Dart_ShutdownIsolate(); 3340 Dart_ShutdownIsolate();
3341 } 3341 }
3342 3342
3343 3343
3344 TEST_CASE(IsolateSetCheckedMode) { 3344 UNIT_TEST_CASE(IsolateSetCheckedMode) {
3345 const char* kScriptChars = 3345 const char* kScriptChars =
3346 "int bad1() {\n" 3346 "int bad1() {\n"
3347 " int foo = 'string';\n" 3347 " int foo = 'string';\n"
3348 " return foo;\n" 3348 " return foo;\n"
3349 "}\n" 3349 "}\n"
3350 "\n" 3350 "\n"
3351 "int good1() {\n" 3351 "int good1() {\n"
3352 " int five = 5;\n" 3352 " int five = 5;\n"
3353 " return five;" 3353 " return five;"
3354 "}\n"; 3354 "}\n";
3355 Dart_Handle result;
3356 3355
3357 // Create a test library and Load up a test script in it. 3356 // Create an isolate with checked mode flags.
3358 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 3357 Dart_IsolateFlags api_flags;
3359 result = Dart_IsolateSetStrictCompilation(true); 3358 api_flags.version = DART_FLAGS_CURRENT_VERSION;
3360 EXPECT_VALID(result); 3359 api_flags.enable_type_checks = true;
3360 api_flags.enable_asserts = true;
3361 api_flags.enable_error_on_bad_type = true;
3362 api_flags.enable_error_on_bad_override = true;
3361 3363
3362 result = Dart_Invoke(lib, NewString("bad1"), 0, NULL); 3364 char* err;
3363 EXPECT_ERROR(result, "Unhandled exception:\n" 3365 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL,
3364 "type 'String' is not a subtype of type 'int' of 'foo'"); 3366 bin::isolate_snapshot_buffer,
3367 &api_flags,
3368 NULL, &err);
3369 if (isolate == NULL) {
3370 OS::Print("Creation of isolate failed '%s'\n", err);
3371 free(err);
3372 }
3373 EXPECT(isolate != NULL);
3365 3374
3366 result = Dart_Invoke(lib, NewString("good1"), 0, NULL); 3375 {
3367 EXPECT_VALID(result); 3376 Dart_EnterScope();
3377 Dart_Handle url = NewString(TestCase::url());
3378 Dart_Handle source = NewString(kScriptChars);
3379 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler);
3380 EXPECT_VALID(result);
3381 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0);
3382 EXPECT_VALID(lib);
3383 result = Dart_FinalizeLoading(false);
3384 EXPECT_VALID(result);
3385 result = Dart_Invoke(lib, NewString("bad1"), 0, NULL);
3386 EXPECT_ERROR(result, "Unhandled exception:\n"
3387 "type 'String' is not a subtype of type 'int' of 'foo'");
3368 3388
3369 result = Dart_IsolateSetStrictCompilation(false); 3389 result = Dart_Invoke(lib, NewString("good1"), 0, NULL);
3370 EXPECT_ERROR(result, "Dart_IsolateSetStrictCompilation expects that the " 3390 EXPECT_VALID(result);
3371 "isolate has not yet compiled code."); 3391 Dart_ExitScope();
3392 }
3393
3394 EXPECT(isolate != NULL);
3395
3396 // Shutdown the isolate.
3397 Dart_ShutdownIsolate();
3372 } 3398 }
3373 3399
3374 3400
3375 TEST_CASE(DebugName) { 3401 TEST_CASE(DebugName) {
3376 Dart_Handle debug_name = Dart_DebugName(); 3402 Dart_Handle debug_name = Dart_DebugName();
3377 EXPECT_VALID(debug_name); 3403 EXPECT_VALID(debug_name);
3378 EXPECT(Dart_IsString(debug_name)); 3404 EXPECT(Dart_IsString(debug_name));
3379 } 3405 }
3380 3406
3381 3407
(...skipping 6178 matching lines...) Expand 10 before | Expand all | Expand 10 after
9560 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); 9586 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer);
9561 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); 9587 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer);
9562 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); 9588 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer);
9563 9589
9564 // Heartbeat test for new events. 9590 // Heartbeat test for new events.
9565 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); 9591 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer);
9566 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); 9592 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer);
9567 } 9593 }
9568 9594
9569 } // namespace dart 9595 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698