From 6dbf996f3ba248bddd0ec7f3bcaaab8f57509b3b Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Fri, 9 May 2014 01:13:26 -0400 Subject: [PATCH] Exit code now passed to expectation handlers --- src/expect-core | 4 ++-- src/spec | 11 +--------- test/test-expect-core | 47 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 test/test-expect-core diff --git a/src/expect-core b/src/expect-core index c52af18..dfad803 100644 --- a/src/expect-core +++ b/src/expect-core @@ -23,6 +23,6 @@ __INC_EXPECT_CORE=1 -_expect--succeed() { test "$(_spec-last-exit)" -eq 0; } -_expect--fail() { test "$(_spec-last-exit)" -ne 0; } +_expect--succeed() { test "$1" -eq 0; } +_expect--fail() { test "$1" -ne 0; } diff --git a/src/spec b/src/spec index c78ba21..b2d1a8d 100644 --- a/src/spec +++ b/src/spec @@ -167,8 +167,7 @@ to() type "$assert" &>/dev/null \ || _bail "unknown expectation: \`$type'" $__spec_caller - # invoke partially-applied assertion with remaining arguments - $assert "$@" || fail "$expect_full" + $assert "$__spec_rexit" "$@" || fail "$expect_full" __spec_caller= } @@ -214,11 +213,3 @@ _bail() exit 1 } - -## -# Retrieve the exit code of the most recently executed command -_spec-last-exit() -{ - echo "$__spec_rexit" -} - diff --git a/test/test-expect-core b/test/test-expect-core new file mode 100644 index 0000000..517e9d6 --- /dev/null +++ b/test/test-expect-core @@ -0,0 +1,47 @@ +#!/bin/bash +# Core expectation tests +# +# Copyright (C) 2014 Mike Gewitz +# +# This file is part of shspec. +# +# shspec is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +## + + +describe succeed + it will succeed when command exits with status code 0 + expect _expect--succeed 0 + to succeed + end + + it will fail when command exits with non-zero status code + expect _expect--succeed 1 + to fail + end +end + + +describe fail + it will succeed when command exits with non-zero status code + expect _expect--fail 1 + to succeed + end + + it will fail when command exits with status code 0 + expect _expect--fail 0 + to fail + end +end +