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

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

Issue 790553002: Handle "fail_" style tests in reflective tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | Annotate | Revision Log
« 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 reflective_tests; 5 library reflective_tests;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:mirrors'; 8 import 'dart:mirrors';
9 9
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 return _runTest(classMirror, symbol); 42 return _runTest(classMirror, symbol);
43 }); 43 });
44 return; 44 return;
45 } 45 }
46 // solo_test_ 46 // solo_test_
47 if (memberName.startsWith('solo_test_')) { 47 if (memberName.startsWith('solo_test_')) {
48 solo_test(memberName, () { 48 solo_test(memberName, () {
49 return _runTest(classMirror, symbol); 49 return _runTest(classMirror, symbol);
50 }); 50 });
51 } 51 }
52 // fail_test_
53 if (memberName.startsWith('fail_')) {
54 test(memberName, () {
55 return _runFailingTest(classMirror, symbol);
56 });
57 }
58 // solo_fail_test_
59 if (memberName.startsWith('solo_fail_')) {
60 solo_test(memberName, () {
61 return _runFailingTest(classMirror, symbol);
62 });
63 }
52 }); 64 });
53 }); 65 });
54 } 66 }
55 67
56
57 Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { 68 Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) {
58 var invocationResult = null; 69 var invocationResult = null;
59 try { 70 try {
60 invocationResult = instanceMirror.invoke(symbol, []).reflectee; 71 invocationResult = instanceMirror.invoke(symbol, []).reflectee;
61 } on NoSuchMethodError catch (e) { 72 } on NoSuchMethodError catch (e) {
62 } 73 }
63 if (invocationResult is Future) { 74 if (invocationResult is Future) {
64 return invocationResult; 75 return invocationResult;
65 } else { 76 } else {
66 return new Future.value(invocationResult); 77 return new Future.value(invocationResult);
67 } 78 }
68 } 79 }
69 80
70 81
82 /**
83 * Run a test that is expected to fail, and confirm that it fails.
84 *
85 * This properly handles the following cases:
86 * - The test fails by throwing an exception
87 * - The test returns a future which completes with an error.
88 *
89 * However, it does not handle the case where the test creates an asynchronous
90 * callback using expectAsync(), and that callback generates a failure.
91 */
92 Future _runFailingTest(ClassMirror classMirror, Symbol symbol) {
93 return new Future(() => _runTest(classMirror, symbol)).then((_) {
94 fail('Test passed - expected to fail.');
95 }, onError: (_) {});
96 }
97
98
71 _runTest(ClassMirror classMirror, Symbol symbol) { 99 _runTest(ClassMirror classMirror, Symbol symbol) {
72 InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []); 100 InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []);
73 return _invokeSymbolIfExists( 101 return _invokeSymbolIfExists(
74 instanceMirror, 102 instanceMirror,
75 #setUp).then( 103 #setUp).then(
76 (_) => 104 (_) =>
77 instanceMirror.invoke( 105 instanceMirror.invoke(
78 symbol, 106 symbol,
79 [ 107 [
80 ]).reflectee).whenComplete( 108 ]).reflectee).whenComplete(
81 () => _invokeSymbolIfExists(instanceMirror, #tearDown) ); 109 () => _invokeSymbolIfExists(instanceMirror, #tearDown) );
82 } 110 }
83 111
84 112
85 /** 113 /**
86 * A marker annotation used to instruct dart2js to keep reflection information 114 * A marker annotation used to instruct dart2js to keep reflection information
87 * for the annotated classes. 115 * for the annotated classes.
88 */ 116 */
89 class ReflectiveTestCase { 117 class ReflectiveTestCase {
90 const ReflectiveTestCase(); 118 const ReflectiveTestCase();
91 } 119 }
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