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 analyzer.test.reflective_tests; | 5 library analyzer.test.reflective_tests; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 @MirrorsUsed(metaTargets: 'ReflectiveTest') | 8 @MirrorsUsed(metaTargets: 'ReflectiveTest') |
9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 * behavior, then `tearDown` will be invoked in `Future.complete`. | 58 * behavior, then `tearDown` will be invoked in `Future.complete`. |
59 */ | 59 */ |
60 void runReflectiveTests(Type type) { | 60 void runReflectiveTests(Type type) { |
61 ClassMirror classMirror = reflectClass(type); | 61 ClassMirror classMirror = reflectClass(type); |
62 if (!classMirror.metadata.any((InstanceMirror annotation) => | 62 if (!classMirror.metadata.any((InstanceMirror annotation) => |
63 annotation.type.reflectedType == ReflectiveTest)) { | 63 annotation.type.reflectedType == ReflectiveTest)) { |
64 String name = MirrorSystem.getName(classMirror.qualifiedName); | 64 String name = MirrorSystem.getName(classMirror.qualifiedName); |
65 throw new Exception('Class $name must have annotation "@reflectiveTest" ' | 65 throw new Exception('Class $name must have annotation "@reflectiveTest" ' |
66 'in order to be run by runReflectiveTests.'); | 66 'in order to be run by runReflectiveTests.'); |
67 } | 67 } |
68 String className = MirrorSystem.getName(classMirror.simpleName); | 68 void runMembers() { |
69 group(className, () { | |
70 classMirror.instanceMembers | 69 classMirror.instanceMembers |
71 .forEach((Symbol symbol, MethodMirror memberMirror) { | 70 .forEach((Symbol symbol, MethodMirror memberMirror) { |
72 // we need only methods | 71 // we need only methods |
73 if (memberMirror is! MethodMirror || !memberMirror.isRegularMethod) { | 72 if (memberMirror is! MethodMirror || !memberMirror.isRegularMethod) { |
74 return; | 73 return; |
75 } | 74 } |
76 String memberName = MirrorSystem.getName(symbol); | 75 String memberName = MirrorSystem.getName(symbol); |
77 // test_ | 76 // test_ |
78 if (memberName.startsWith('test_')) { | 77 if (memberName.startsWith('test_')) { |
79 test(memberName, () { | 78 test(memberName, () { |
(...skipping 18 matching lines...) Expand all Loading... |
98 return _runFailingTest(classMirror, symbol); | 97 return _runFailingTest(classMirror, symbol); |
99 }); | 98 }); |
100 } | 99 } |
101 // solo_fail_test_ | 100 // solo_fail_test_ |
102 if (memberName.startsWith('solo_fail_')) { | 101 if (memberName.startsWith('solo_fail_')) { |
103 solo_test(memberName, () { | 102 solo_test(memberName, () { |
104 return _runFailingTest(classMirror, symbol); | 103 return _runFailingTest(classMirror, symbol); |
105 }); | 104 }); |
106 } | 105 } |
107 }); | 106 }); |
108 }); | 107 } |
| 108 String className = MirrorSystem.getName(classMirror.simpleName); |
| 109 if (className.endsWith('SoloTest')) { |
| 110 solo_group(className, runMembers); |
| 111 } else { |
| 112 group(className, runMembers); |
| 113 } |
109 } | 114 } |
110 | 115 |
111 bool _hasAnnotationInstance(DeclarationMirror declaration, instance) => | 116 bool _hasAnnotationInstance(DeclarationMirror declaration, instance) => |
112 declaration.metadata.any((InstanceMirror annotation) => | 117 declaration.metadata.any((InstanceMirror annotation) => |
113 identical(annotation.reflectee, instance)); | 118 identical(annotation.reflectee, instance)); |
114 | 119 |
115 bool _hasAssertFailingTestAnnotation(MethodMirror method) => | 120 bool _hasAssertFailingTestAnnotation(MethodMirror method) => |
116 _hasAnnotationInstance(method, assertFailingTest); | 121 _hasAnnotationInstance(method, assertFailingTest); |
117 | 122 |
118 bool _hasFailingTestAnnotation(MethodMirror method) => | 123 bool _hasFailingTestAnnotation(MethodMirror method) => |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 const _AssertFailingTest(); | 176 const _AssertFailingTest(); |
172 } | 177 } |
173 | 178 |
174 /** | 179 /** |
175 * A marker annotation used to annotate overridden test methods (so we cannot | 180 * A marker annotation used to annotate overridden test methods (so we cannot |
176 * rename them to `fail_`) which are expected to fail. | 181 * rename them to `fail_`) which are expected to fail. |
177 */ | 182 */ |
178 class _FailingTest { | 183 class _FailingTest { |
179 const _FailingTest(); | 184 const _FailingTest(); |
180 } | 185 } |
OLD | NEW |