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: pkg/analysis_server/test/reflective_tests.dart

Issue 314413004: A simple B+Tree implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Better redistribution, random stress test, renames. Created 6 years, 6 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library reflective.tests; 5 library reflective.tests;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 @MirrorsUsed(metaTargets: 'ReflectiveTestCase') 9 @MirrorsUsed(metaTargets: 'ReflectiveTestCase')
10 import 'dart:mirrors'; 10 import 'dart:mirrors';
(...skipping 26 matching lines...) Expand all
37 * method invocation. If method returns [Future] to test some asyncronous 37 * method invocation. If method returns [Future] to test some asyncronous
38 * behavior, then `tearDown` will be invoked in `Future.complete`. 38 * behavior, then `tearDown` will be invoked in `Future.complete`.
39 */ 39 */
40 void runReflectiveTests(Type type) { 40 void runReflectiveTests(Type type) {
41 ClassMirror classMirror = reflectClass(type); 41 ClassMirror classMirror = reflectClass(type);
42 classMirror.instanceMembers.forEach((symbol, memberMirror) { 42 classMirror.instanceMembers.forEach((symbol, memberMirror) {
43 // we need only methods 43 // we need only methods
44 if (memberMirror is! MethodMirror || !memberMirror.isRegularMethod) { 44 if (memberMirror is! MethodMirror || !memberMirror.isRegularMethod) {
45 return; 45 return;
46 } 46 }
47 // check name
48 String memberName = MirrorSystem.getName(symbol); 47 String memberName = MirrorSystem.getName(symbol);
48 // test_
49 if (memberName.startsWith('test_')) { 49 if (memberName.startsWith('test_')) {
50 String testName = memberName.substring('test_'.length); 50 String testName = memberName.substring('test_'.length);
51 test(testName, () { 51 test(testName, () {
52 InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []); 52 _runTest(classMirror, symbol);
53 _invokeSymbolIfExists(instanceMirror, #setUp); 53 });
54 var testReturn = instanceMirror.invoke(symbol, []).reflectee; 54 return;
55 if (testReturn is Future) { 55 }
56 return testReturn.whenComplete(() { 56 // solo_test_
57 _invokeSymbolIfExists(instanceMirror, #tearDown); 57 if (memberName.startsWith('solo_test_')) {
58 }); 58 String testName = memberName.substring('solo_test_'.length);
59 } else { 59 solo_test(testName, () {
60 _invokeSymbolIfExists(instanceMirror, #tearDown); 60 _runTest(classMirror, symbol);
61 return testReturn;
62 }
63 }); 61 });
64 } 62 }
65 }); 63 });
66 } 64 }
67 65
66 void _runTest(ClassMirror classMirror, Symbol symbol) {
67 InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []);
68 _invokeSymbolIfExists(instanceMirror, #setUp);
69 var testReturn = instanceMirror.invoke(symbol, []).reflectee;
70 if (testReturn is Future) {
71 return testReturn.whenComplete(() {
72 _invokeSymbolIfExists(instanceMirror, #tearDown);
73 });
74 } else {
75 _invokeSymbolIfExists(instanceMirror, #tearDown);
76 return testReturn;
77 }
78 }
79
68 80
69 void _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { 81 void _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) {
70 try { 82 try {
71 instanceMirror.invoke(symbol, []); 83 instanceMirror.invoke(symbol, []);
72 } on NoSuchMethodError catch (e) { 84 } on NoSuchMethodError catch (e) {
73 } 85 }
74 } 86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698