#! /bin/sh

set -e

. ${srcdir}/test.lib.sh

tl_plan 5

# The she-bang gets removed from the output
(cat <<EOF
#! ${top_builddir}/src/dh-exec
# 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 --without=install | \
        tl_forbid "Comments get removed" "#"
tl_next

# Empty lines get removed from the output
(cat <<EOF
#! ${top_builddir}/src/dh-exec
## This is another comment.
some LINES

and the final one
EOF
) | ${top_builddir}/src/dh-exec --without=install | \
        tl_forbid "Empty lines get removed" "^$"
tl_next

# Whitespace-only lines get removed aswell
(cat <<EOF
#! ${top_builddir}/src/dh-exec
## This is another comment.
some LINES
   	   
and the final one
EOF
) | ${top_builddir}/src/dh-exec --without=install | \
        tl_forbid "Whitespace-only lines get removed" "^[ 	]\{1,\}$"
tl_next

# Calling with no sub-commands to run still works
(cat <<EOF
#! ${top_builddir}/src/dh-exec
one line


.
EOF
) | ${top_builddir}/src/dh-exec --no-act --with= | \
        tl_expect_match "dh-exec without sub-commands still works" \
                        "^[^\|]*/dh-exec-strip \[input: {0, NULL}, output: {0, NULL}\]\$"
tl_next

# Calling with --with-scripts still strips
t=$(mktemp --tmpdir=. tmpXXXXXXXX.install)

cat >"${t}" <<EOF
#! ${top_builddir}/src/dh-exec --with-scripts=subst-multiarch
something...
EOF

chmod +x "${t}"

${t} | tl_forbid "dh-exec called with --with-scripts still strips" \
                 "#"
rm -f "${t}"

tl_next
