@@ -118,7 +118,7 @@ void defineReflectiveTests(Type type) {
118118 _hasAnnotationInstance (memberMirror, soloTest);
119119 // test_
120120 if (memberName.startsWith ('test_' )) {
121- group.addTest (isSolo, memberName, () {
121+ group.addTest (isSolo, memberName, memberMirror, () {
122122 if (_hasFailingTestAnnotation (memberMirror) ||
123123 _isCheckedMode && _hasAssertFailingTestAnnotation (memberMirror)) {
124124 return _runFailingTest (classMirror, symbol);
@@ -130,19 +130,19 @@ void defineReflectiveTests(Type type) {
130130 }
131131 // solo_test_
132132 if (memberName.startsWith ('solo_test_' )) {
133- group.addTest (true , memberName, () {
133+ group.addTest (true , memberName, memberMirror, () {
134134 return _runTest (classMirror, symbol);
135135 });
136136 }
137137 // fail_test_
138138 if (memberName.startsWith ('fail_' )) {
139- group.addTest (isSolo, memberName, () {
139+ group.addTest (isSolo, memberName, memberMirror, () {
140140 return _runFailingTest (classMirror, symbol);
141141 });
142142 }
143143 // solo_fail_test_
144144 if (memberName.startsWith ('solo_fail_' )) {
145- group.addTest (true , memberName, () {
145+ group.addTest (true , memberName, memberMirror, () {
146146 return _runFailingTest (classMirror, symbol);
147147 });
148148 }
@@ -162,7 +162,8 @@ void _addTestsIfTopLevelSuite() {
162162 if (allGroups || group.isSolo) {
163163 for (_Test test in group.tests) {
164164 if (allTests || test.isSolo) {
165- test_package.test (test.name, test.function);
165+ test_package.test (test.name, test.function,
166+ timeout: test.timeout);
166167 }
167168 }
168169 }
@@ -194,6 +195,15 @@ String _combineNames(String base, String addition) {
194195 }
195196}
196197
198+ Object _getAnnotationInstance (DeclarationMirror declaration, Type type) {
199+ for (InstanceMirror annotation in declaration.metadata) {
200+ if (annotation.reflectee.runtimeType == type) {
201+ return annotation.reflectee;
202+ }
203+ }
204+ return null ;
205+ }
206+
197207bool _hasAnnotationInstance (DeclarationMirror declaration, instance) =>
198208 declaration.metadata.any ((InstanceMirror annotation) =>
199209 identical (annotation.reflectee, instance));
@@ -264,6 +274,16 @@ class _ReflectiveTest {
264274 const _ReflectiveTest ();
265275}
266276
277+ /**
278+ * A marker annotation used to annotate test methods with additional timeout
279+ * information.
280+ */
281+ class TestTimeout {
282+ final test_package.Timeout timeout;
283+
284+ const TestTimeout (this .timeout);
285+ }
286+
267287/**
268288 * A marker annotation used to annotate overridden test methods (so we cannot
269289 * rename them to `fail_` ) which are expected to fail at `assert` in the
@@ -293,9 +313,11 @@ class _Group {
293313
294314 bool get hasSoloTest => tests.any ((test) => test.isSolo);
295315
296- void addTest (bool isSolo, String name, _TestFunction function) {
316+ void addTest (bool isSolo, String name, MethodMirror memberMirror,
317+ _TestFunction function) {
297318 String fullName = _combineNames (this .name, name);
298- tests.add (new _Test (isSolo, fullName, function));
319+ TestTimeout timeout = _getAnnotationInstance (memberMirror, TestTimeout );
320+ tests.add (new _Test (isSolo, fullName, function, timeout? .timeout));
299321 }
300322}
301323
@@ -313,6 +335,7 @@ class _Test {
313335 final bool isSolo;
314336 final String name;
315337 final _TestFunction function;
338+ final test_package.Timeout timeout;
316339
317- _Test (this .isSolo, this .name, this .function);
340+ _Test (this .isSolo, this .name, this .function, this .timeout );
318341}
0 commit comments