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

Side by Side Diff: runtime/tests/vm/dart/isolate_mirror_local_test.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
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 // Dart test program for checking implemention of MirrorSystem when 5 // Dart test program for checking implemention of MirrorSystem when
6 // inspecting the current isolate. 6 // inspecting the current isolate.
7 // 7 //
8 // VMOptions=--enable_type_checks 8 // VMOptions=--enable_type_checks
9 9
10 library isolate_mirror_local_test; 10 library isolate_mirror_local_test;
11 11
12 import 'dart:async';
12 import 'dart:isolate'; 13 import 'dart:isolate';
13 import 'dart:mirrors'; 14 import 'dart:mirrors';
14 15
15 ReceivePort exit_port; 16 ReceivePort exit_port;
16 Set expectedTests; 17 Set expectedTests;
17 18
18 void testDone(String test) { 19 void testDone(String test) {
19 if (!expectedTests.contains(test)) { 20 if (!expectedTests.contains(test)) {
20 throw "Unexpected test name '$test'"; 21 throw "Unexpected test name '$test'";
21 } 22 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 lib_mirror.invoke('function', [ 123 ]).then( 119 lib_mirror.invoke('function', [ 123 ]).then(
119 (InstanceMirror retval) { 120 (InstanceMirror retval) {
120 Expect.equals(123, global_var); 121 Expect.equals(123, global_var);
121 Expect.equals('int', retval.type.simpleName); 122 Expect.equals('int', retval.type.simpleName);
122 Expect.isTrue(retval.hasReflectee); 123 Expect.isTrue(retval.hasReflectee);
123 Expect.equals(124, retval.reflectee); 124 Expect.equals(124, retval.reflectee);
124 testDone('testRootLibraryMirror'); 125 testDone('testRootLibraryMirror');
125 }); 126 });
126 127
127 // Check that the members map is complete. 128 // Check that the members map is complete.
128 List keys = lib_mirror.members.keys; 129 List keys = lib_mirror.members.keys.toList();
129 sort(keys); 130 sort(keys);
130 Expect.equals('[' 131 Expect.equals('['
131 'FuncType, ' 132 'FuncType, '
132 'GenericClass, ' 133 'GenericClass, '
133 'MyClass, ' 134 'MyClass, '
134 'MyException, ' 135 'MyException, '
135 'MyInterface, ' 136 'MyInterface, '
136 'MySuperClass, ' 137 'MySuperClass, '
137 '_stringCompare, ' 138 '_stringCompare, '
138 'buildMethodString, ' 139 'buildMethodString, '
(...skipping 16 matching lines...) Expand all
155 'testIntegerInstanceMirror, ' 156 'testIntegerInstanceMirror, '
156 'testLibrariesMap, ' 157 'testLibrariesMap, '
157 'testMirrorErrors, ' 158 'testMirrorErrors, '
158 'testMirrorSystem, ' 159 'testMirrorSystem, '
159 'testNullInstanceMirror, ' 160 'testNullInstanceMirror, '
160 'testRootLibraryMirror, ' 161 'testRootLibraryMirror, '
161 'testStringInstanceMirror]', 162 'testStringInstanceMirror]',
162 '$keys'); 163 '$keys');
163 164
164 // Check that the classes map is complete. 165 // Check that the classes map is complete.
165 keys = lib_mirror.classes.keys; 166 keys = lib_mirror.classes.keys.toList();
166 sort(keys); 167 sort(keys);
167 Expect.equals('[' 168 Expect.equals('['
168 'FuncType, ' 169 'FuncType, '
169 'GenericClass, ' 170 'GenericClass, '
170 'MyClass, ' 171 'MyClass, '
171 'MyException, ' 172 'MyException, '
172 'MyInterface, ' 173 'MyInterface, '
173 'MySuperClass]', 174 'MySuperClass]',
174 '$keys'); 175 '$keys');
175 176
176 // Check that the functions map is complete. 177 // Check that the functions map is complete.
177 keys = lib_mirror.functions.keys; 178 keys = lib_mirror.functions.keys.toList();
178 sort(keys); 179 sort(keys);
179 Expect.equals('[' 180 Expect.equals('['
180 '_stringCompare, ' 181 '_stringCompare, '
181 'buildMethodString, ' 182 'buildMethodString, '
182 'buildVariableString, ' 183 'buildVariableString, '
183 'function, ' 184 'function, '
184 'main, ' 185 'main, '
185 'methodWithError, ' 186 'methodWithError, '
186 'methodWithException, ' 187 'methodWithException, '
187 'myVar, ' 188 'myVar, '
188 'myVar=, ' 189 'myVar=, '
189 'sort, ' 190 'sort, '
190 'testBoolInstanceMirror, ' 191 'testBoolInstanceMirror, '
191 'testCustomInstanceMirror, ' 192 'testCustomInstanceMirror, '
192 'testDone, ' 193 'testDone, '
193 'testIntegerInstanceMirror, ' 194 'testIntegerInstanceMirror, '
194 'testLibrariesMap, ' 195 'testLibrariesMap, '
195 'testMirrorErrors, ' 196 'testMirrorErrors, '
196 'testMirrorSystem, ' 197 'testMirrorSystem, '
197 'testNullInstanceMirror, ' 198 'testNullInstanceMirror, '
198 'testRootLibraryMirror, ' 199 'testRootLibraryMirror, '
199 'testStringInstanceMirror]', 200 'testStringInstanceMirror]',
200 '$keys'); 201 '$keys');
201 202
202 // Check that the getters map is complete. 203 // Check that the getters map is complete.
203 keys = lib_mirror.getters.keys; 204 keys = lib_mirror.getters.keys.toList();
204 sort(keys); 205 sort(keys);
205 Expect.equals('[myVar]', '$keys'); 206 Expect.equals('[myVar]', '$keys');
206 207
207 // Check that the setters map is complete. 208 // Check that the setters map is complete.
208 keys = lib_mirror.setters.keys; 209 keys = lib_mirror.setters.keys.toList();
209 sort(keys); 210 sort(keys);
210 Expect.equals('[myVar=]', '$keys'); 211 Expect.equals('[myVar=]', '$keys');
211 212
212 // Check that the variables map is complete. 213 // Check that the variables map is complete.
213 keys = lib_mirror.variables.keys; 214 keys = lib_mirror.variables.keys.toList();
214 sort(keys); 215 sort(keys);
215 Expect.equals('[' 216 Expect.equals('['
216 'exit_port, ' 217 'exit_port, '
217 'expectedTests, ' 218 'expectedTests, '
218 'final_global_var, ' 219 'final_global_var, '
219 'global_var, ' 220 'global_var, '
220 'myFunc]', 221 'myFunc]',
221 '$keys'); 222 '$keys');
222 223
223 ClassMirror cls_mirror = lib_mirror.members['MyClass']; 224 ClassMirror cls_mirror = lib_mirror.members['MyClass'];
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 452 }
452 453
453 void methodWithError() { 454 void methodWithError() {
454 // We get a parse error when we try to run this function. 455 // We get a parse error when we try to run this function.
455 +++; 456 +++;
456 } 457 }
457 458
458 void testMirrorErrors(MirrorSystem mirrors) { 459 void testMirrorErrors(MirrorSystem mirrors) {
459 LibraryMirror lib_mirror = mirrors.isolate.rootLibrary; 460 LibraryMirror lib_mirror = mirrors.isolate.rootLibrary;
460 461
461 Future<InstanceMirror> future = 462 lib_mirror.invoke('methodWithException', [])
462 lib_mirror.invoke('methodWithException', []); 463 .then((InstanceMirror retval) {
463 future.handleException( 464 // Should not reach here.
464 (MirroredError exc) { 465 Expect.isTrue(false);
465 Expect.isTrue(exc is MirroredUncaughtExceptionError); 466 })
467 .catchError((exc) {
468 Expect.isTrue(exc.error is MirroredUncaughtExceptionError);
466 Expect.equals('MyException', 469 Expect.equals('MyException',
467 exc.exception_mirror.type.simpleName); 470 exc.error.exception_mirror.type.simpleName);
468 Expect.equals('MyException: from methodWithException', 471 Expect.equals('MyException: from methodWithException',
469 exc.exception_string); 472 exc.error.exception_string);
470 Expect.isTrue(exc.stacktrace.toString().contains( 473 Expect.isTrue(exc.error.stacktrace.toString().contains(
471 'isolate_mirror_local_test.dart')); 474 'isolate_mirror_local_test.dart'));
472 testDone('testMirrorErrors1'); 475 testDone('testMirrorErrors1');
473 return true;
474 });
475 future.then(
476 (InstanceMirror retval) {
477 // Should not reach here.
478 Expect.isTrue(false);
479 }); 476 });
480 477
481 Future<InstanceMirror> future2 = 478 lib_mirror.invoke('methodWithError', [])
482 lib_mirror.invoke('methodWithError', []); 479 .then((InstanceMirror retval) {
483 future2.handleException( 480 // Should not reach here.
484 (MirroredError exc) { 481 Expect.isTrue(false);
485 Expect.isTrue(exc is MirroredCompilationError); 482 })
486 Expect.isTrue(exc.message.contains('unexpected token')); 483 .catchError((exc) {
487 testDone('testMirrorErrors2'); 484 Expect.isTrue(exc.error is MirroredCompilationError);
488 return true; 485 Expect.isTrue(exc.error.message.contains('unexpected token'));
489 }); 486 testDone('testMirrorErrors2');
490 future2.then( 487 });
491 (InstanceMirror retval) {
492 // Should not reach here.
493 Expect.isTrue(false);
494 });
495 488
496 // TODO(turnidge): When we call a method that doesn't exist, we 489 // TODO(turnidge): When we call a method that doesn't exist, we
497 // should probably call noSuchMethod(). I'm adding this test to 490 // should probably call noSuchMethod(). I'm adding this test to
498 // document the current behavior in the meantime. 491 // document the current behavior in the meantime.
499 Future<InstanceMirror> future3 = 492 lib_mirror.invoke('methodNotFound', [])
500 lib_mirror.invoke('methodNotFound', []); 493 .then((InstanceMirror retval) {
501 future3.handleException( 494 // Should not reach here.
502 (MirroredError exc) { 495 Expect.isTrue(false);
503 Expect.isTrue(exc is MirroredCompilationError); 496 })
504 Expect.isTrue(exc.message.contains( 497 .catchError((exc) {
505 "did not find top-level function 'methodNotFound'")); 498 Expect.isTrue(exc.error is MirroredCompilationError);
506 testDone('testMirrorErrors3'); 499 Expect.isTrue(exc.error.message.contains(
507 return true; 500 "did not find top-level function 'methodNotFound'"));
508 }); 501 testDone('testMirrorErrors3');
509 future3.then( 502 });
510 (InstanceMirror retval) {
511 // Should not reach here.
512 Expect.isTrue(false);
513 });
514 } 503 }
515 504
516 void main() { 505 void main() {
517 // When all of the expected tests complete, the exit_port is closed, 506 // When all of the expected tests complete, the exit_port is closed,
518 // allowing the program to terminate. 507 // allowing the program to terminate.
519 exit_port = new ReceivePort(); 508 exit_port = new ReceivePort();
520 expectedTests = new Set<String>.from(['testRootLibraryMirror', 509 expectedTests = new Set<String>.from(['testRootLibraryMirror',
521 'testLibrariesMap', 510 'testLibrariesMap',
522 'testMirrorSystem', 511 'testMirrorSystem',
523 'testIntegerInstanceMirror', 512 'testIntegerInstanceMirror',
524 'testStringInstanceMirror', 513 'testStringInstanceMirror',
525 'testBoolInstanceMirror', 514 'testBoolInstanceMirror',
526 'testNullInstanceMirror', 515 'testNullInstanceMirror',
527 'testCustomInstanceMirror', 516 'testCustomInstanceMirror',
528 'testMirrorErrors1', 517 'testMirrorErrors1',
529 'testMirrorErrors2', 518 'testMirrorErrors2',
530 'testMirrorErrors3']); 519 'testMirrorErrors3']);
531 520
532 // Test that an isolate can reflect on itself. 521 // Test that an isolate can reflect on itself.
533 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem); 522 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem);
534 523
535 testIntegerInstanceMirror(reflect(1001)); 524 testIntegerInstanceMirror(reflect(1001));
536 testStringInstanceMirror(reflect('This\nis\na\nString')); 525 testStringInstanceMirror(reflect('This\nis\na\nString'));
537 testBoolInstanceMirror(reflect(true)); 526 testBoolInstanceMirror(reflect(true));
538 testNullInstanceMirror(reflect(null)); 527 testNullInstanceMirror(reflect(null));
539 testCustomInstanceMirror(reflect(new MyClass(17))); 528 testCustomInstanceMirror(reflect(new MyClass(17)));
540 testMirrorErrors(currentMirrorSystem()); 529 testMirrorErrors(currentMirrorSystem());
541 } 530 }
OLDNEW
« no previous file with comments | « runtime/lib/timer_patch.dart ('k') | runtime/tests/vm/dart/isolate_unhandled_exception_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698