# Copyright (C) 2012 The Meme Factory, Inc. http://www.meme.com>/ # # This file is part of GombeMI. # # GombeMI is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GombeMI. If not, see . # # Regression test supporting makefile. Should not be run directly. # # Karl O. Pinc # # Remarks: # This just to test db operation, not creation etc. # # We want to empty the db and reset it to an initial state after # each test so that we don't accidently break later tests by # having earlier tests leave old data lying around. # # We use .SECONDEXPANSION trickey to setup dependences for # all the targets. This requires GNU make. # # We create phony save_* targets instead of relying on the existance # of the actual result files and using the files as targets because # changes to the db may change the output and the user will want # to save new results without having to delete an old file. include ../defaults.mk include test.mk include gentargets.mk # Trickery so we don't have to make load_file executable. # (And don't use source (.) because posix won't let it take args.) export RUN_SQL := sh /dev/null 2>&4 \ || { printf 'Error running reset.sql\n' >&4 ; exit 1 ; } .PHONY: $(TEST_FILES) $(TEST_FILES): %: loaded/% begin: loaded/begin # Let the executor know if we need a transaction commit included # in the test output. $(include_commit_targets): export INCLUDE_COMMIT := true # When a prerequsite is virtual, don't run the implicit rule that # generates an error on non-existance. $(VIRTUAL_PREREQS): ; # A fake target for generating an error when a test does not exist. .PHONY: % %: if [ ! -e sql/$@ ] ; then \ printf '%s: Undefined prerequsite ($@)\n' $$THIS_TEST >&4 ; \ exit 1 ; \ fi .SECONDEXPANSION: $(load_targets): loaded/%: sql/% $$($$(patsubst loaded/%,prereq_%,$$@)) $(RUN_SQL) prereq "$(PSQL_ARGS_MINIMAL)" "$<" .PHONY: $(test_targets) $(test_targets): test_%: sql/% reset $$($$(patsubst test_%,prereq_%,$$@)) $(RUN_SQL) test "$(PSQL_ARGS_MINIMAL)" "$<" .PHONY: $(save_targets) $(save_targets): save_%: sql/% reset $$($$(patsubst save_%,prereq_%,$$@)) $(RUN_SQL) save "$(PSQL_ARGS_MINIMAL)" "$<" .PHONY: $(show_targets) $(show_targets): show_%: sql/% reset $$($$(patsubst show_%,prereq_%,$$@)) $(RUN_SQL) show "$(PSQL_ARGS_MINIMAL)" "$<" # Tests that run in a transaction. $(trans_load_targets): loaded/%: sql/% \ begin \ $$($$(patsubst loaded/%,prereq_%,$$@)) $(RUN_SQL) prereq "$(PSQL_ARGS_MINIMAL)" "$<" .PHONY: $(trans_test_targets) $(trans_test_targets): test_%: sql/% reset begin \ $$($$(patsubst test_%,prereq_%,$$@)) $(RUN_SQL) test "$(PSQL_ARGS_MINIMAL)" "$<" .PHONY: $(trans_save_targets) $(trans_save_targets): save_%: sql/% reset begin \ $$($$(patsubst save_%,prereq_%,$$@)) $(RUN_SQL) save "$(PSQL_ARGS_MINIMAL)" "$<" .PHONY: $(trans_show_targets) $(trans_show_targets): show_%: sql/% reset begin \ $$($$(patsubst show_%,prereq_%,$$@)) $(RUN_SQL) show "$(PSQL_ARGS_MINIMAL)" "$<" # Make the virtual prerequsites into rules. $(VIRTUAL_PREREQS): %: $$($$@)