Environment expectations now permit omitting operator
Export expectations will only succeed/fail based on flag checks, whereas the declare/set expectations will fail on value.master
parent
9045a3298b
commit
a116a4ac72
|
@ -56,6 +56,13 @@ __expect-env()
|
||||||
=|==|!=|-eq|-ne|-lt|-le|-gt|-ge)
|
=|==|!=|-eq|-ne|-lt|-le|-gt|-ge)
|
||||||
test "$val" $cmp "$expect";;
|
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;;
|
*) false;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,8 @@ declare -x -- var="val"
|
||||||
declare -x -- long="foo bar baz"
|
declare -x -- long="foo bar baz"
|
||||||
declare -x -- empty=""
|
declare -x -- empty=""
|
||||||
declare -x -- one="1"
|
declare -x -- one="1"
|
||||||
declare -- nonexport=""'
|
declare -- nonexport="moo"
|
||||||
|
declare -- nonexport_empty=""'
|
||||||
|
|
||||||
|
|
||||||
declare curchk
|
declare curchk
|
||||||
|
@ -213,9 +214,43 @@ for name in set declare export; do
|
||||||
|
|
||||||
if [ "$name" == export ]; then
|
if [ "$name" == export ]; then
|
||||||
it fails when variable is not exported
|
it fails when variable is not exported
|
||||||
expect setchk nonexport -z
|
expect setchk nonexport
|
||||||
to fail
|
to fail
|
||||||
end
|
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
|
fi
|
||||||
end
|
end
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue