#===========================================================================
#
# OPUS tests Makefile
#
#   These are unit tests for languages like perl and python
#   (unless it would eventually make sense to include unit tests
#   for compiled langs like C++ and java?)
#
# author: Lisa E. Sherbert
#
# Modification History:
#
#   Date       OPR         Who       Reason
# --------   -------   ------------  -----------------------------------------
# 10/21/07   n/a       Sherbert      first version
#===========================================================================
#
# Determine the operating system
#    may not need these if we're not going to conditionalize execution or
#    write to an OS-specific output dir
#
OSNAME:=$(shell uname)

ifeq ($(OSNAME),OSF1)
  os_name = axp_unix
endif

ifeq ($(OSNAME),SunOS)
  os_name = sparc_solaris
endif

ifeq ($(OSNAME),Linux)
  os_name = linux
endif

os_sub_dir = $(os_name)

# Want tests to run if 
#   a) the pre-requisite files change or
#   b) if the test files themselves change
# Create the name of the pre-requisite files by pre-pending
# the relative location of the src/scripts dir to the
# expected name of the files containing the subroutines to be tested.
# For perl, we'll name those <basename>.pm and for python <basename>.py.
# I have chosen <basename> with the suffix .pytest for the python 
# unit test files, instead of their convention test_<basename>.py, so
# that it is easy for gmake to figure out all the names.

script_dir    = ../
module_perl   = .pm
module_python = .py
test_suffix_perl   = .t
test_suffix_python = .pytest

# Get a list of the test files in this directory
test_files_perl = $(filter %$(test_suffix_perl), $(wildcard *))
prereqs_perl    = $(addsuffix $(module_perl), $(addprefix $(script_dir), $(basename $(test_files_perl))))

test_files_python = $(filter %$(test_suffix_python), $(wildcard *))
prereqs_python    = $(addsuffix $(module_python), $(addprefix $(script_dir), $(basename $(test_files_python))))

## When is this block encountered?
all: 
	@echo ""
	@echo "----- all rule: ----- "
	@echo "test_files_perl are: $(test_files_perl)"
	@echo "prereqs_perl    are: $(prereqs_perl)"
	@echo ""
	@echo "test_files_python are: $(test_files_python)"
	@echo "prereqs_python    are: $(prereqs_python)"
	@echo ""
	@echo ""
	@echo ""
	@echo "Finished updating tests"
	@echo "This block is only echoes and does nothing yet"

## Whereas tests should be run if either the subroutine file OR the test
## file have been updated, the command should ONLY be run on the test file.
## Therefore, use order-only-prerequisites (to right of | in dependency list) 
## so a special variable can be used to list the test files.
FORCE:
do_test_perl   : $(prereqs_perl) | $(test_files_perl) 
	@echo ""
	@echo "----- Running perl tests ... ----- "
	@cp test_results_perl test_results_perl.old
	@echo "## prove -I .. -v $| 2>&1 | tee test_results_perl"
	@prove -I .. -v $| 2>&1 | tee test_results_perl

FORCE:
do_test_python : $(prereqs_python) | $(test_files_python)
	@echo ""
	@echo "----- Running python tests ... ----- "
	@cp test_results_python test_results_python.old
	@echo "## python $| 2>&1 | tee test_results_python"
	@python $| 2>&1 | tee test_results_python


.PHONY: clean
clean:
	@echo "No cleaning.  Dinnae want to accidently mess w/repository.";
