-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
52 lines (43 loc) · 1.82 KB
/
Copy pathMakefile
File metadata and controls
52 lines (43 loc) · 1.82 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
ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
BADGE_SCRIPT := $(ROOT)/scripts/update_coverage_badge.sh
.PHONY: test test-unit test-integration test-all coverage badge lint
NVIM ?= nvim
INIT := $(ROOT)/tests/minimal_init.lua
COV_INIT := $(ROOT)/tests/coverage_init.lua
UNIT_DIR := $(ROOT)/tests/unit
INTEG_DIR := $(ROOT)/tests/integration
LUACOV := $(HOME)/.luarocks/bin/luacov
# Run all unit tests (no server required)
test: test-unit
test-unit:
$(NVIM) --headless -u $(INIT) \
-c "lua require('plenary.test_harness').test_directory('$(UNIT_DIR)', { minimal_init = '$(INIT)' })" \
-c "qa!"
# Run integration tests (requires a live Swank server on 127.0.0.1:4005)
test-integration:
$(NVIM) --headless -u $(INIT) \
-c "lua require('plenary.test_harness').test_directory('$(INTEG_DIR)', { minimal_init = '$(INIT)' })" \
-c "qa!"
# Run everything
test-all: test-unit test-integration
MIN_COV := 80
# Run unit tests with luacov, then generate luacov.report.out
coverage:
@rm -f $(ROOT)/luacov.stats.out $(ROOT)/luacov.report.out
cd $(ROOT) && $(NVIM) --headless -u $(COV_INIT) \
-c "lua require('plenary.test_harness').test_directory('$(UNIT_DIR)', { minimal_init = '$(COV_INIT)', sequential = true })" \
-c "qa!"
cd $(ROOT) && $(LUACOV)
@echo ""
@echo "=== Coverage summary ==="
@grep -E "[0-9]+\.[0-9]+%" $(ROOT)/luacov.report.out || cat $(ROOT)/luacov.report.out
@echo ""
@TOTAL=$$(awk '/^Total/{gsub(/%/,"",$$NF); print int($$NF)}' $(ROOT)/luacov.report.out); \
echo "=== Total: $${TOTAL}% (minimum: $(MIN_COV)%) ==="; \
if [ "$${TOTAL}" -lt "$(MIN_COV)" ]; then \
echo "FAIL: coverage $${TOTAL}% is below the $(MIN_COV)% minimum (CONTRIBUTING.md)"; \
exit 1; \
fi
# Update the coverage badge in README.md (runs coverage first)
badge: coverage
@bash $(BADGE_SCRIPT)