#!/bin/sh
# autopkgtest check: Build and run simple programs against libmodplug
#  This test should pass when built against either libopenmpt-modplug or
#  libmodplug.

set -e

# Require $ADTTMP for temporary build files
if [ -z "$ADTTMP" ]
then
	echo 'Required envvar "$ADTTMP" is not set' >&2
	exit 1
fi

cd debian/tests

# Runs argument on the test data and ensures it's matches expected result
run_dump() {
	RESULT=$($1 data/test.xm)
	if [ "$RESULT" != "$(cat data/test.expected)" ]; then
		echo "bad result: $RESULT" 1>&2
		exit 1
	fi
}

# Build programs
gcc -Wall -o "$ADTTMP/pattern-dump-modplug1" pattern-dump-modplug.c -lmodplug
echo "build1: OK"
gcc -Wall -o "$ADTTMP/pattern-dump-modplug2" pattern-dump-modplug.c $(pkg-config --cflags --libs libmodplug)
echo "build2: OK"

# Run them
run_dump "$ADTTMP/pattern-dump-modplug1"
echo "run1: OK"
run_dump "$ADTTMP/pattern-dump-modplug2"
echo "run2: OK"
