#!/bin/sh

set -e

. $(pwd)/common.sh

printf "Test that we create TMPDIR and propagate that variable intact"

cat >$TMP/echotest <<EOF
#!/bin/sh
echo \$TMPDIR
EOF
chmod a+x $TMP/echotest

cat >$TMP/unrestricted <<EOF
@unrestricted
EOF

export TMPDIR="$(mktemp -du /tmp/snaps/XXXXXX)/foo/bar"
test ! -e "$TMPDIR" # just sanity checking

OUTPUT="$($L appname unrestricted $TMP/echotest)"

if [ ! -d "$TMPDIR" ]; then
    # we didn't create TMPDIR like we should have
    FAIL
fi

if [ "$TMPDIR" != "$OUTPUT" ]; then
    # we didn't propagate TMPDIR to the command
    FAIL
fi

PASS
