#!/bin/sh
# modelled after denemo/tests/unit.c

set -u

exec 2>&1

oneTimeSetUp() {
	export GUILE_AUTO_COMPILE=0
	export HOME=$AUTOPKGTEST_TMP
}

tearDown() {
	echo
}

testRunAndQuit() {
	denemo -n -e -a "(d-Quit)"
	exit_code=$?
	assertEquals 'Denemo should have exited with 0' 0 $exit_code
}

testSchemeLog() {
	denemo -n -e --verbose -a '
		(d-Debug "This is debug")
	        (d-Info "This is info")
	        (d-Message "This is message")
	        (d-Warning "This is warning")
	        (d-Critical "This is critical")
	        (d-Quit)' 2>&1
	exit_code=$?
	assertEquals 'Denemo should have exited with 0' 0 $exit_code
}

testSchemeLogError() {
	denemo -n --fatal-scheme-errors \
		-a '(d-Error "This error is fatal")(d-Quit)' 2>&1
	exit_code=$?
	assertNotEquals 'Denemo should have aborted with a non-zero exit code' \
		0 $exit_code
}

testThumbnailer() {
	thumbnail=$AUTOPKGTEST_TMP/thumbnail.png
	scheme="(d-CreateThumbnail #f \"$thumbnail\")(d-Exit)"
	input=tests/fixtures/denemo/blank.denemo

	echo "Running scheme: $scheme $input"
	denemo -n -e -V -a "$scheme" "$input" 2>&1
	exit_code=$?
	assertEquals 'Denemo should have exited with 0' 0 $exit_code
	assertTrue "Thumbnail file $thumbnail should exist" '[ -r "$thumbnail" ]'
}

# load and run shUnit2
. shunit2
