@@ -118,7 +118,7 @@ void defineReflectiveTests(Type type) {
118
118
_hasAnnotationInstance (memberMirror, soloTest);
119
119
// test_
120
120
if (memberName.startsWith ('test_' )) {
121
- group.addTest (isSolo, memberName, () {
121
+ group.addTest (isSolo, memberName, memberMirror, () {
122
122
if (_hasFailingTestAnnotation (memberMirror) ||
123
123
_isCheckedMode && _hasAssertFailingTestAnnotation (memberMirror)) {
124
124
return _runFailingTest (classMirror, symbol);
@@ -130,19 +130,19 @@ void defineReflectiveTests(Type type) {
130
130
}
131
131
// solo_test_
132
132
if (memberName.startsWith ('solo_test_' )) {
133
- group.addTest (true , memberName, () {
133
+ group.addTest (true , memberName, memberMirror, () {
134
134
return _runTest (classMirror, symbol);
135
135
});
136
136
}
137
137
// fail_test_
138
138
if (memberName.startsWith ('fail_' )) {
139
- group.addTest (isSolo, memberName, () {
139
+ group.addTest (isSolo, memberName, memberMirror, () {
140
140
return _runFailingTest (classMirror, symbol);
141
141
});
142
142
}
143
143
// solo_fail_test_
144
144
if (memberName.startsWith ('solo_fail_' )) {
145
- group.addTest (true , memberName, () {
145
+ group.addTest (true , memberName, memberMirror, () {
146
146
return _runFailingTest (classMirror, symbol);
147
147
});
148
148
}
@@ -162,7 +162,8 @@ void _addTestsIfTopLevelSuite() {
162
162
if (allGroups || group.isSolo) {
163
163
for (_Test test in group.tests) {
164
164
if (allTests || test.isSolo) {
165
- test_package.test (test.name, test.function);
165
+ test_package.test (test.name, test.function,
166
+ timeout: test.timeout);
166
167
}
167
168
}
168
169
}
@@ -194,6 +195,15 @@ String _combineNames(String base, String addition) {
194
195
}
195
196
}
196
197
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
+
197
207
bool _hasAnnotationInstance (DeclarationMirror declaration, instance) =>
198
208
declaration.metadata.any ((InstanceMirror annotation) =>
199
209
identical (annotation.reflectee, instance));
@@ -264,6 +274,16 @@ class _ReflectiveTest {
264
274
const _ReflectiveTest ();
265
275
}
266
276
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
+
267
287
/**
268
288
* A marker annotation used to annotate overridden test methods (so we cannot
269
289
* rename them to `fail_` ) which are expected to fail at `assert` in the
@@ -293,9 +313,11 @@ class _Group {
293
313
294
314
bool get hasSoloTest => tests.any ((test) => test.isSolo);
295
315
296
- void addTest (bool isSolo, String name, _TestFunction function) {
316
+ void addTest (bool isSolo, String name, MethodMirror memberMirror,
317
+ _TestFunction function) {
297
318
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));
299
321
}
300
322
}
301
323
@@ -313,6 +335,7 @@ class _Test {
313
335
final bool isSolo;
314
336
final String name;
315
337
final _TestFunction function;
338
+ final test_package.Timeout timeout;
316
339
317
- _Test (this .isSolo, this .name, this .function);
340
+ _Test (this .isSolo, this .name, this .function, this .timeout );
318
341
}
0 commit comments