From 331a1161b294fa44b72331eec0bd0fcfe7b87a9f Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 10 Jun 2014 22:12:09 -0400 Subject: [PATCH] Added `declare` as an alias for `set` expectation --- src/expect/env.sh | 9 ++ test/test-expect-env | 338 ++++++++++++++++++++++--------------------- 2 files changed, 181 insertions(+), 166 deletions(-) diff --git a/src/expect/env.sh b/src/expect/env.sh index 771d0c6..cedaf9a 100644 --- a/src/expect/env.sh +++ b/src/expect/env.sh @@ -64,3 +64,12 @@ _expect--set() esac } + +## +# Alias for `set` +# +_expect--declare() +{ + _expect--set "$@" +} + diff --git a/test/test-expect-env b/test/test-expect-env index e5fb3be..dcb79b0 100644 --- a/test/test-expect-env +++ b/test/test-expect-env @@ -26,182 +26,188 @@ declare -- empty="" declare -- one="1"' +declare curchk function setchk() { - _expect--set 0 4 <(:) <( echo "$stubenv" ) "$@" + _expect--$curchk 0 4 <(:) <( echo "$stubenv" ) "$@" } -describe set - describe = and == operators - it succeeds on string equality - expect setchk var = val - to succeed +for name in set declare; do + curchk=$name - expect setchk var == val - to succeed + describe set + describe = and == operators + it succeeds on string equality + expect setchk var = val + to succeed + + expect setchk var == val + to succeed + end + + it fails on string inequality + expect setchk var = unval + to fail + + expect setchk var == unval + to fail + end end - it fails on string inequality - expect setchk var = unval - to fail - expect setchk var == unval + describe != operator + it succeeds on string inequality + expect setchk var != foo + to succeed + end + + it fails on string equality + expect setchk var != val + to fail + end + end + + + describe =~ operator + it succeeds on a match + expect setchk \ + long =~ fo+ ba. baz\$ + to succeed + end + + # note that this also ensures that *all* arguments are part of the + # match + it fails on a mismatch + expect setchk \ + long =~ fo+ baX baz\$ + to fail + end + end + + + describe -n operator + it succeeds when string is non-empty + expect setchk var -n + to succeed + end + + it fails when string is empty + expect setchk empty -n + to fail + end + end + + + describe -z operator + it succeeds when string is empty + expect setchk empty -z + to succeed + end + + it fails when string is non-empty + expect setchk var -z + to fail + end + end + + + describe -eq operator + it succeeds on numeric equality + expect setchk one -eq 1 + to succeed + end + + it fails on numeric inequality + expect setchk one -eq 2 + to fail + end + end + + + describe -gt operator + it succeeds when numerically greater + expect setchk one -gt 0 + to succeed + end + + it fails when not numerically greater + expect setchk one -gt 1 + to fail + end + end + + + describe -ge operator + it succeeds when numerically greater + expect setchk one -ge 0 + to succeed + end + + it succeeds when numerically equal + expect setchk one -ge 1 + to succeed + end + + it fails when numerically less than + expect setchk one -ge 2 + to fail + end + end + + + describe -lt operator + it succeeds when numerically less than + expect setchk one -lt 2 + to succeed + end + + it fails when not numerically less than + expect setchk one -lt 1 + to fail + end + end + + + describe -le operator + it succeeds when numerically less than + expect setchk one -le 2 + to succeed + end + + it succeeds when numerically equal + expect setchk one -le 1 + to succeed + end + + it fails when numerically greater than + expect setchk one -le 0 + to fail + end + end + + + describe -ne operator + it succeeds when numerically unequal + expect setchk one -ne 2 + to succeed + end + + it fails when numerically equal + expect setchk one -ne 1 + to fail + end + end + + + # primarily for safety and strict documentation, but no other tests make + # sense at the moment + it fails on unrecognized operators + # shell injection (not that this is realistically a problem, because + # we can execute arbitrary shell code anyway) + expect setchk var "!= foo -a 1 -eq" 1 to fail end end - - - describe != operator - it succeeds on string inequality - expect setchk var != foo - to succeed - end - - it fails on string equality - expect setchk var != val - to fail - end - end - - - describe =~ operator - it succeeds on a match - expect setchk \ - long =~ fo+ ba. baz\$ - to succeed - end - - # note that this also ensures that *all* arguments are part of the match - it fails on a mismatch - expect setchk \ - long =~ fo+ baX baz\$ - to fail - end - end - - - describe -n operator - it succeeds when string is non-empty - expect setchk var -n - to succeed - end - - it fails when string is empty - expect setchk empty -n - to fail - end - end - - - describe -z operator - it succeeds when string is empty - expect setchk empty -z - to succeed - end - - it fails when string is non-empty - expect setchk var -z - to fail - end - end - - - describe -eq operator - it succeeds on numeric equality - expect setchk one -eq 1 - to succeed - end - - it fails on numeric inequality - expect setchk one -eq 2 - to fail - end - end - - - describe -gt operator - it succeeds when numerically greater - expect setchk one -gt 0 - to succeed - end - - it fails when not numerically greater - expect setchk one -gt 1 - to fail - end - end - - - describe -ge operator - it succeeds when numerically greater - expect setchk one -ge 0 - to succeed - end - - it succeeds when numerically equal - expect setchk one -ge 1 - to succeed - end - - it fails when numerically less than - expect setchk one -ge 2 - to fail - end - end - - - describe -lt operator - it succeeds when numerically less than - expect setchk one -lt 2 - to succeed - end - - it fails when not numerically less than - expect setchk one -lt 1 - to fail - end - end - - - describe -le operator - it succeeds when numerically less than - expect setchk one -le 2 - to succeed - end - - it succeeds when numerically equal - expect setchk one -le 1 - to succeed - end - - it fails when numerically greater than - expect setchk one -le 0 - to fail - end - end - - - describe -ne operator - it succeeds when numerically unequal - expect setchk one -ne 2 - to succeed - end - - it fails when numerically equal - expect setchk one -ne 1 - to fail - end - end - - - # primarily for safety and strict documentation, but no other tests make - # sense at the moment - it fails on unrecognized operators - # shell injection (not that this is realistically a problem, because we - # can execute arbitrary shell code anyway) - expect setchk var "!= foo -a 1 -eq" 1 - to fail - end -end +done