#!/bin/sh

set -e

: "${S5:=s5}"

d="$(mktemp -d -t s5-test.XXXXXX)"
# shellcheck disable=SC2064
trap "rm -rf -- '$d'" EXIT QUIT TERM INT HUP 

cd -- "$d"

echo 'Not really creating a blank presentation'
$S5 -N blank new
if [ -e new ]; then
	echo '"s5 -N blank" created something called "new"' 1>&2
	exit 1
fi

echo 'Creating a blank presentation'
$S5 blank new
if [ ! -d 'new' ]; then
	echo '"s5 blank" could not create a "new" directory' 1>&2
	exit 1
fi

for f in s5-checksums.txt s5-blank/s5-blank.html s5-blank/ui/default/s5-core.css; do
	if [ ! -f "new/$f" ]; then
		echo "'s5 blank' did not create the '$f' file" 1>&2
		exit 1
	fi
done

cd new
echo 'Running s5 check s5-blank'
$S5 check s5-blank

mv s5-blank teststuff
echo 'Running s5 check teststuff'
$S5 check teststuff

echo 'Modifying teststuff/s5-blank.html'
echo >> teststuff/s5-blank.html
echo 'Running s5 check teststuff'
$S5 check teststuff && exit 1

echo 'Everything seems fine'
