Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(553)

Side by Side Diff: pkg/analyzer/test/reflective_tests.dart

Issue 1933283002: Add @assertFailingTest annotation support. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.reflective_tests; 5 library analyzer.test.reflective_tests;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 @MirrorsUsed(metaTargets: 'ReflectiveTest')
9 import 'dart:mirrors'; 8 import 'dart:mirrors';
10 9
11 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
12 11
13 /** 12 /**
14 * A marker annotation used to annotate overridden test methods (so we cannot 13 * A marker annotation used to annotate overridden test methods (so we cannot
14 * rename them to `fail_`) which are expected to fail at `assert` in the
15 * checked mode.
16 */
17 const _AssertFailingTest assertFailingTest = const _AssertFailingTest();
18
19 /**
20 * A marker annotation used to annotate overridden test methods (so we cannot
15 * rename them to `fail_`) which are expected to fail. 21 * rename them to `fail_`) which are expected to fail.
16 */ 22 */
17 const _FailingTest failingTest = const _FailingTest(); 23 const _FailingTest failingTest = const _FailingTest();
18 24
19 /** 25 /**
20 * A marker annotation used to instruct dart2js to keep reflection information 26 * A marker annotation used to instruct dart2js to keep reflection information
21 * for the annotated classes. 27 * for the annotated classes.
22 */ 28 */
23 const ReflectiveTest reflectiveTest = const ReflectiveTest(); 29 const ReflectiveTest reflectiveTest = const ReflectiveTest();
24 30
25 /** 31 /**
32 * 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!
33 */
34 final bool _isCheckedMode = () {
35 try {
36 assert(false);
37 return false;
38 } catch (_) {
39 return true;
40 }
41 }();
42
43 /**
26 * Runs test methods existing in the given [type]. 44 * Runs test methods existing in the given [type].
27 * 45 *
28 * Methods with names starting with `test` are run using [test] function. 46 * Methods with names starting with `test` are run using [test] function.
29 * Methods with names starting with `solo_test` are run using [solo_test] functi on. 47 * Methods with names starting with `solo_test` are run using [solo_test] functi on.
30 * 48 *
31 * Each method is run with a new instance of [type]. 49 * Each method is run with a new instance of [type].
32 * So, [type] should have a default constructor. 50 * So, [type] should have a default constructor.
33 * 51 *
34 * If [type] declares method `setUp`, it methods will be invoked before any test 52 * If [type] declares method `setUp`, it methods will be invoked before any test
35 * method invocation. 53 * method invocation.
(...skipping 15 matching lines...) Expand all
51 classMirror.instanceMembers 69 classMirror.instanceMembers
52 .forEach((Symbol symbol, MethodMirror memberMirror) { 70 .forEach((Symbol symbol, MethodMirror memberMirror) {
53 // we need only methods 71 // we need only methods
54 if (memberMirror is! MethodMirror || !memberMirror.isRegularMethod) { 72 if (memberMirror is! MethodMirror || !memberMirror.isRegularMethod) {
55 return; 73 return;
56 } 74 }
57 String memberName = MirrorSystem.getName(symbol); 75 String memberName = MirrorSystem.getName(symbol);
58 // test_ 76 // test_
59 if (memberName.startsWith('test_')) { 77 if (memberName.startsWith('test_')) {
60 test(memberName, () { 78 test(memberName, () {
61 if (_hasFailingTestAnnotation(memberMirror)) { 79 if (_hasFailingTestAnnotation(memberMirror) ||
80 _isCheckedMode && _hasAssertFailingTestAnnotation(memberMirror)) {
62 return _runFailingTest(classMirror, symbol); 81 return _runFailingTest(classMirror, symbol);
63 } else { 82 } else {
64 return _runTest(classMirror, symbol); 83 return _runTest(classMirror, symbol);
65 } 84 }
66 }); 85 });
67 return; 86 return;
68 } 87 }
69 // solo_test_ 88 // solo_test_
70 if (memberName.startsWith('solo_test_')) { 89 if (memberName.startsWith('solo_test_')) {
71 solo_test(memberName, () { 90 solo_test(memberName, () {
72 return _runTest(classMirror, symbol); 91 return _runTest(classMirror, symbol);
73 }); 92 });
74 } 93 }
75 // fail_test_ 94 // fail_test_
76 if (memberName.startsWith('fail_')) { 95 if (memberName.startsWith('fail_')) {
77 test(memberName, () { 96 test(memberName, () {
78 return _runFailingTest(classMirror, symbol); 97 return _runFailingTest(classMirror, symbol);
79 }); 98 });
80 } 99 }
81 // solo_fail_test_ 100 // solo_fail_test_
82 if (memberName.startsWith('solo_fail_')) { 101 if (memberName.startsWith('solo_fail_')) {
83 solo_test(memberName, () { 102 solo_test(memberName, () {
84 return _runFailingTest(classMirror, symbol); 103 return _runFailingTest(classMirror, symbol);
85 }); 104 });
86 } 105 }
87 }); 106 });
88 }); 107 });
89 } 108 }
90 109
91 bool _hasFailingTestAnnotation(MethodMirror method) { 110 bool _hasAnnotationInstance(DeclarationMirror declaration, instance) =>
92 return method.metadata.any((InstanceMirror annotation) => 111 declaration.metadata.any((InstanceMirror annotation) =>
93 annotation.type.reflectedType == _FailingTest); 112 identical(annotation.reflectee, instance));
94 } 113
114 bool _hasAssertFailingTestAnnotation(MethodMirror method) =>
115 _hasAnnotationInstance(method, assertFailingTest);
116
117 bool _hasFailingTestAnnotation(MethodMirror method) =>
118 _hasAnnotationInstance(method, failingTest);
95 119
96 Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { 120 Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) {
97 var invocationResult = null; 121 var invocationResult = null;
98 InstanceMirror closure; 122 InstanceMirror closure;
99 try { 123 try {
100 closure = instanceMirror.getField(symbol); 124 closure = instanceMirror.getField(symbol);
101 } on NoSuchMethodError {} 125 } on NoSuchMethodError {}
102 126
103 if (closure is ClosureMirror) { 127 if (closure is ClosureMirror) {
104 invocationResult = closure.apply([]).reflectee; 128 invocationResult = closure.apply([]).reflectee;
(...skipping 27 matching lines...) Expand all
132 /** 156 /**
133 * A marker annotation used to instruct dart2js to keep reflection information 157 * A marker annotation used to instruct dart2js to keep reflection information
134 * for the annotated classes. 158 * for the annotated classes.
135 */ 159 */
136 class ReflectiveTest { 160 class ReflectiveTest {
137 const ReflectiveTest(); 161 const ReflectiveTest();
138 } 162 }
139 163
140 /** 164 /**
141 * A marker annotation used to annotate overridden test methods (so we cannot 165 * A marker annotation used to annotate overridden test methods (so we cannot
166 * rename them to `fail_`) which are expected to fail at `assert` in the
167 * checked mode.
168 */
169 class _AssertFailingTest {
170 const _AssertFailingTest();
171 }
172
173 /**
174 * A marker annotation used to annotate overridden test methods (so we cannot
142 * rename them to `fail_`) which are expected to fail. 175 * rename them to `fail_`) which are expected to fail.
143 */ 176 */
144 class _FailingTest { 177 class _FailingTest {
145 const _FailingTest(); 178 const _FailingTest();
146 } 179 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698