#-----------------------------------------------------------------------------#
# vim: ts=8 sw=8 noexpandtab ft=make
#-----------------------------------------------------------------------------#
# Copyright (C) 1997-2000 The University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public Licence - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
#
# These rules define the main targets: depend, all, check.
#

TESTS_DIR = ..
THIS_DIR = exceptions
MAYBE_J1 =

#-----------------------------------------------------------------------------#

EXCEPTION_PROGS = \
	test_exceptions \
	test_exceptions_func \
	test_try_all \
	test_uncaught_exception \
	tricky_try_store

# XXX the following tests are not enabled because we do not pass them yet:
#	looptest.m
#		(fails in debugging grades, because debugging breaks
#		tail recursion optimization)
#	test_memo.m test_loop_check.m
#       	(those two tests test the combination of
#		tabling and exceptions).
#
# Also currently the compiler has a bug where it generates
# static ground terms even for things with `di' modes;
# tricky_try_store.m contains a work-around for that,
# which should be deleted once that bug is fixed.

# Deep profiling grades cannot yet handle catching exceptions, either
# explicitly or implicitly by the runtime system.

ifneq "$(findstring profdeep,$(GRADE))" ""
	PROGS=
else
	PROGS=$(EXCEPTION_PROGS)
endif

TESTS = $(PROGS)
include ../Mmake.common

# Module-specific options should go in Mercury.options so they
# can be found by `mmc --make'.
include Mercury.options

%.runtest: %.res ;

#-----------------------------------------------------------------------------#

# test_uncaught_exception is *supposed* to return an error exit status.
# We also need to pipe the output through sed to avoid hard-coding
# dependencies on particular line numbers in the standard library source code.
# We also filter out the stack trace in the java grade in order to avoid
# hard-coding dependencies on the Java runtime / generated code.
test_uncaught_exception.out: test_uncaught_exception
	if ./$< > $@.tmp 2>&1; then \
		grep . $@.tmp; \
		exit 1; \
	else \
		sed -e '/pred exception/s/exception.m:[0-9]*/exception.m:NNNN/g' \
			< $@.tmp | grep -v "jmercury\." > $@ ; \
		rm -f $@.tmp; \
	fi

#-----------------------------------------------------------------------------#
