Makefile RawHistoryFolder
1.PHONY: bin build test vet race mod-check mocks mocks-check fakes-check arch perf-check check
2
3GOBIN_DIR := $(or $(shell go env GOBIN),$(firstword $(subst :, ,$(shell go env GOPATH)))/bin)
4MOCKERY ?= $(GOBIN_DIR)/mockery
5HEXCHECK ?= $(GOBIN_DIR)/hexcheck
6
7# Build a fresh binary.
8bin:
9 CGO_ENABLED=0 go build -o bin/nefercap ./cmd/nefercap
10build:
11 CGO_ENABLED=0 go build ./...
12test:
13 CGO_ENABLED=0 go test ./...
14vet:
15 CGO_ENABLED=0 go vet ./...
16race:
17 # cgo is enabled only for the race test binary.
18 CGO_ENABLED=1 go test -race ./...
19# go.mod and go.sum must be tidy (prints the diff and fails otherwise).
20mod-check:
21 go mod tidy -diff
22
23# Regenerate from scratch so mocks of removed interfaces disappear too.
24mocks:
25 @test -x '$(MOCKERY)' || { echo 'mockery not found or not executable: $(MOCKERY)' >&2; exit 1; }
26 rm -rf internal/mocks
27 find internal -name '*_mock_test.go' -delete
28 $(MOCKERY)
29
30MOCKS := internal/mocks ':(glob)internal/**/*_mock_test.go'
31# Regenerate, then require the mocks to be tracked and unchanged.
32mocks-check: mocks
33 git diff --exit-code -- $(MOCKS)
34 @test -z "$$(git ls-files --others --exclude-standard -- $(MOCKS))" || { echo 'untracked generated mocks: commit them' >&2; exit 1; }
35
36# Test doubles come from Mockery only: no handwritten fake/stub/spy types.
37# grep exit 1 (no match) passes; 0 (match) and 2 (error) fail.
38FAKES := ^\s*type\s+\w*(fake|stub|spy|dummy|mock)\w*|^\s*\w*(fake|stub|spy|dummy|mock)\w*(\[[^]]*\])?\s+(struct|interface)\b
39fakes-check:
40 @dirs=$$(ls -d internal cmd 2>/dev/null); [ -n "$$dirs" ] || exit 0; \
41 rc=0; grep -rniE '$(FAKES)' --include='*_test.go' --exclude='*_mock_test.go' $$dirs || rc=$$?; \
42 [ $$rc -eq 1 ] || { [ $$rc -eq 0 ] && echo 'handwritten test double: add an interface and a Mockery entry (see AGENTS.md)' >&2; exit 1; }
43arch:
44 $(HEXCHECK) -hexcheck.config .hexcheck.yaml -hexcheck.root . ./...
45# Steady-state allocation guards. PERF_TESTS lists exact test names and PERF_PKGS
46# the packages holding them. Every named test must exist, so the guard cannot
47# pass vacuously when a frame-path test is removed or renamed.
48PERF_TESTS := TestFrameAllocations TestSelectionAllocations TestPickerAllocations TestMonitorGridAllocations TestMonitorGridPhysicalAllocations TestGridAllocations TestGridModeAllocations TestSelectorAllocations TestModeToggleAllocations TestRefreshAllocations TestVideoRowsAllocations TestWriteSteadyStateAllocations TestResolveOutputAllocations TestCaptureAllocations
49PERF_PKGS := ./internal/ports ./internal/core ./internal/adapters/selection ./internal/adapters/indicator ./internal/adapters/ffmpeg ./internal/app ./internal/adapters/wayland
50perf_empty :=
51perf_space := $(perf_empty) $(perf_empty)
52PERF_RE := ^($(subst $(perf_space),|,$(strip $(PERF_TESTS))))$$
53perf-check:
54 @out=$$(CGO_ENABLED=0 go test -list '$(PERF_RE)' $(PERF_PKGS)) || { echo "$$out" >&2; exit 1; }; \
55 for t in $(PERF_TESTS); do \
56 printf '%s\n' "$$out" | grep -qx "$$t" || { echo "perf-check: test $$t not found in $(PERF_PKGS)" >&2; exit 1; }; \
57 done
58 CGO_ENABLED=0 go test $(PERF_PKGS) -run '$(PERF_RE)' -count=1
59check: mod-check vet test arch fakes-check perf-check