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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/reflective_tests.dart
diff --git a/pkg/analyzer/test/reflective_tests.dart b/pkg/analyzer/test/reflective_tests.dart
index ec90c28acef2125322660103a48745b25547fb6b..a48c962f95fd4155f539008c60b4aa0d0c4591bd 100644
--- a/pkg/analyzer/test/reflective_tests.dart
+++ b/pkg/analyzer/test/reflective_tests.dart
@@ -49,11 +49,22 @@ void runReflectiveTests(Type type) {
return _runTest(classMirror, symbol);
});
}
+ // fail_test_
+ if (memberName.startsWith('fail_')) {
+ test(memberName, () {
+ return _runFailingTest(classMirror, symbol);
+ });
+ }
+ // solo_fail_test_
+ if (memberName.startsWith('solo_fail_')) {
+ solo_test(memberName, () {
+ return _runFailingTest(classMirror, symbol);
+ });
+ }
});
});
}
-
Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) {
var invocationResult = null;
try {
@@ -68,6 +79,23 @@ Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) {
}
+/**
+ * Run a test that is expected to fail, and confirm that it fails.
+ *
+ * This properly handles the following cases:
+ * - The test fails by throwing an exception
+ * - The test returns a future which completes with an error.
+ *
+ * However, it does not handle the case where the test creates an asynchronous
+ * callback using expectAsync(), and that callback generates a failure.
+ */
+Future _runFailingTest(ClassMirror classMirror, Symbol symbol) {
+ return new Future(() => _runTest(classMirror, symbol)).then((_) {
+ fail('Test passed - expected to fail.');
+ }, onError: (_) {});
+}
+
+
_runTest(ClassMirror classMirror, Symbol symbol) {
InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []);
return _invokeSymbolIfExists(
« 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