#! @TESTSHELL@

. @testlib_sh_LIBS@

cd @abs_top_builddir@/tests

exe="@abs_top_builddir@/syspathsubst/syspathsubst"

trap "rm -rf $$-*" EXIT

PATH="@abs_top_builddir@/sysarch:@abs_top_builddir@/syspathsubst:.:$PATH"

# note that it is possible for the absolute path returned by the %l
# and %L options to not match the output of the pwd command.  Thus,
# strip off leading path components before comparing them.

a="$$-a"
b="$$-b"
c="$$-c"
d="$$-d"
e="$$-e"

test_initialize

test_set_hook result test_result_hook_save_output_on_failure
test_set check_exit_status 1

mkdir $a $b $c $d
ln -s $d $e

res=$($exe -d : -c a:b:c:d:e "$$-%s")
test_is "$res" "$a:$b:$c:$d:$e" "%s"

res=$($exe -d : -c a:b:c:d:e "$$-%p")
test_is "$res" "$a:$b:$c:$d:$e" "%p"

res=$($exe -d : -c k:j:f:r:e "$$-%P")
test_is "$res" "$e" "%P"

res=$($exe -d : -c a:b:c:d:e "$$-%l" | sed -e 's|[^:]*/'$$'|'$$'|g' )
test_is "$res" "$a:$b:$c:$d" "%l"

# the %L will add an absolute path, which won't match the first $a
# path, which is why $a is duplicated in the output
res=$($exe -d : -c a:b:c:d:e $$-%p $$-%L | sed -e 's|[^:]*/'$$'|'$$'|g' )
test_is "$res" "$a:$b:$c:$d:$e:$a" "%p %L"


test_summary
test_exit
