From 683c4cc6914d1f71e90617c34ecb438b5cc356be Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 15 May 2014 00:45:49 -0400 Subject: [PATCH] Added `not' expectation Simply negates the result of whatever expectation it is given --- src/expect-core | 5 +++++ test/test-expect-core | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/expect-core b/src/expect-core index b2d2f49..ee40002 100644 --- a/src/expect-core +++ b/src/expect-core @@ -66,3 +66,8 @@ _expect--be() { _proxy-to "$@"; } _expect--succeed() { test "$1" -eq 0; } _expect--fail() { test "$1" -ne 0; } + +## +# Inverts the result of an expectation represented by the remainder clause +_expect--not() { ! _proxy-to "$@"; } + diff --git a/test/test-expect-core b/test/test-expect-core index bd06b78..a57f786 100644 --- a/test/test-expect-core +++ b/test/test-expect-core @@ -63,6 +63,19 @@ describe fail end +describe not + it will invert the result of an expectation + # exit code of 1, so normally `succeed' would fail + expect _expect--not 1 2 succeed + to succeed + + # exit code of 0, so normally `succeed' would succeed + expect _expect--not 0 2 succeed + to fail + end +end + + describe output it will default to asserting against stdout expect _expect--output 0 2 "test string" <<< "test string"