aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: b4ece5d753edd16af608f2e2e23350c894e17a27 (plain)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# Makefile for org-drill
#
# Usage:
#   make help              - Show this help message
#   make test              - Run all tests (unit + robot)
#   make test-unit         - Run ERT unit tests only
#   make test-file FILE=org-drill-test.el  - Run specific test file
#   make test-name TEST=load-test          - Run tests matching pattern
#   make robot             - Run basic robot tests
#   make robot-all         - Run all robot tests
#   make docker-test       - Run tests in Docker (multiple Emacs versions)
#   make install           - Install dependencies via Cask
#   make clean             - Remove generated files

# Emacs binary to use (override with: make EMACS=emacs29 test)
EMACS ?= emacs
# Check for Cask in PATH or common installation location
CASK ?= $(shell command -v cask 2>/dev/null || echo "$(HOME)/.cask/bin/cask")

# Include local overrides if present
-include makefile-local

ifdef EMACS
EMACS_ENV=EMACS=$(EMACS)
endif

# Test directories and files
TEST_DIR = tests
# Match test-*.el pattern, excluding integration tests
UNIT_TESTS = $(filter-out $(TEST_DIR)/%integration-test.el, \
               $(wildcard $(TEST_DIR)/test-*.el))
INTEGRATION_TESTS = $(wildcard $(TEST_DIR)/*-integration-test.el)
ALL_TESTS = $(UNIT_TESTS) $(INTEGRATION_TESTS)

# Emacs batch flags
EMACS_BATCH = $(EMACS) --batch --no-site-file --no-site-lisp

# Docker configuration
DOCKER_TAG=26

.PHONY: help test test-all test-unit test-integration test-file test-name install build clean clean-elc
.PHONY: robot robot-all robot-basic robot-leitner robot-all-card robot-spanish robot-explainer
.PHONY: docker-test test-cp test-git

# Default target
help:
	@echo "org-drill Test Targets:"
	@echo ""
	@echo "Primary Targets:"
	@echo "  make help              - Show this help message"
	@echo "  make test              - Run all tests (unit + robot)"
	@echo "  make test-unit         - Run unit tests only ($(words $(UNIT_TESTS)) files)"
	@echo "  make test-integration  - Run integration tests only ($(words $(INTEGRATION_TESTS)) files)"
	@echo "  make robot             - Run basic robot tests"
	@echo "  make robot-all         - Run all robot tests"
	@echo ""
	@echo "Selective Testing:"
	@echo "  make test-file FILE=<filename>  - Run specific test file"
	@echo "  make test-name TEST=<pattern>   - Run tests matching pattern"
	@echo ""
	@echo "Advanced Targets:"
	@echo "  make install           - Install dependencies via Cask"
	@echo "  make build             - Build package via Cask"
	@echo "  make docker-test       - Run tests in Docker (multiple Emacs versions)"
	@echo "  make clean             - Remove generated files"
	@echo "  make clean-elc         - Remove compiled .elc files"
	@echo ""
	@echo "Examples:"
	@echo "  make test-file FILE=org-drill-test.el"
	@echo "  make test-name TEST=load-test"
	@echo "  make test-name TEST='find-*'"
	@echo "  make EMACS=emacs29 test   # Use specific Emacs version"
	@echo ""
	@echo "Robot Test Targets:"
	@echo "  make robot-basic       - Run basic robot test"
	@echo "  make robot-leitner     - Run Leitner algorithm test"
	@echo "  make robot-all-card    - Run all-card robot test"
	@echo "  make robot-spanish     - Run Spanish vocabulary test"
	@echo "  make robot-explainer   - Run explainer robot test"

# Default: run all tests
all: robot test-unit

# Install dependencies
install:
	@if ! command -v $(CASK) >/dev/null 2>&1; then \
		echo "[✗] Cask not found. Please install Cask first:"; \
		echo "    https://github.com/cask/cask"; \
		echo "    Or: curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python"; \
		exit 1; \
	fi
	@echo "[i] Installing dependencies via Cask..."
	@$(EMACS_ENV) $(CASK) install
	@echo "[✓] Dependencies installed"

# Build package
build:
	$(EMACS_ENV) $(CASK) build

# Run all tests
test: robot test-unit

# Full test suite
test-all: robot-all test-unit test-integration

# Run unit tests only
test-unit: install
	@echo "[i] Running unit tests ($(words $(UNIT_TESTS)) files)..."
	@failed=0; \
	for test in $(UNIT_TESTS); do \
		echo "  Testing $$test..."; \
		$(EMACS_ENV) $(CASK) emacs --batch -q \
			-l ert \
			-l assess \
			-l org-drill.el \
			-l $$test \
			-f ert-run-tests-batch-and-exit || failed=$$((failed + 1)); \
	done; \
	if [ $$failed -eq 0 ]; then \
		echo "[✓] All unit tests passed"; \
	else \
		echo "[✗] $$failed unit test file(s) failed"; \
		exit 1; \
	fi

# Run integration tests only
test-integration: install
	@echo "[i] Running integration tests ($(words $(INTEGRATION_TESTS)) files)..."
	@if [ $(words $(INTEGRATION_TESTS)) -eq 0 ]; then \
		echo "[i] No integration tests found"; \
	else \
		failed=0; \
		for test in $(INTEGRATION_TESTS); do \
			echo "  Testing $$test..."; \
			$(EMACS_ENV) $(CASK) emacs --batch -q \
				-l ert \
				-l assess \
				-l org-drill.el \
				-l $$test \
				-f ert-run-tests-batch-and-exit || failed=$$((failed + 1)); \
		done; \
		if [ $$failed -eq 0 ]; then \
			echo "[✓] All integration tests passed"; \
		else \
			echo "[✗] $$failed integration test file(s) failed"; \
			exit 1; \
		fi; \
	fi

# Run specific test file
# Usage: make test-file FILE=org-drill-test.el
test-file: install
ifndef FILE
	@echo "[✗] Error: FILE parameter required"
	@echo "Usage: make test-file FILE=org-drill-test.el"
	@exit 1
endif
	@echo "[i] Running tests in $(FILE)..."
	@$(EMACS_ENV) $(CASK) emacs --batch -q \
		-l ert \
		-l assess \
		-l org-drill.el \
		-l $(TEST_DIR)/$(FILE) \
		-f ert-run-tests-batch-and-exit
	@echo "[✓] Tests in $(FILE) complete"

# Run specific test by name/pattern
# Usage: make test-name TEST=load-test
#        make test-name TEST="find-*"
test-name: install
ifndef TEST
	@echo "[✗] Error: TEST parameter required"
	@echo "Usage: make test-name TEST=load-test"
	@echo "       make test-name TEST='find-*'"
	@exit 1
endif
	@echo "[i] Running tests matching pattern: $(TEST)..."
	@$(EMACS_ENV) $(CASK) emacs --batch -q \
		-l ert \
		-l assess \
		-l org-drill.el \
		$(foreach test,$(ALL_TESTS),-l $(test)) \
		--eval '(ert-run-tests-batch-and-exit "$(TEST)")'
	@echo "[✓] Tests matching '$(TEST)' complete"

#
# Robot Tests (Automated UI Tests)
#

# Basic robot test (default for quick testing)
robot: robot-basic

# All robot tests
robot-all: robot-basic robot-leitner robot-all-card robot-spanish

# Individual robot tests
robot-basic: clean-elc
	@echo "[i] Running basic robot test..."
	@$(EMACS_ENV) ./robot/basic-run.sh $(SMALL)
	@echo "[✓] Basic robot test complete"

robot-leitner: clean-elc
	@echo "[i] Running Leitner robot test..."
	@$(EMACS_ENV) ./robot/leitner-run.sh $(SMALL)
	@echo "[✓] Leitner robot test complete"

robot-all-card: clean-elc
	@echo "[i] Running all-card robot test..."
	@$(EMACS_ENV) ./robot/all-card-run.sh $(SMALL)
	@echo "[✓] All-card robot test complete"

robot-spanish: clean-elc
	@echo "[i] Running Spanish robot test..."
	@$(EMACS_ENV) ./robot/spanish-run.sh $(SMALL)
	@echo "[✓] Spanish robot test complete"

robot-explainer: clean-elc
	@echo "[i] Running explainer robot test..."
	@$(EMACS_ENV) ./robot/explainer-run.sh $(SMALL)
	@echo "[✓] Explainer robot test complete"

#
# Docker Testing (Multiple Emacs Versions)
#

test-cp:
	docker run -it --rm --name docker-cp \
		-v $(PWD):/usr/src/app \
		-w /usr/src/app \
		--entrypoint=/bin/bash \
		silex/emacs:$(DOCKER_TAG)-dev ./test-by-cp

test-git:
	docker run -it --rm --name docker-git \
		-v $(PWD):/usr/src/app \
		-w /usr/src/app \
		--entrypoint=/bin/bash \
		silex/emacs:$(DOCKER_TAG)-dev ./test-from-git

docker-test:
	@echo "[i] Running Docker tests across multiple Emacs versions..."
	@$(MAKE) test-git DOCKER_TAG=27.2
	@$(MAKE) test-cp DOCKER_TAG=27.2
	@$(MAKE) test-git DOCKER_TAG=26.3
	@$(MAKE) test-cp DOCKER_TAG=26.3
	@echo "[✓] Docker tests complete"

#
# Cleanup
#

clean-elc:
	@echo "[i] Cleaning compiled .elc files..."
	@find . -name "*.elc" -delete
	@echo "[✓] Clean .elc complete"

clean:
	@echo "[i] Cleaning generated files..."
	@find . -name "*.elc" -delete
	@find $(TEST_DIR) -name "*-test-*" -type f -delete
	@echo "[✓] Clean complete"