Skip to content

Commit

Permalink
Merge pull request flutter#10 from dart-lang/failingTest-fail-when-pass
Browse files Browse the repository at this point in the history
Fail @failingTest when the test passes.
  • Loading branch information
scheglov authored Dec 8, 2017
2 parents 3bea04c + f4861b2 commit f012537
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.3

- Fix `@failingTest` to fail when the test passes.

## 0.1.2

- Update the pubspec `dependencies` section to include `package:test`
Expand Down
14 changes: 12 additions & 2 deletions lib/test_reflective_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,24 @@ Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) {
* - An exception is thrown to the zone handler from a timer task.
*/
Future _runFailingTest(ClassMirror classMirror, Symbol symbol) {
bool passed = false;
return runZoned(() {
return new Future.sync(() => _runTest(classMirror, symbol)).then((_) {
passed = true;
test_package.fail('Test passed - expected to fail.');
}).catchError((e) {
// an exception is not a failure for _runFailingTest
// if passed, and we call fail(), rethrow this exception
if (passed) {
throw e;
}
// otherwise, an exception is not a failure for _runFailingTest
});
}, onError: (e) {
// an exception is not a failure for _runFailingTest
// if passed, and we call fail(), rethrow this exception
if (passed) {
throw e;
}
// otherwise, an exception is not a failure for _runFailingTest
});
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test_reflective_loader
version: 0.1.2
version: 0.1.3
description: Support for discovering tests and test suites using reflection.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/test_reflective_loader
Expand Down

0 comments on commit f012537

Please sign in to comment.