-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
101 lines (85 loc) · 3.7 KB
/
Copy pathmakefile
File metadata and controls
101 lines (85 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# ==============================
# CONFIGURACAO DE CONEXAO
# Edite os valores abaixo antes de executar.
# Se usar DBURL, os demais podem ficar em branco.
# ==============================
PSQL ?= psql
PSQL_FLAGS ?= -v ON_ERROR_STOP=1
DBURL =
HOST =
PORT =
DBUSER =
DBPASS =
DBNAME =
TRASHDB = dbtest_trash
TRASHDB_VERS = pg16-psql17
PSQL_DIFF_LINE_SED = s|^psql:([^:]+):[0-9]+:|psql:\1:<LINE>:|
PSQL_ENV = $(if $(HOST),PGHOST='$(HOST)') $(if $(PORT),PGPORT='$(PORT)') $(if $(DBUSER),PGUSER='$(DBUSER)') $(if $(DBPASS),PGPASSWORD='$(DBPASS)') $(if $(DBNAME),PGDATABASE='$(DBNAME)')
PSQL_CMD = $(PSQL_ENV) $(PSQL) $(PSQL_FLAGS) $(DBURL)
# only for TRASHDB:
DBURL_prefix = postgres://postgres@localhost
PSQL_ENV2 = $(if $(HOST),PGHOST='$(HOST)') $(if $(PORT),PGPORT='$(PORT)') $(if $(DBUSER),PGUSER='$(DBUSER)') $(if $(DBPASS),PGPASSWORD='$(DBPASS)') $(if $(DBNAME),PGDATABASE='$(TRASHDB)')
PSQL_DB2 = $(if $(strip $(PSQL_ENV2)),"","$(DBURL_prefix)/$(TRASHDB)")
PSQL_CMD2 = $(PSQL_ENV2) $(PSQL) $(PSQL_DB2)
PSQL_CMD2_STOP = $(PSQL_ENV2) $(PSQL) $(PSQL_FLAGS) $(PSQL_DB2)
# conly for drop/create TRASHDB, using db=postgres:
PSQL_ENV3 = $(if $(HOST),PGHOST='$(HOST)') $(if $(PORT),PGPORT='$(PORT)') $(if $(DBUSER),PGUSER='$(DBUSER)') $(if $(DBPASS),PGPASSWORD='$(DBPASS)') $(if $(DBNAME),PGDATABASE='postgres')
PSQL_CMD3 = $(PSQL_ENV3) $(PSQL) $(PSQL_FLAGS) $(if $(strip $(PSQL_ENV3)),"","$(DBURL_prefix)/postgres")
CORE_SQL = \
./src/inst01-fw_lib.sql \
./src/inst02-fw_core.sql \
./src/inst03-fw_govRules.sql \
./src/inst04-documentation_examples.sql \
./src/assert01-basic.sql
.PHONY: help see assertDiff core all manualExamples usecaseExamples dropDbTest
help:
@printf '%s\n' \
'Targets:' \
' all - execute all, including asserts.' \
' inst - installations.' \
' assertDiff - execute only asserts by diff.' \
' manualExamples - execute the SQL examples from the user manual tutorial.' \
' usecaseExamples - execute approved simple use-case test cases.' \
' test_all - execute all on the default test-database.' \
' see - show variables' \
' dropDbTest - run all on trash-test database' \
'' \
'Configuring makefile, for database conection:' \
' Please edit the makefile and fill:' \
' DBURL="postgres://usuario@host/banco"' \
' or variables HOST, PORT, DBUSER, DBPASS e DBNAME' \
''
see:
@echo "psql_env = $(PSQL_ENV)"
@echo "psql_cmd = $(PSQL_CMD)"
@echo "psql_env2 = $(PSQL_ENV2)"
@echo "psql_cmd2 = $(PSQL_CMD2)"
@echo "psql_env3 = $(PSQL_ENV3)"
@echo "psql_cmd3 = $(PSQL_CMD3)"
assertDiff:
@echo ">>> Executing psql-text-diff asserts:"
$(PSQL_CMD) -f "./src/assert02-psqlDiff.sql | diff - ./src/assert02-res-psqlDiff.txt";
core:
@for f in $(CORE_SQL); do \
echo ">>> Executando $$f"; \
$(PSQL_CMD) -f "$$f"; \
done
all: core assertDiff
manualExamples:
@echo ">>> Executing user manual tutorial examples:"
$(PSQL_CMD) -f ./assets/data/manual01-public_health_tutorial.sql
usecaseExamples: manualExamples
dropDbTest:
$(PSQL_CMD3) -c "DROP DATABASE IF EXISTS $(TRASHDB);"
$(PSQL_CMD3) -c "CREATE DATABASE $(TRASHDB);"
@for f in $(CORE_SQL); do \
echo ">>> Executando $$f"; \
$(PSQL_CMD2_STOP) -f "$$f"; \
done
@echo ">>> Executing psql-text-diff asserts on fresh $(TRASHDB):"
$(PSQL_CMD2) -f ./src/assert02-psqlDiff.sql > /tmp/trash.txt 2>&1
sed -E '$(PSQL_DIFF_LINE_SED)' /tmp/trash.txt > /tmp/trash.normalized.txt
sed -E '$(PSQL_DIFF_LINE_SED)' "./assets/assert02-res-psqlDiff.$(TRASHDB_VERS).txt" > /tmp/assert02-res-psqlDiff.normalized.txt
diff -w -b /tmp/trash.normalized.txt /tmp/assert02-res-psqlDiff.normalized.txt
@echo " ... if no diff, rm /tmp/trash.txt /tmp/trash.normalized.txt /tmp/assert02-res-psqlDiff.normalized.txt"
@echo