#! /bin/sh

set -e

. ${srcdir}/test.lib.sh

tl_plan 5

# Calling without arguments is valid
echo | ${top_builddir}/src/dh-exec-subst | \
        tl_expect "Calling without arguments is valid" ""
tl_next

# The she-bang gets removed from the output
(cat <<EOF
#! ${top_builddir}/src/dh-exec-subst
# This is another comment.
we add some stuff, such as \${DH_EXEC_SOURCE}

# and some more comments
and in the end, we quit
EOF
) | ${top_builddir}/src/dh-exec-subst | \
        tl_forbid "Comments get removed" "#"
tl_next

# Calling as a she-bang works
t=$(mktemp)

cat >"${t}" <<EOF
#! ${top_builddir}/src/dh-exec-subst
nothing = \${DH_EXEC_SOURCE}
EOF

chmod +x "${t}"
"${t}" | tl_expect "Calling as a she-bang works" "nothing = ${t}"
rm -f "${t}"

tl_next

# Calling with too many arguments does NOT work
(${top_builddir}/src/dh-exec-subst too many arguments 2>&1 || true) | \
        tl_expect_match "Calling with too many arguments does NOT work" \
                        "no argument at all"
tl_next

# Calling with a non-existing file does NOT work, either.
(${top_builddir}/src/dh-exec-subst --invalid-file-- 2>&1 || true) | \
        tl_expect_match "Calling with a non-existing file does NOT work" \
                        "can't open --invalid-file--"
tl_next
