#-----------------------------------------------------------------------------#
# vim: ts=8 sw=8 noexpandtab ft=make
#-----------------------------------------------------------------------------#

THIS_DIR=tests
PROGS=
TESTS=

# If you modify this, modify all_test_dirs in tools/bootcheck as well.
SUBDIRS = \
	accumulator \
	analysis \
	analysis_ctgc \
	analysis_excp \
	analysis_external \
	analysis_sharing \
	analysis_table \
	analysis_trail \
	analysis_unused_args \
	benchmarks \
	debugger \
	declarative_debugger \
	dppd \
	exceptions \
	feedback \
	general \
	grade_subdirs \
	hard_coded \
	invalid \
	invalid_make_int \
	invalid_nodepend \
	invalid_onlydepend \
	invalid_options_file \
	invalid_purity \
	invalid_submodules \
	misc_tests \
	mmc_make \
	options_file \
	par_conj \
	purity \
	recompilation \
	string_format \
	structure_reuse \
	submodules \
	tabling \
	term \
	trailing \
	typeclasses \
	valid \
	valid_make_int \
	valid_seq \
	warnings

NOT_YET_READY_SUBDIRS = \
	stm

TESTS_DIR = .
include Mmake.common

.PHONY: check
check: runtests

.PHONY: runtests
runtests:
	+@if mmake -k runtests_subdirs; then \
		rm -f $(ERROR_OUTPUT_FILE); \
	else \
	for subdir in $(SUBDIRS); do \
		if test -f $$subdir/$(ERROR_OUTPUT_FILE); then \
			cat $$subdir/$(ERROR_OUTPUT_FILE) \
				>> $(ERROR_OUTPUT_FILE); \
		fi; \
		if test -f $$subdir/FAILED_TESTS; then \
			sed "s@^@$$subdir/@" $$subdir/FAILED_TESTS \
				>> FAILED_TESTS; \
		fi; \
	done; \
        echo SOME TESTS FAILED: see FAILED_TESTS and $(ERROR_OUTPUT_FILE); \
        exit 1; \
    fi

RUNTESTS_IN_SUBDIRS=$(SUBDIRS:%=runtests_in_%)

.PHONY: runtests_subdirs
runtests_subdirs: $(RUNTESTS_IN_SUBDIRS)

.PHONY: runtests_in_subdirs
$(RUNTESTS_IN_SUBDIRS): runtests_in_%:
	+if test -d $* ; then \
		cd $* && mmake runtests_dir ; \
	else \
		echo Could not run tests in directory $* ; \
		echo Could not run tests in directory $* >> NOMAKE_DIRS ; \
	fi

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

realclean: realclean_subdirs

realclean_subdirs:
	+succeeded=true; \
	for dir in $(SUBDIRS); do \
		(cd $$dir && mmake realclean) || succeeded=false; \
	done
	case $$succeeded in \
		false) \
			exit 1 \
			;; \
	esac

clean: clean_subdirs

clean_subdirs:
	+succeeded=true; \
	for dir in $(SUBDIRS); do \
		(cd $$dir && mmake clean) || succeeded=false; \
	done; \
	case $$succeeded in \
		false) \
			exit 1 \
			;; \
	esac

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