| OLD | NEW |
| 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 @MirrorsUsed(metaTargets: 'ReflectiveTestCase') | 7 @MirrorsUsed(metaTargets: 'ReflectiveTestCase') |
| 8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * | 22 * |
| 23 * If [type] declares method `setUp`, it methods will be invoked before any test | 23 * If [type] declares method `setUp`, it methods will be invoked before any test |
| 24 * method invocation. | 24 * method invocation. |
| 25 * | 25 * |
| 26 * If [type] declares method `tearDown`, it will be invoked after any test | 26 * If [type] declares method `tearDown`, it will be invoked after any test |
| 27 * method invocation. If method returns [Future] to test some asyncronous | 27 * method invocation. If method returns [Future] to test some asyncronous |
| 28 * behavior, then `tearDown` will be invoked in `Future.complete`. | 28 * behavior, then `tearDown` will be invoked in `Future.complete`. |
| 29 */ | 29 */ |
| 30 void runReflectiveTests(Type type) { | 30 void runReflectiveTests(Type type) { |
| 31 ClassMirror classMirror = reflectClass(type); | 31 ClassMirror classMirror = reflectClass(type); |
| 32 if (!classMirror.metadata.any( |
| 33 (InstanceMirror annotation) => |
| 34 annotation.type.reflectedType == ReflectiveTestCase)) { |
| 35 String name = MirrorSystem.getName(classMirror.qualifiedName); |
| 36 throw new Exception( |
| 37 'Class $name must have annotation "@ReflectiveTestCase()" ' |
| 38 'in order to be run by runReflectiveTests.'); |
| 39 } |
| 32 String className = MirrorSystem.getName(classMirror.simpleName); | 40 String className = MirrorSystem.getName(classMirror.simpleName); |
| 33 group(className, () { | 41 group(className, () { |
| 34 classMirror.instanceMembers.forEach((symbol, memberMirror) { | 42 classMirror.instanceMembers.forEach((symbol, memberMirror) { |
| 35 // we need only methods | 43 // we need only methods |
| 36 if (memberMirror is! MethodMirror || !memberMirror.isRegularMethod) { | 44 if (memberMirror is! MethodMirror || !memberMirror.isRegularMethod) { |
| 37 return; | 45 return; |
| 38 } | 46 } |
| 39 String memberName = MirrorSystem.getName(symbol); | 47 String memberName = MirrorSystem.getName(symbol); |
| 40 // test_ | 48 // test_ |
| 41 if (memberName.startsWith('test_')) { | 49 if (memberName.startsWith('test_')) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 120 } |
| 113 | 121 |
| 114 | 122 |
| 115 /** | 123 /** |
| 116 * A marker annotation used to instruct dart2js to keep reflection information | 124 * A marker annotation used to instruct dart2js to keep reflection information |
| 117 * for the annotated classes. | 125 * for the annotated classes. |
| 118 */ | 126 */ |
| 119 class ReflectiveTestCase { | 127 class ReflectiveTestCase { |
| 120 const ReflectiveTestCase(); | 128 const ReflectiveTestCase(); |
| 121 } | 129 } |
| OLD | NEW |