#! /bin/sh
# -*- sh -*-
# $Id: debian-test.c2hs,v 1.1 2001/03/10 23:33:05 michaelw Exp $
#
# Copyright (c) 2001 Michael Weber <michaelw@debian.org>
# This program is distributed under the terms of the GPL.
#
# test script for debian-test package
# Based on example debian-test/grep program


# check that c2hs is installed
test -e /usr/bin/c2hs-config || exit 0


# Work in C locale
unset LC_ALL LANG LC_MESSAGES

. ${DEBIANTEST_LIB}/functions.sh


# variables
PACKAGE=c2hs
DOCDIR=/usr/share/doc/${PACKAGE}
# leave 'build' in there! (workaround for examples/ Makefile)
TEMPDIR=${TMPDIR-/tmp}/${PACKAGE}-build.$$


# tests
test_version_number() {
	VERSION="$(c2hs-config --version)"
	grep ${VERSION} ${DOCDIR}/copyright || {
		printmsg "package version '${VERSION}' not found in copyright file."
		false
	}
}


test_build() {
	cp -a ${DOCDIR}/tests ${TEMPDIR} || {
		printmsg "could not find build tests in '${DOCDIR}/tests'."
		false
	}
	
	BUILDDIR=${TEMPDIR}/tests
	
	make simple -C ${BUILDDIR} \
			C2HS="$(c2hs-config --c2hs)" \
			HCFLAGS="$(echo $(c2hs-config --cflags --libs))" || {
		printmsg "build test for 'simple' failed."
		false
	}
	
	cd ${BUILDDIR} && ./simple || {
		printmsg "could not run '${BUILDDIR}/simple'."
		false
	}
}


# global setup
mkdir ${TEMPDIR}


# run tests
runtest "Version numbering"	test_version_number
runtest "Build'n'smoke test"	test_build


# clean up
rm -rf ${TEMPDIR}
