-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (151 loc) · 6.6 KB
/
Makefile
File metadata and controls
165 lines (151 loc) · 6.6 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
.PHONY: all
all: test
# Capture git status once at Make parse time
GIT_DIRTY := $(shell git status --porcelain 2>/dev/null)
# Build fresh foundation environment (clean + create)
# Foundation is the base TEST_REPO that all tests depend on
# See test/lib/foundation.bats for detailed explanation of why foundation.bats
# is both a test and a library
.PHONY: foundation
foundation: clean-envs
@test/bats/bin/bats test/lib/foundation.bats
# Test recursion and pollution detection
# Cleans environments then runs one independent test, which auto-runs foundation
# as a prerequisite. This validates that recursion and pollution detection work correctly.
# Note: Doesn't matter which independent test we use, we just pick the fastest one (doc).
.PHONY: test-recursion
test-recursion: clean-envs
@echo "Testing recursion with clean environment..."
@test/bats/bin/bats test/standard/doc.bats
# Test file lists
# These are computed at Make parse time for efficiency
SEQUENTIAL_TESTS := $(shell ls test/sequential/[0-9][0-9]-*.bats 2>/dev/null | sort)
STANDARD_TESTS := $(shell ls test/standard/*.bats 2>/dev/null | grep -v foundation.bats)
EXTRA_TESTS := $(shell ls test/extra/*.bats 2>/dev/null)
ALL_INDEPENDENT_TESTS := $(STANDARD_TESTS) $(EXTRA_TESTS)
# Common test setup: runs foundation test ONLY
# This is shared by all test targets to avoid duplication
#
# IMPORTANT: test-setup ONLY runs foundation.bats, no other tests.
# See test/lib/foundation.bats for detailed explanation of why foundation.bats
# must be run directly (not as part of another test) to get useful error output.
#
# If git repo is dirty (uncommitted test code changes), runs test-recursion FIRST
# to validate that recursion/pollution detection still work with the changes.
# This is critical because changes to test infrastructure (helpers.bash, etc.) could
# break the prerequisite or pollution detection systems. By running test-recursion
# first with a clean environment, we exercise these systems before running the full suite.
# If recursion is broken, we want to know immediately, not after running all tests.
.PHONY: test-setup
test-setup:
ifneq ($(GIT_DIRTY),)
@echo "Git repo is dirty (uncommitted changes detected)"
@echo "Running recursion test first to validate test infrastructure..."
$(MAKE) test-recursion
@echo "Recursion test passed, now running full test suite..."
endif
@$(MAKE) clean-envs
@$(MAKE) check-readme
@test/bats/bin/bats test/lib/foundation.bats
# Run standard tests - sequential tests in order, then standard independent tests
# Excludes optional/extra tests (e.g., test-pgtle-versions.bats) - use test-extra or test-all for those
#
# Note: We explicitly list all sequential tests rather than just running the last one
# because BATS only outputs TAP results for the test files directly invoked.
# If we only ran the last test, prerequisite tests would run but their results
# wouldn't appear in the output.
.PHONY: test
test:
@echo
@echo "Tip: Use 'make test-extra' for additional tests, or 'make test-all' for everything"
@echo
@$(MAKE) test-setup
@test/bats/bin/bats $(SEQUENTIAL_TESTS) $(STANDARD_TESTS)
@echo
@echo "Tip: Use 'make test-extra' for additional tests, or 'make test-all' for everything"
@echo
# Run ONLY extra/optional tests (e.g., test-pgtle-versions.bats)
# These tests have additional requirements (like multiple pg_tle versions installed)
# Use test-all to run standard tests plus extra tests together
.PHONY: test-extra
test-extra:
ifneq ($(EXTRA_TESTS),)
@echo
@echo "Tip: Use 'make test-all' to run both standard and extra tests"
@echo
@$(MAKE) test-setup
@test/bats/bin/bats $(EXTRA_TESTS)
@echo
@echo "Tip: Use 'make test-all' to run both standard and extra tests"
@echo
else
@echo "No extra tests found in test/extra/"
endif
# Run regular test suite PLUS extra/optional tests
# This passes all test files to bats in a single invocation for proper TAP output
.PHONY: test-all
test-all:
@$(MAKE) test-setup
@test/bats/bin/bats $(SEQUENTIAL_TESTS) $(STANDARD_TESTS) $(EXTRA_TESTS)
# Clean test environments
.PHONY: clean-envs
clean-envs:
@echo "Removing test environments..."
@rm -rf test/.envs
.PHONY: clean
clean: clean-envs
# Build README.html from README.asc
# Prefers asciidoctor over asciidoc
# Note: This works on the pgxntool source repository, not test environments
ASCIIDOC_CMD := $(shell which asciidoctor 2>/dev/null || which asciidoc 2>/dev/null)
PGXNTOOL_SOURCE_DIR := $(shell cd $(CURDIR)/../pgxntool && pwd)
.PHONY: readme
readme:
ifndef ASCIIDOC_CMD
$(error Could not find "asciidoc" or "asciidoctor". Add one of them to your PATH)
endif
@if [ ! -f "$(PGXNTOOL_SOURCE_DIR)/README.asc" ]; then \
echo "ERROR: README.asc not found at $(PGXNTOOL_SOURCE_DIR)/README.asc" >&2; \
exit 1; \
fi
@$(ASCIIDOC_CMD) $(if $(findstring asciidoctor,$(ASCIIDOC_CMD)),-a sectlinks -a sectanchors -a toc -a numbered,) "$(PGXNTOOL_SOURCE_DIR)/README.asc" -o "$(PGXNTOOL_SOURCE_DIR)/README.html"
# Check if README.html is up to date
#
# CRITICAL: This target checks if README.html is out of date BEFORE rebuilding.
# If out of date, we:
# 1. Set an error flag
# 2. Rebuild as a convenience for developers
# 3. Exit with error status (even after rebuilding)
#
# This ensures CI fails if README.html is out of date, while still providing
# a convenient auto-rebuild for local development.
#
# The rebuild is to make life easy FOR A PERSON. But having .html out of date
# IS AN ERROR and needs to ALWAYS be treated as such.
.PHONY: check-readme
check-readme:
@# Check if source file exists
@if [ ! -f "$(PGXNTOOL_SOURCE_DIR)/README.asc" ]; then \
echo "ERROR: README.asc not found at $(PGXNTOOL_SOURCE_DIR)/README.asc" >&2; \
exit 1; \
fi
@# Check if README.html is out of date (BEFORE rebuilding)
@OUT_OF_DATE=0; \
if [ "$(PGXNTOOL_SOURCE_DIR)/README.asc" -nt "$(PGXNTOOL_SOURCE_DIR)/README.html" ] 2>/dev/null; then \
OUT_OF_DATE=1; \
fi; \
if [ $$OUT_OF_DATE -eq 1 ]; then \
echo "ERROR: pgxntool/README.html is out of date relative to README.asc" >&2; \
echo "Rebuilding as a convenience, but this is an ERROR condition..." >&2; \
$(MAKE) -s readme 2>/dev/null || true; \
echo "README.html has been automatically updated, but you must commit the change." >&2; \
echo "This check ensures README.html stays up-to-date for automated testing." >&2; \
echo "To fix this, run: cd ../pgxntool && git add README.html && git commit" >&2; \
exit 1; \
fi
# To use this, do make print-VARIABLE_NAME
print-% : ; $(info $* is $(flavor $*) variable set to "$($*)") @true
# List all make targets
.PHONY: list
list:
sh -c "$(MAKE) -p no_targets__ | awk -F':' '/^[a-zA-Z0-9][^\$$#\/\\t=]*:([^=]|$$)/ {split(\$$1,A,/ /);for(i in A)print A[i]}' | grep -v '__\$$' | sort"