Skip to content

Commit

Permalink
Fix some unit test behavior on OpenBSD
Browse files Browse the repository at this point in the history
Partial fix for #483
  • Loading branch information
krader1961 committed Jun 3, 2018
1 parent 9c927e6 commit 235ea6b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 37 deletions.
13 changes: 9 additions & 4 deletions src/cmd/ksh93/tests/arith.sh
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,15 @@ then
expect="$2"
actual=$(printf "%g\n" $(($1)))
[[ $actual == $expect ]] || log_error "printf '%g\\n' \$(($1)) failed" "$expect" "$actual"
actual=$(printf "%g\n" $1)
[[ $actual == $expect ]] || log_error "printf '%g\\n' $1 failed" "$expect" "$actual"
actual=$(printf -- $(($1)))
[[ $actual == $expect ]] || log_error "print -- \$(($1)) failed" "$expect" "$actual"
# TODO: Re-enable this on OpenBSD when it's handling of NaN is fixed.
# See https://marc.info/?l=openbsd-bugs&m=152488432922625&w=2
if [[ $OS_NAME != OpenBSD ]]
then
actual=$(printf "%g\n" $1)
[[ $actual == $expect ]] || log_error "printf '%g\\n' $1 failed" "$expect" "$actual"
actual=$(printf -- $(($1)))
[[ $actual == $expect ]] || log_error "print -- \$(($1)) failed" "$expect" "$actual"
fi
shift 2
done
(( 1.0/0.0 == Inf )) || log_error '1.0/0.0 != Inf'
Expand Down
17 changes: 15 additions & 2 deletions src/cmd/ksh93/tests/comvario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,21 @@ count_brackets "$(print -C y1)" || log_error "y1: bracket open ${bracketstat.bop
count_brackets "$y2" || log_error "y2: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
count_brackets "$(print -v y2)" || log_error "y2: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
count_brackets "$(print -C y2)" || log_error "y2: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
[[ "$y1" == "$y2" ]] || log_error "Expected $(printf "%q\n" "${y1}") == $(printf "%q\n" "${y2}")."
[[ "$x" == "$y1" ]] || log_error "Expected $(printf "%q\n" "${x}") == $(printf "%q\n" "${y1}")."
[[ "$y1" == "$y2" ]] || {
expect=$(printf "%q\n" "${y1}")
actual=$(printf "%q\n" "${y2}")
log_error "Expected \$y1 == \$y2" "$expect" "$actual"
}
# TODO: Re-enable this on OpenBSD when it's handling of NaN is fixed.
# See https://marc.info/?l=openbsd-bugs&m=152488432922625&w=2
if [[ $OS_NAME != OpenBSD ]]
then
[[ "$x" == "$y1" ]] || {
expect=$(printf "%q\n" "${x}")
actual=$(printf "%q\n" "${y1}")
log_error "Expected \$x == \$y1" "$expect" "$actual"
}
fi

# cleanup
unset x y1 y2 || log_error "unset failed"
Expand Down
76 changes: 45 additions & 31 deletions src/cmd/ksh93/tests/treemove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@

