Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike@mikegerwitz.com>2014-06-10 23:39:20 -0400
committerMike Gerwitz <mike@mikegerwitz.com>2014-06-11 00:23:54 -0400
commitc9b826d975771201b64078ba2946ef8f83d80062 (patch)
tree0ce6c8ce11e9c5085ea3563088c221c7e6402343
parent658fd29e0d3f5cc1807c00184ff53338885abc23 (diff)
downloadshspec-env.tar.gz
shspec-env.tar.bz2
shspec-env.zip
Environment expectations now permit omitting operatorenv
Export expectations will only succeed/fail based on flag checks, whereas the declare/set expectations will fail on value.
-rw-r--r--src/expect/env.sh7
-rw-r--r--test/test-expect-env39
2 files changed, 44 insertions, 2 deletions
diff --git a/src/expect/env.sh b/src/expect/env.sh
index 252c7f8..8523efa 100644
--- a/src/expect/env.sh
+++ b/src/expect/env.sh
@@ -56,6 +56,13 @@ __expect-env()
=|==|!=|-eq|-ne|-lt|-le|-gt|-ge)
test "$val" $cmp "$expect";;
+ # at this point, if we have succeeded in performing flag tests, then we
+ # will always pass; otherwise, if no such tests were performed, then we
+ # fall back to the conventional non-empty check
+ '')
+ test -n "$expflags" -o -n "$val";;
+
+ # TODO: provide error description
*) false;;
esac
}
diff --git a/test/test-expect-env b/test/test-expect-env
index 935f23b..e0f7d7c 100644
--- a/test/test-expect-env
+++ b/test/test-expect-env
@@ -24,7 +24,8 @@ declare -x -- var="val"
declare -x -- long="foo bar baz"
declare -x -- empty=""
declare -x -- one="1"
-declare -- nonexport=""'
+declare -- nonexport="moo"
+declare -- nonexport_empty=""'
declare curchk
@@ -213,9 +214,43 @@ for name in set declare export; do
if [ "$name" == export ]; then
it fails when variable is not exported
- expect setchk nonexport -z
+ expect setchk nonexport
to fail
end
+
+ describe in absence of any operator
+ it succeeds on exported, non-empty var
+ expect setchk var
+ to succeed
+ end
+
+ it succeeds on exported empty var
+ expect setchk empty
+ to succeed
+ end
+
+ it fails on non-exported, non-empty var
+ expect setchk nonexport
+ to fail
+ end
+
+ it fails on non-exported empty var
+ expect setchk nonexport_empty
+ to fail
+ end
+ end
+ else
+ describe in absence of any operator
+ it succeeds on non-empty string
+ expect setchk var
+ to succeed
+ end
+
+ it fails on empty string
+ expect setchk empty
+ to fail
+ end
+ end
fi
end
done