Skip to content

Commit c2bb0c1

Browse files
Merge pull request dart-archive/test_reflective_loader#24 from MichaelRFairhurst/allow-skipping-tests
Add support for skipping tests
2 parents d30eec7 + e7b8234 commit c2bb0c1

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

pkgs/test_reflective_loader/lib/test_reflective_loader.dart

+52-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ const FailingTest failingTest = const FailingTest();
2626
*/
2727
const _ReflectiveTest reflectiveTest = const _ReflectiveTest();
2828

29+
/**
30+
* A marker annotation used to annotate test methods that should be skipped.
31+
*/
32+
const SkippedTest skippedTest = const SkippedTest();
33+
2934
/**
3035
* A marker annotation used to annotate "solo" groups and tests.
3136
*/
@@ -115,14 +120,18 @@ void defineReflectiveTests(Type type) {
115120
_hasAnnotationInstance(memberMirror, soloTest);
116121
// test_
117122
if (memberName.startsWith('test_')) {
118-
group.addTest(isSolo, memberName, memberMirror, () {
119-
if (_hasFailingTestAnnotation(memberMirror) ||
120-
_isCheckedMode && _hasAssertFailingTestAnnotation(memberMirror)) {
121-
return _runFailingTest(classMirror, symbol);
122-
} else {
123-
return _runTest(classMirror, symbol);
124-
}
125-
});
123+
if (_hasSkippedTestAnnotation(memberMirror)) {
124+
group.addSkippedTest(memberName);
125+
} else {
126+
group.addTest(isSolo, memberName, memberMirror, () {
127+
if (_hasFailingTestAnnotation(memberMirror) ||
128+
_isCheckedMode && _hasAssertFailingTestAnnotation(memberMirror)) {
129+
return _runFailingTest(classMirror, symbol);
130+
} else {
131+
return _runTest(classMirror, symbol);
132+
}
133+
});
134+
}
126135
return;
127136
}
128137
// solo_test_
@@ -143,6 +152,10 @@ void defineReflectiveTests(Type type) {
143152
return _runFailingTest(classMirror, symbol);
144153
});
145154
}
155+
// skip_test_
156+
if (memberName.startsWith('skip_test_')) {
157+
group.addSkippedTest(memberName);
158+
}
146159
});
147160

148161
// Support for the case of missing enclosing [defineReflectiveSuite].
@@ -160,7 +173,7 @@ void _addTestsIfTopLevelSuite() {
160173
for (_Test test in group.tests) {
161174
if (allTests || test.isSolo) {
162175
test_package.test(test.name, test.function,
163-
timeout: test.timeout);
176+
timeout: test.timeout, skip: test.isSkipped);
164177
}
165178
}
166179
}
@@ -211,6 +224,9 @@ bool _hasAssertFailingTestAnnotation(MethodMirror method) =>
211224
bool _hasFailingTestAnnotation(MethodMirror method) =>
212225
_hasAnnotationInstance(method, failingTest);
213226

227+
bool _hasSkippedTestAnnotation(MethodMirror method) =>
228+
_hasAnnotationInstance(method, skippedTest);
229+
214230
Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) {
215231
var invocationResult = null;
216232
InstanceMirror closure;
@@ -276,6 +292,19 @@ class FailingTest {
276292
const FailingTest({String issue, String reason});
277293
}
278294

295+
/**
296+
* A marker annotation used to annotate test methods which are skipped.
297+
*/
298+
class SkippedTest {
299+
/**
300+
* Initialize this annotation with the given arguments.
301+
*
302+
* [issue] is a full URI describing the failure and used for tracking.
303+
* [reason] is a free form textual description.
304+
*/
305+
const SkippedTest({String issue, String reason});
306+
}
307+
279308
/**
280309
* A marker annotation used to annotate test methods with additional timeout
281310
* information.
@@ -309,6 +338,11 @@ class _Group {
309338

310339
bool get hasSoloTest => tests.any((test) => test.isSolo);
311340

341+
void addSkippedTest(String name) {
342+
String fullName = _combineNames(this.name, name);
343+
tests.add(new _Test.skipped(isSolo, fullName));
344+
}
345+
312346
void addTest(bool isSolo, String name, MethodMirror memberMirror,
313347
_TestFunction function) {
314348
String fullName = _combineNames(this.name, name);
@@ -341,5 +375,13 @@ class _Test {
341375
final _TestFunction function;
342376
final test_package.Timeout timeout;
343377

344-
_Test(this.isSolo, this.name, this.function, this.timeout);
378+
final bool isSkipped;
379+
380+
_Test(this.isSolo, this.name, this.function, this.timeout)
381+
: isSkipped = false;
382+
383+
_Test.skipped(this.isSolo, this.name)
384+
: isSkipped = true,
385+
function = null,
386+
timeout = null;
345387
}

pkgs/test_reflective_loader/test/test_reflective_loader_test.dart

+10
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@ class TestReflectiveLoaderTest {
3535
Future test_fails_throws_async() {
3636
return new Future.error('foo');
3737
}
38+
39+
@skippedTest
40+
void test_fails_but_skipped() {
41+
throw 'foo';
42+
}
43+
44+
@skippedTest
45+
void test_times_out_but_skipped() {
46+
while (true) {}
47+
}
3848
}

0 commit comments

Comments
 (0)