# dot-y.tst: yash-specific test of the dot built-in

echo true >true
echo 'echo "$*"' >print
echo 'set a "$@"; echo "$*"' >set_print

test_oE 'positional parameters in dot script'
set 1 2 3
. ./print
__IN__
1 2 3
__OUT__

test_oE 'changing outer-scope positional parameters in dot script'
set 1 2 3
. ./set_print
echo "$*"
__IN__
a 1 2 3
a 1 2 3
__OUT__

test_oE 'temporary positional parameters'
set 1 2 3
. ./print x y
echo "$*"
__IN__
x y
1 2 3
__OUT__

test_oE 'changing temporary positional parameters'
set 1 2 3
. ./set_print x y
echo "$*"
__IN__
a x y
1 2 3
__OUT__

(
setup 'alias true=false'

test_OE -e n 'alias in dot script (POSIX)' --posix
. ./true
__IN__

test_OE -e n 'alias in dot script (non-POSIX)'
. ./true
__IN__

test_OE -e 0 'disabling alias (short option)'
. -A ./true
__IN__

test_OE -e 0 'disabling alias (long option)'
. --no-alias ./true
__IN__

)

(
# Ensure $PWD is safe to assign to $YASH_LOADPATH
case $PWD in (*[:%]*)
    skip="true"
esac

mkdir testpath
echo 'echo foo' >testpath/foo

mkdir testpath/dir
echo 'echo bar' >testpath/dir/bar

(
setup 'YASH_LOADPATH="$PWD/testpath"'

test_oE 'using $LOADPATH (short option)'
. -L foo
__IN__
foo
__OUT__

test_oE 'using $LOADPATH (long option)'
. --autoload foo
__IN__
foo
__OUT__

test_oE 'dot script in subdirectory of $LOADPATH'
. -L dir/bar
__IN__
bar
__OUT__

)

mkdir testpath/dir1 testpath/dir2

test_oE 'multiple directories in $LOADPATH'
p="$PWD/testpath"
YASH_LOADPATH="$p/dir1:$p/xxx:$p/dir:$p/dir2"
. -L bar
__IN__
bar
__OUT__

)

(
posix='true'

test_Oe -e n 'missing operand'
.
__IN__
.: this command requires an operand
__ERR__

test_Oe -e n 'too many operands'
. _no_such_file_ X
__IN__
.: too many operands are specified
__ERR__

test_Oe -e n 'invalid option'
. -X ''
__IN__
.: `-X' is not a valid option
__ERR__
#'
#`

)

test_Oe -e n 'unset load path'
unset YASH_LOADPATH
. -L _no_such_file_
__IN__
.: file `_no_such_file_' was not found in $YASH_LOADPATH
__ERR__
#'
#`

test_Oe -e n 'null load path'
YASH_LOADPATH=
. -L _no_such_file_
__IN__
.: file `_no_such_file_' was not found in $YASH_LOADPATH
__ERR__
#'
#`

# vim: set ft=sh ts=8 sts=4 sw=4 noet:
