/ db / test /
/db/test/run_test.mkf
1 # Copyright (C) 2012 The Meme Factory, Inc. http://www.meme.com>/
2 #
3 # This file is part of GombeMI.
4 #
5 # GombeMI is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with GombeMI. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Regression test supporting makefile. Should not be run directly.
19 #
20 # Karl O. Pinc <kop@meme.com>
21 #
22 # Remarks:
23 # This just to test db operation, not creation etc.
24 #
25 # We want to empty the db and reset it to an initial state after
26 # each test so that we don't accidently break later tests by
27 # having earlier tests leave old data lying around.
28 #
29 # We use .SECONDEXPANSION trickey to setup dependences for
30 # all the targets. This requires GNU make.
31 #
32 # We create phony save_* targets instead of relying on the existance
33 # of the actual result files and using the files as targets because
34 # changes to the db may change the output and the user will want
35 # to save new results without having to delete an old file.
36
37 include ../defaults.mk
38 include test.mk
39 include gentargets.mk
40
41 # Trickery so we don't have to make load_file executable.
42 # (And don't use source (.) because posix won't let it take args.)
43 export RUN_SQL := sh <run_sql.sh run_sql.sh
44
45 INCLUDE_COMMIT_FILES := \
46 $(filter $(patsubst %,sql/%,$(ERROR_RAISING_TRANSACTIONS)) \
47 , $(SQL_FILES))
48
49
50 include_commit_targets := $(patsubst sql/%,loaded/%,$(INCLUDE_COMMIT_FILES)) \
51 $(patsubst sql/%,test_%,$(INCLUDE_COMMIT_FILES)) \
52 $(patsubst sql/%,show_%,$(INCLUDE_COMMIT_FILES)) \
53 $(patsubst sql/%,save_%,$(INCLUDE_COMMIT_FILES))
54
55 all:
56
57 .PHONY: reset
58 reset: reset.sql
59 rm -rf loaded/* ; \
60 ( printf 'set client_min_messages TO WARNING;\n' ; \
61 printf '\\set ON_ERROR_STOP\n' ; \
62 cat reset.sql ) \
63 | psql $(PSQL_ARGS) >/dev/null 2>&4 \
64 || { printf 'Error running reset.sql\n' >&4 ; exit 1 ; }
65
66 .PHONY: $(TEST_FILES)
67 $(TEST_FILES): %: loaded/%
68
69 begin: loaded/begin
70
71 # Let the executor know if we need a transaction commit included
72 # in the test output.
73 $(include_commit_targets): export INCLUDE_COMMIT := true
74
75 # When a prerequsite is virtual, don't run the implicit rule that
76 # generates an error on non-existance.
77 $(VIRTUAL_PREREQS): ;
78
79 # A fake target for generating an error when a test does not exist.
80 .PHONY: %
81 %:
82 if [ ! -e sql/$@ ] ; then \
83 printf '%s: Undefined prerequsite ($@)\n' $$THIS_TEST >&4 ; \
84 exit 1 ; \
85 fi
86
87 .SECONDEXPANSION:
88
89 $(load_targets): loaded/%: sql/% $$($$(patsubst loaded/%,prereq_%,$$@))
90 $(RUN_SQL) prereq "$(PSQL_ARGS_MINIMAL)" "$<"
91
92 .PHONY: $(test_targets)
93 $(test_targets): test_%: sql/% reset $$($$(patsubst test_%,prereq_%,$$@))
94 $(RUN_SQL) test "$(PSQL_ARGS_MINIMAL)" "$<"
95
96 .PHONY: $(save_targets)
97 $(save_targets): save_%: sql/% reset $$($$(patsubst save_%,prereq_%,$$@))
98 $(RUN_SQL) save "$(PSQL_ARGS_MINIMAL)" "$<"
99
100 .PHONY: $(show_targets)
101 $(show_targets): show_%: sql/% reset $$($$(patsubst show_%,prereq_%,$$@))
102 $(RUN_SQL) show "$(PSQL_ARGS_MINIMAL)" "$<"
103
104
105 # Tests that run in a transaction.
106
107 $(trans_load_targets): loaded/%: sql/% \
108 begin \
109 $$($$(patsubst loaded/%,prereq_%,$$@))
110 $(RUN_SQL) prereq "$(PSQL_ARGS_MINIMAL)" "$<"
111
112 .PHONY: $(trans_test_targets)
113 $(trans_test_targets): test_%: sql/% reset begin \
114 $$($$(patsubst test_%,prereq_%,$$@))
115 $(RUN_SQL) test "$(PSQL_ARGS_MINIMAL)" "$<"
116
117 .PHONY: $(trans_save_targets)
118 $(trans_save_targets): save_%: sql/% reset begin \
119 $$($$(patsubst save_%,prereq_%,$$@))
120 $(RUN_SQL) save "$(PSQL_ARGS_MINIMAL)" "$<"
121
122 .PHONY: $(trans_show_targets)
123 $(trans_show_targets): show_%: sql/% reset begin \
124 $$($$(patsubst show_%,prereq_%,$$@))
125 $(RUN_SQL) show "$(PSQL_ARGS_MINIMAL)" "$<"
126
127
128 # Make the virtual prerequsites into rules.
129 $(VIRTUAL_PREREQS): %: $$($$@)