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

Unified Diff: lib/src/frontend/expect.dart

Issue 2123353002: Add a skip parameter to expect(). (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/backend/invoker.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/frontend/expect.dart
diff --git a/lib/src/frontend/expect.dart b/lib/src/frontend/expect.dart
index 965aebde48ec29d7e9567059a8a1fff080c688b5..e992daf4579b628d48752d71162a5e1c3cc6b7d2 100644
--- a/lib/src/frontend/expect.dart
+++ b/lib/src/frontend/expect.dart
@@ -32,18 +32,45 @@ typedef String ErrorFormatter(
///
/// If the assertion fails a [TestFailure] is thrown.
///
+/// If [skip] is a String or `true`, the assertion is skipped. The arguments are
+/// still evaluated, but [actual] is not verified to match [matcher]. If
+/// [actual] is a [Future], the test won't complete until the future emits a
+/// value.
+///
+/// If [skip] is a string, it should explain why the assertion is skipped; this
+/// reason will be printed when running the test.
+///
/// In some cases extra diagnostic info can be produced on failure (for
/// example, stack traces on mismatched exceptions). To enable these,
/// [verbose] should be specified as `true`.
void expect(actual, matcher,
- {String reason, bool verbose: false, ErrorFormatter formatter}) {
+ {String reason, skip, bool verbose: false, ErrorFormatter formatter}) {
if (Invoker.current == null) {
throw new StateError("expect() may only be called within a test.");
}
if (Invoker.current.closed) throw new ClosedException();
+ if (skip != null && skip is! bool && skip is! String) {
+ throw new ArgumentError.value(skip, "skip", "must be a bool or a String");
+ }
+
matcher = wrapMatcher(matcher);
+ if (skip != null && skip != false) {
+ String message;
+ if (skip is String) {
+ message = "Skip expect: $skip";
+ } else if (reason != null) {
+ message = "Skip expect ($reason).";
+ } else {
+ var description = new StringDescription().addDescriptionOf(matcher);
+ message = "Skip expect ($description).";
+ }
+
+ Invoker.current.skip(message);
+ return;
+ }
+
var matchState = {};
try {
if (matcher.matches(actual, matchState)) return;
« no previous file with comments | « lib/src/backend/invoker.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698