Added `exports` expectation
parent
302977eb74
commit
9045a3298b
|
@ -29,7 +29,7 @@ __INC_EXPECT_ENV=1
|
||||||
#
|
#
|
||||||
__expect-env()
|
__expect-env()
|
||||||
{
|
{
|
||||||
local -r flag="$1" var="$2" cmp="$3"
|
local -r expflags="$1" var="$2" cmp="$3"
|
||||||
shift 3
|
shift 3
|
||||||
local -r expect="$@"
|
local -r expect="$@"
|
||||||
|
|
||||||
|
@ -37,6 +37,11 @@ __expect-env()
|
||||||
local flags val
|
local flags val
|
||||||
__read-env-line "$var" flags val < "$envpath"
|
__read-env-line "$var" flags val < "$envpath"
|
||||||
|
|
||||||
|
# perform flag assertion if requested
|
||||||
|
test -n "$expflags" && {
|
||||||
|
[[ "$flags" =~ [$expflags] ]] || return 1
|
||||||
|
}
|
||||||
|
|
||||||
# cannot quote regex without causing problems, and [[ syntax does not
|
# cannot quote regex without causing problems, and [[ syntax does not
|
||||||
# allow a variable comparison operator; further, argument order varies
|
# allow a variable comparison operator; further, argument order varies
|
||||||
# with certain operators; whitelist to explicitly document support and
|
# with certain operators; whitelist to explicitly document support and
|
||||||
|
@ -100,3 +105,22 @@ _expect--declare()
|
||||||
_expect--set "$@"
|
_expect--set "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Checks that a variable is exported with the given value
|
||||||
|
#
|
||||||
|
# Same syntax as `set`
|
||||||
|
#
|
||||||
|
_expect--export()
|
||||||
|
{
|
||||||
|
local -ri shiftn="$2"
|
||||||
|
local -r envpath="$4"
|
||||||
|
shift "$shiftn"
|
||||||
|
|
||||||
|
# ensure envpath is available
|
||||||
|
__chk-shiftn 4 "$shiftn"
|
||||||
|
|
||||||
|
# expect the -x flag, which denotes export
|
||||||
|
__expect-env x "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,11 @@
|
||||||
##
|
##
|
||||||
|
|
||||||
declare -r stubenv='
|
declare -r stubenv='
|
||||||
declare -- var="val"
|
declare -x -- var="val"
|
||||||
declare -- long="foo bar baz"
|
declare -x -- long="foo bar baz"
|
||||||
declare -- empty=""
|
declare -x -- empty=""
|
||||||
declare -- one="1"'
|
declare -x -- one="1"
|
||||||
|
declare -- nonexport=""'
|
||||||
|
|
||||||
|
|
||||||
declare curchk
|
declare curchk
|
||||||
|
@ -34,10 +35,10 @@ function setchk()
|
||||||
|
|
||||||
|
|
||||||
# we have a few different expectations that have the same syntax
|
# we have a few different expectations that have the same syntax
|
||||||
for name in set declare; do
|
for name in set declare export; do
|
||||||
curchk=$name
|
curchk=$name
|
||||||
|
|
||||||
describe set
|
describe "$name"
|
||||||
describe = and == operators
|
describe = and == operators
|
||||||
it succeeds on string equality
|
it succeeds on string equality
|
||||||
expect setchk var = val
|
expect setchk var = val
|
||||||
|
@ -209,6 +210,13 @@ for name in set declare; do
|
||||||
expect setchk var "!= foo -a 1 -eq" 1
|
expect setchk var "!= foo -a 1 -eq" 1
|
||||||
to fail
|
to fail
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if [ "$name" == export ]; then
|
||||||
|
it fails when variable is not exported
|
||||||
|
expect setchk nonexport -z
|
||||||
|
to fail
|
||||||
|
end
|
||||||
|
fi
|
||||||
end
|
end
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue