.PHONY: vet fmt-check test race browser ci

# ci is the one gate: what a runner executes and what you run before
# pushing are the same definition (amadan's own rule — CI steps
# delegate to make targets, never keep their own copies).
#
# The node tests are not a separate target: js_test.go runs them from
# inside `go test`, skipping when node is absent, so a runner without
# node still reports the Go half honestly instead of failing a step
# it cannot run.
ci: vet fmt-check test race browser

# The example is its own module with a replace back here, so ./...
# does not reach it; each target visits it explicitly.
vet:
	go vet ./...
	cd example && go vet ./...

fmt-check:
	@out=$$(gofmt -l .); if [ -n "$$out" ]; then echo "gofmt needed:"; echo "$$out"; exit 1; fi

# -count=1 on purpose: these tests build a real SQLite database and
# race goroutines against it; a cached PASS re-reports one scheduling
# as though it were every scheduling.
test:
	go test ./... -count=1
	cd example && go test ./... -count=1

# -race needs cgo; everything else runs with the default toolchain, so
# this target sets CGO_ENABLED for its own command only.
race:
	CGO_ENABLED=1 go test ./... -race -count=1

# The browser drive: the module, the worker import and the handlers
# agreeing in a real Chromium, via rastrillo's harness. It fails, not
# skips, without a browser — rastrillo's rule (RASTRILLO_BROWSER_OPTIONAL
# stays unset): a skip is not a pass, and a machine that loses its
# browser should say so loudly.
browser:
	go test -tags browser -run TestBrowser -count=1 .
