| 1 | .PHONY: vet fmt-check test race browser ci |
| 2 | |
| 3 | # ci is the one gate: what a runner executes and what you run before |
| 4 | # pushing are the same definition (amadan's own rule: CI steps |
| 5 | # delegate to make targets, never keep their own copies). |
| 6 | ci: vet fmt-check test race browser |
| 7 | |
| 8 | # The example, when there is one, is its own module with a replace |
| 9 | # back here, so ./... does not reach it; each target visits it |
| 10 | # explicitly. |
| 11 | vet: |
| 12 | go vet ./... |
| 13 | @if [ -d example ]; then cd example && go vet ./... && go vet -tags browser ./...; fi |
| 14 | |
| 15 | fmt-check: |
| 16 | @out=$$(gofmt -l .); if [ -n "$$out" ]; then echo "gofmt needed:"; echo "$$out"; exit 1; fi |
| 17 | |
| 18 | # -count=1 on purpose: these tests build a real SQLite database; a |
| 19 | # cached PASS re-reports one run as though it were every run. |
| 20 | test: |
| 21 | go test ./... -count=1 |
| 22 | @if [ -d example ]; then cd example && go test ./... -count=1; fi |
| 23 | |
| 24 | # -race needs cgo; everything else runs with the default toolchain, so |
| 25 | # this target sets CGO_ENABLED for its own command only. |
| 26 | race: |
| 27 | CGO_ENABLED=1 go test ./... -race -count=1 |
| 28 | @if [ -d example ]; then cd example && CGO_ENABLED=1 go test ./... -race -count=1; fi |
| 29 | |
| 30 | # The browser drive, via rastrillo's harness. It fails, not skips, |
| 31 | # without a browser (rastrillo's rule: a skip is not a pass). It runs in |
| 32 | # each of the module and the example that has a browser test file, so |
| 33 | # an empty package does not fail the gate; the example's drives the |
| 34 | # starter pages. |
| 35 | browser: |
| 36 | @ran=; for dir in . example; do \ |
| 37 | found=; for f in $$dir/*_browser_test.go $$dir/browser_test.go; do \ |
| 38 | if [ -f "$$f" ]; then found=1; fi; \ |
| 39 | done; \ |
| 40 | if [ -n "$$found" ]; then \ |
| 41 | (cd $$dir && go test -tags browser -run TestBrowser -count=1 .) || exit 1; \ |
| 42 | ran=1; \ |
| 43 | fi; \ |
| 44 | done; \ |
| 45 | if [ -z "$$ran" ]; then echo "browser: no browser test file yet, nothing to run"; fi |
| 46 | |