Chromium Code Reviews| Index: pkg/analyzer/test/reflective_tests.dart |
| diff --git a/pkg/analyzer/test/reflective_tests.dart b/pkg/analyzer/test/reflective_tests.dart |
| index 310e7d063d688e8cc04308a3b66cf69578f18331..51fa02ffc1a836c585a9ebc5bbd398ca73a0e996 100644 |
| --- a/pkg/analyzer/test/reflective_tests.dart |
| +++ b/pkg/analyzer/test/reflective_tests.dart |
| @@ -5,13 +5,19 @@ |
| library analyzer.test.reflective_tests; |
| import 'dart:async'; |
| -@MirrorsUsed(metaTargets: 'ReflectiveTest') |
| import 'dart:mirrors'; |
| import 'package:unittest/unittest.dart'; |
| /** |
| * A marker annotation used to annotate overridden test methods (so we cannot |
| + * rename them to `fail_`) which are expected to fail at `assert` in the |
| + * checked mode. |
| + */ |
| +const _AssertFailingTest assertFailingTest = const _AssertFailingTest(); |
| + |
| +/** |
| + * A marker annotation used to annotate overridden test methods (so we cannot |
| * rename them to `fail_`) which are expected to fail. |
| */ |
| const _FailingTest failingTest = const _FailingTest(); |
| @@ -23,6 +29,18 @@ const _FailingTest failingTest = const _FailingTest(); |
| const ReflectiveTest reflectiveTest = const ReflectiveTest(); |
| /** |
| + * Is `true` the application runs in the checked mode. |
|
Paul Berry
2016/04/29 17:57:31
s/runs/is running/
("runs" implies that the app "
scheglov
2016/04/29 18:04:07
Done.
Thanks!
|
| + */ |
| +final bool _isCheckedMode = () { |
| + try { |
| + assert(false); |
| + return false; |
| + } catch (_) { |
| + return true; |
| + } |
| +}(); |
| + |
| +/** |
| * Runs test methods existing in the given [type]. |
| * |
| * Methods with names starting with `test` are run using [test] function. |
| @@ -58,7 +76,8 @@ void runReflectiveTests(Type type) { |
| // test_ |
| if (memberName.startsWith('test_')) { |
| test(memberName, () { |
| - if (_hasFailingTestAnnotation(memberMirror)) { |
| + if (_hasFailingTestAnnotation(memberMirror) || |
| + _isCheckedMode && _hasAssertFailingTestAnnotation(memberMirror)) { |
| return _runFailingTest(classMirror, symbol); |
| } else { |
| return _runTest(classMirror, symbol); |
| @@ -88,10 +107,15 @@ void runReflectiveTests(Type type) { |
| }); |
| } |
| -bool _hasFailingTestAnnotation(MethodMirror method) { |
| - return method.metadata.any((InstanceMirror annotation) => |
| - annotation.type.reflectedType == _FailingTest); |
| -} |
| +bool _hasAnnotationInstance(DeclarationMirror declaration, instance) => |
| + declaration.metadata.any((InstanceMirror annotation) => |
| + identical(annotation.reflectee, instance)); |
| + |
| +bool _hasAssertFailingTestAnnotation(MethodMirror method) => |
| + _hasAnnotationInstance(method, assertFailingTest); |
| + |
| +bool _hasFailingTestAnnotation(MethodMirror method) => |
| + _hasAnnotationInstance(method, failingTest); |
| Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { |
| var invocationResult = null; |
| @@ -139,6 +163,15 @@ class ReflectiveTest { |
| /** |
| * A marker annotation used to annotate overridden test methods (so we cannot |
| + * rename them to `fail_`) which are expected to fail at `assert` in the |
| + * checked mode. |
| + */ |
| +class _AssertFailingTest { |
| + const _AssertFailingTest(); |
| +} |
| + |
| +/** |
| + * A marker annotation used to annotate overridden test methods (so we cannot |
| * rename them to `fail_`) which are expected to fail. |
| */ |
| class _FailingTest { |