#! /bin/sh

set -e

dir=$(pwd)/debian/tests
. $dir/textutils.sh

frame "Here we are testing the patch" \
      "fixes/crontab-raises-an-error-for-too-long-CLI.patch" \
      " (fixing bug#1144850)"


f=/tmp/$(python3 -c "print('a'*93)")/x
mkdir -p "$(dirname "$f")"; echo '* * * * * true' > "$f"
echo "====== Created a path \$f which is $(echo $f | wc -c) characters long. ======"
echo '====== trying to launch `crontab "$f"` ======'
set +e
crontab "$f" 2>/tmp/error.txt; status=$?; true
set -e

echo "======= check the error status and the sensible error message ======"
if [ "$status" -ne "1" ]; then
    exit 1;
else
    echo "OK: the return code is 1"
fi

if grep -q "pathname too long" /tmp/error.txt; then
    echo "OK: the error message says 'path too long'"
else
    exit 1
fi
