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