#!/bin/bash
set -e

pkg=gifshuffle

export LC_ALL=C.UTF-8
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  # shellcheck disable=SC2064
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

head -n8 $0 > "${AUTOPKGTEST_TMP}"/testfile
cd "${AUTOPKGTEST_TMP}"

convert -size 256x256 xc: \
        -channel R -fx "i/255" \
        -channel G -fx "j/255" \
        -channel B -fx "0.5" \
        -colors 256 \
        colorcube.gif

gifshuffle -C -f testfile -p "shuffle" colorcube.gif outfile.gif
gifshuffle -C -p "shuffle" outfile.gif > testcompare

diff testfile testcompare || { echo "Fail"; exit 1; }
echo "Pass"
