#!/bin/sh
#
# Exercise nickle with its test suite.
#

# Tests write scratch files in the current directory, so run them
# from autopkgtest's writable temporary directory
cd "$AUTOPKGTEST_TMP" || exit 1

# Some tests need to know where the binary is
export NICKLE=$(which nickle)

status=0
for test in /usr/share/nickle/test/*.5c; do

    echo "TEST: $test"

    # Tests ending in -error.5c are expected to fail
    case "$test" in
    *-error.5c)

	# Send stderr to stdout so autopkgtest doesn't
	# mark the test as failing
        if "$NICKLE" "$test" 2>&1; then
            echo "FAIL: $test exited successfully"
            status=1
        fi
        ;;
    *)
        if ! "$NICKLE" "$test"; then
            echo "FAIL: $test"
            status=1
        fi
        ;;
    esac
done
exit $status
