# binaries_runtests.mk # $Id: binaries_runtests.mk,v 1.5 1999/08/26 20:43:29 russo Exp $ # # Rules for running test programs and comparing their output with # expected values. # # Define TESTS to be the list of test binaries to build (without # a directory name). This scrap will set things up to build them # in $(workdir). Each test T.EXT should also have an `expected' file # T.exp; the output of T.EXT will be compared with the contents of # T.exp. # # Sometimes, tests are scripts and not binaries; these should be added # to TEST_SCRIPTS, rather than TESTS. # # Sometimes, during development, you want to build only one or a few # of the tests. This can be done by setting the variable ONLYTESTS # to the test programs which you actually want to build. (This is probably # best done from the command line.) # # binaries_runtests.mk uses binaries.mk to do the linking. # # Example: # # Assuming the package contains the test program foo.cc and # its expected output foo.exp, the following will (in the test phase) # build it, run it, and compare it with the expected output. # # TESTS := foo.x # $(workdir)foo.x : foo.o # # include SoftRelTools/standard.mk # include SoftRelTools/binaries_runtests.mk # # scott snyder, jan 1999; adapted from d0_util. # ############################################################################### # # Define the `test' target. # test : tests diffs # # Allow building only a subset of the tests. # ifdef ONLYTESTS TESTS := $(filter $(ONLYTESTS),$(TESTS)) endif # # Define the binaries to install. # BINARIES := $(TESTS) BINARY_DIR := $(workdir) # # Define the `tests' target. # .PHONY: tests TESTBINS = $(foreach t,$(TESTS),$(workdir)$t) tests: lib $(TESTBINS) # # And handle script-based tests. # TESTS += $(TEST_SCRIPTS) ifdef ONLYTESTS TESTS := $(filter $(ONLYTESTS),$(TESTS)) endif $(addprefix $(BINARY_DIR),$(TEST_SCRIPTS)) : $(BINARY_DIR)% : % cp $* $(BINARY_DIR) chmod +x $(BINARY_DIR)$* ifneq (,$(findstring AIX,$(BFARCH))) DIFFFLAGS = -c # diff on AIX doesn't support unidiffs. else ifneq (,$(findstring OSF,$(BFARCH))) DIFFFLAGS = -c # can't rely on it on OSF either. else DIFFFLAGS = -u endif endif ifneq (,$(findstring NT,$(BFARCH))) MAYBESED := | sed -e `echo -e 's/\r//g'` # gotta clean off CR's else MAYBESED := endif TESTS_X := $(filter %.x,$(TESTS)) TESTS_EXE := $(filter %.exe,$(TESTS)) TESTS_NOEXT := $(filter-out $(TESTS_X) $(TESTS_EXE),$(TESTS)) TESTS_STEMS := $(TESTS_NOEXT) \ $(TESTS_X:.x=) \ $(TESTS_EXE:.exe=) DIFFTARGS_X := $(addsuffix .diffs,$(TESTS_X:.x=)) DIFFTARGS_EXE := $(addsuffix .diffs,$(TESTS_EXE:.exe=)) DIFFTARGS_NOEXT := $(addsuffix .diffs,$(TESTS_NOEXT)) DIFFTARGS := $(DIFFTARGS_X) $(DIFFTARGS_EXE) $(DIFFTARGS_NOEXT) .PHONY: diffs $(DIFFTARGS) diffs: lib $(DIFFTARGS) ifdef NOTRACE define RUN_TESTS $< $(TEST_ARGS) 2>&1 $(MAYBESED) | diff $(DIFFFLAGS) $*.exp - endef else define RUN_TESTS echo "--> Diffing $<" $< $(TEST_ARGS) 2>&1 $(MAYBESED) | diff $(DIFFFLAGS) $*.exp - endef endif $(DIFFTARGS_X): %.diffs : $(BINARY_DIR)%.x %.exp $(RUN_TESTS) $(DIFFTARGS_EXE): %.diffs : $(BINARY_DIR)%.exe %.exp $(RUN_TESTS) $(DIFFTARGS_NOEXT): %.diffs : $(BINARY_DIR)% %.exp $(RUN_TESTS) # # Rules for decending into subdirectories. # diffs: $(LIB) $(foreach v,$(DIFFS_SUBDIRS),$v.diffs) %.diffs: ifndef NOTRACE @echo "--> <**diffs**> $(@:.diffs=)" endif @$(MAKE) -C $(@:.diffs=) diffs # # Include the rules to build binaries. # include SoftRelTools/binaries.mk