function idempotent
{
typeset got var action='typeset -p'
[[ $1 == -* ]] && { shift;var=$2=; action='print -v';}
typeset -n exp=$1
got=$($SHELL <<- EOF
typeset var action='typeset -p'
[[ $1 == -* ]] && { shift; var=$2=; action='print -v'; }
typeset -n expect=$1
typeset actual=$($SHELL <<- EOF
$3
$var$exp
$action $2
$var$expect
$action $2
EOF)
[[ $got == "$exp" ]] || log_error "$exp is not idempotent"
[[ "$actual" == "$expect" ]] || log_error "idempotent test failed" "$expect" "$actual"
}
## test start
Expand Down Expand Up @@ -107,9 +108,10 @@ compound c
typeset -C -a c.ar
c.ar[4]=( a4=1 )
typeset -m "c.ar[5]=c.ar[4]"
exp=$'(\n\ttypeset -C -a ar=(\n\t\t[5]=(\n\t\t\ta4=1\n\t\t)\n\t)\n)'
[[ $(print -v c) == "$exp" ]] || log_error 'typeset -m "c.ar[5]=c.ar[4]" not working'
idempotent -v exp c
expect=$'(\n\ttypeset -C -a ar=(\n\t\t[5]=(\n\t\t\ta4=1\n\t\t)\n\t)\n)'
actual=$(print -v c)
[[ "$actual" == "$expect" ]] || log_error 'typeset -m "c.ar[5]=c.ar[4]" not working' "$expect" "$actual"
idempotent -v exexpect c
typeset -T x_t=( hello=world )
function m
Expand Down Expand Up @@ -202,9 +204,10 @@ function sortar
}
sortar c.ar
exp='typeset -C -a c.ar=((typeset -l -E i=24) (typeset -l -E i=7) (typeset -l -E i=4) (typeset -l -E i=2) (typeset -l -E i=1) (typeset -l -E i=-1))'
[[ $(typeset -p c.ar) == "$exp" ]] || log_error 'sorting compound arrays with typeset -m failed'
idempotent exp c.ar 'typeset -C c'
expect='typeset -C -a c.ar=((typeset -l -E i=24) (typeset -l -E i=7) (typeset -l -E i=4) (typeset -l -E i=2) (typeset -l -E i=1) (typeset -l -E i=-1))'
actual=$(typeset -p c.ar)
[[ "$actual" == "$expect" ]] || log_error 'sorting compound arrays with typeset -m failed' "$expect" "$actual"
idempotent expect c.ar 'typeset -C c'
typeset -T objstack_t=(
compound -a st
Expand All @@ -228,9 +231,10 @@ compound foo=( integer val=5 )
c.ost.pushobj foo
compound res
c.ost.popobj res.a
exp='typeset -C res.a=(typeset -l -i val=5)'
[[ $(typeset -p res.a) == "$exp" ]] || log_error 'typeset -m for compound variable in a type not working'
idempotent exp res.a 'typeset -C res'
expect='typeset -C res.a=(typeset -l -i val=5)'
actual=$(typeset -p res.a)
[[ "$actual" == "$expect" ]] || log_error 'typeset -m for compound variable in a type not working' "$expect" "$actual"
idempotent expect res.a 'typeset -C res'
unset c
compound c dummy
Expand All @@ -240,9 +244,10 @@ typeset -a bar=( 2 3 4 )
c.ost.pushobj foo
c.ost.pushobj bar
c.ost.popobj dummy
exp='typeset -C c=(objstack_t ost=(typeset -l -i st_n=1;st[0]=(obj=(typeset -l -i val=5))))'
[[ $(typeset -p c) == "$exp" ]] || log_error 'typeset -m for types not working'
idempotent exp c "$(typeset -T)"
expect='typeset -C c=(objstack_t ost=(typeset -l -i st_n=1;st[0]=(obj=(typeset -l -i val=5))))'
actual=$(typeset -p c)
[[ "$actual" == "$expect" ]] || log_error 'typeset -m for types not working' "$expect" "$actual"
idempotent expect c "$(typeset -T)"
unset c
typeset -p c
Expand Down Expand Up @@ -292,9 +297,10 @@ nameref ar=c.ar
typeset -m "tmpvar=ar[1]"
command typeset -m "ar[1]=ar[2]" 2> /dev/null || log_error 'typeset -m ar[1]=ar[2] not working when ar is numerical'
typeset -m "ar[2]=tmpvar"
exp='key_t -a c.ar=((typeset -l -E i=7) (typeset -l -E i=11) (typeset -l -E i=1))'
[[ $(typeset -p c.ar) == "$exp" ]] 2> /dev/null || log_error 'typeset -m c.ar has wrong value'
idempotent exp c.ar 'typeset -T key_t=(float i);compound c'
expect='key_t -a c.ar=((typeset -l -E i=7) (typeset -l -E i=11) (typeset -l -E i=1))'
actual=$(typeset -p c.ar)
[[ "$actual" == "$expect" ]] 2> /dev/null || log_error 'typeset -m c.ar has wrong value' "$expect" "$actual"
idempotent expect c.ar 'typeset -T key_t=(float i);compound c'
function sortar
{
Expand Down Expand Up @@ -325,9 +331,15 @@ function main
( float i=+inf ) ( float i=-1 ) )
)
sortar c.ar
exp='typeset -C -a c.ar=((typeset -l -E i=-nan) (typeset -l -E i=inf) (typeset -l -E i=24) (typeset -l -E i=4) (typeset -l -E i=2) (typeset -l -E i=1) (typeset -l -E i=-1) (typeset -l -E i=-inf))'
[[ $(typeset -p c.ar) == "$exp" ]] || log_error 'typeset -m not working when passed a reference to an local argument from a calling function'
idempotent exp c.ar 'compound c'
expect='typeset -C -a c.ar=((typeset -l -E i=-nan) (typeset -l -E i=inf) (typeset -l -E i=24) (typeset -l -E i=4) (typeset -l -E i=2) (typeset -l -E i=1) (typeset -l -E i=-1) (typeset -l -E i=-inf))'
# TODO: Re-enable this on OpenBSD when it's handling of NaN is fixed.
# See https://marc.info/?l=openbsd-bugs&m=152488432922625&w=2
if [[ $OS_NAME != OpenBSD ]]
then
actual=$(typeset -p c.ar)
[[ "$actual" == "$expect" ]] || log_error 'typeset -m not working when passed a reference to an local argument from a calling function' "$expect" "$actual"
idempotent expect c.ar 'compound c'
fi
}
main
Expand All @@ -338,19 +350,21 @@ compound cc.a.xc
typeset cc.a.xc.i=5
X_t cc.b
typeset -m "cc.b.xc.j=cc.a.xc.i"
exp='typeset -C cc=(X_t a=(typeset -C xc);X_t b=(xc=(j=5)))'
[[ $(typeset -p cc) == $exp ]] || log_error 'typeset -m compound variable embedded in type not working'
idempotent exp cc 'typeset -T X_t=( typeset -C xc )'
expect='typeset -C cc=(X_t a=(typeset -C xc);X_t b=(xc=(j=5)))'
actual=$(typeset -p cc)
[[ "$actual" == "$expect" ]] || log_error 'typeset -m compound variable embedded in type not working' "$expect" "$actual"
idempotent expect cc 'typeset -T X_t=( typeset -C xc )'
unset d
compound d=(
compound sta=( compound -a st;integer st_numelements=0)
)
exp='typeset -C d=(sta=(typeset -C -a st=( [0]=(obj=(typeset -l -i t=3;);););typeset -l -i st_numelements=1))'
expect='typeset -C d=(sta=(typeset -C -a st=( [0]=(obj=(typeset -l -i t=3;);););typeset -l -i st_numelements=1))'
compound foo=( integer t=3 )
typeset -m "d.sta.st[$((d.sta.st_numelements++))].obj=foo"
[[ $(typeset -p d) == "$exp" ]] || log_error 'compound variable not displayed properly'
idempotent exp d
actual=$(typeset -p d)
[[ "$actual" == "$expect" ]] || log_error 'compound variable not displayed properly' "$expect" "$actual"
idempotent expect d
function f2
{
Expand Down
1 change: 1 addition & 0 deletions src/cmd/ksh93/tests/util/preamble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readonly SAFE_PATH
readonly TEST_DIR
readonly TEST_SRC_DIR
readonly BUILD_DIR
readonly OS_NAME

#
# Create some functions for reporting and counting errors.
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/ksh93/tests/util/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ mkfifo fifo8
mkdir $TEST_DIR/home
export HOME=$TEST_DIR/home
export HISTFILE=$TEST_DIR/sh_history
#
# A test may need to alter its behavior based on the OS we're running on.
#
export OS_NAME=$(uname -s)

#
# Make sure any locale vars set by the user (or the continuous build environment) don't affect the
Expand Down

0 comments on commit 235ea6b

Please sign in to comment.