From f4861b27c9be9d51dde5a0042448af4199f755f1 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Fri, 8 Dec 2017 10:35:48 -0800 Subject: [PATCH] Fail @failingTest when the test passes. --- CHANGELOG.md | 4 ++++ lib/test_reflective_loader.dart | 14 ++++++++++++-- pubspec.yaml | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59b2b0093a906..6e5b8519c45e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/lib/test_reflective_loader.dart b/lib/test_reflective_loader.dart index c833e61032bca..9ebaf84e44604 100644 --- a/lib/test_reflective_loader.dart +++ b/lib/test_reflective_loader.dart @@ -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 }); } diff --git a/pubspec.yaml b/pubspec.yaml index 73e6d63d71551..1360d687b7c79 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 homepage: https://github.com/dart-lang/test_reflective_loader