Skip to content

Commit

Permalink
Merge pull request #24 from MichaelRFairhurst/allow-skipping-tests
Browse files Browse the repository at this point in the history
Add support for skipping tests
  • Loading branch information
MichaelRFairhurst authored Sep 30, 2019
2 parents a6617e3 + 067ee54 commit 9c13ef0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
62 changes: 52 additions & 10 deletions lib/test_reflective_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const FailingTest failingTest = const FailingTest();
*/
const _ReflectiveTest reflectiveTest = const _ReflectiveTest();

/**
* A marker annotation used to annotate test methods that should be skipped.
*/
const SkippedTest skippedTest = const SkippedTest();

/**
* A marker annotation used to annotate "solo" groups and tests.
*/
Expand Down Expand Up @@ -115,14 +120,18 @@ void defineReflectiveTests(Type type) {
_hasAnnotationInstance(memberMirror, soloTest);
// test_
if (memberName.startsWith('test_')) {
group.addTest(isSolo, memberName, memberMirror, () {
if (_hasFailingTestAnnotation(memberMirror) ||
_isCheckedMode && _hasAssertFailingTestAnnotation(memberMirror)) {
return _runFailingTest(classMirror, symbol);
} else {
return _runTest(classMirror, symbol);
}
});
if (_hasSkippedTestAnnotation(memberMirror)) {
group.addSkippedTest(memberName);
} else {
group.addTest(isSolo, memberName, memberMirror, () {
if (_hasFailingTestAnnotation(memberMirror) ||
_isCheckedMode && _hasAssertFailingTestAnnotation(memberMirror)) {
return _runFailingTest(classMirror, symbol);
} else {
return _runTest(classMirror, symbol);
}
});
}
return;
}
// solo_test_
Expand All @@ -143,6 +152,10 @@ void defineReflectiveTests(Type type) {
return _runFailingTest(classMirror, symbol);
});
}
// skip_test_
if (memberName.startsWith('skip_test_')) {
group.addSkippedTest(memberName);
}
});

// Support for the case of missing enclosing [defineReflectiveSuite].
Expand All @@ -160,7 +173,7 @@ void _addTestsIfTopLevelSuite() {
for (_Test test in group.tests) {
if (allTests || test.isSolo) {
test_package.test(test.name, test.function,
timeout: test.timeout);
timeout: test.timeout, skip: test.isSkipped);
}
}
}
Expand Down Expand Up @@ -211,6 +224,9 @@ bool _hasAssertFailingTestAnnotation(MethodMirror method) =>
bool _hasFailingTestAnnotation(MethodMirror method) =>
_hasAnnotationInstance(method, failingTest);

bool _hasSkippedTestAnnotation(MethodMirror method) =>
_hasAnnotationInstance(method, skippedTest);

Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) {
var invocationResult = null;
InstanceMirror closure;
Expand Down Expand Up @@ -276,6 +292,19 @@ class FailingTest {
const FailingTest({String issue, String reason});
}

/**
* A marker annotation used to annotate test methods which are skipped.
*/
class SkippedTest {
/**
* Initialize this annotation with the given arguments.
*
* [issue] is a full URI describing the failure and used for tracking.
* [reason] is a free form textual description.
*/
const SkippedTest({String issue, String reason});
}

/**
* A marker annotation used to annotate test methods with additional timeout
* information.
Expand Down Expand Up @@ -309,6 +338,11 @@ class _Group {

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

void addSkippedTest(String name) {
String fullName = _combineNames(this.name, name);
tests.add(new _Test.skipped(isSolo, fullName));
}

void addTest(bool isSolo, String name, MethodMirror memberMirror,
_TestFunction function) {
String fullName = _combineNames(this.name, name);
Expand Down Expand Up @@ -341,5 +375,13 @@ class _Test {
final _TestFunction function;
final test_package.Timeout timeout;

_Test(this.isSolo, this.name, this.function, this.timeout);
final bool isSkipped;

_Test(this.isSolo, this.name, this.function, this.timeout)
: isSkipped = false;

_Test.skipped(this.isSolo, this.name)
: isSkipped = true,
function = null,
timeout = null;
}
10 changes: 10 additions & 0 deletions test/test_reflective_loader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,14 @@ class TestReflectiveLoaderTest {
Future test_fails_throws_async() {
return new Future.error('foo');
}

@skippedTest
void test_fails_but_skipped() {
throw 'foo';
}

@skippedTest
void test_times_out_but_skipped() {
while (true) {}
}
}

0 comments on commit 9c13ef0

Please sign in to comment.