From d5758be3222a9bab350865009228e3b1e32f0fe9 Mon Sep 17 00:00:00 2001 From: Bryan Frimin Date: Mon, 14 Jul 2025 12:37:27 +0200 Subject: [PATCH] Add make test target Signed-off-by: Bryan Frimin --- .gitignore | 3 ++- GNUmakefile | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index abff4c056..2bac2d0aa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ node_modules/ dist/ sbom.json sbom-docker.json -*_sbom.json \ No newline at end of file +*_sbom.json +*.out diff --git a/GNUmakefile b/GNUmakefile index 4493bf21b..44e853ad5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -15,8 +15,15 @@ VERSION= 0.40.0 LDFLAGS= -ldflags "-X 'main.version=$(VERSION)' -X 'main.env=prod'" GCFLAGS= -gcflags="-e" -GO_BUILD= CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) $(GO) build $(LDFLAGS) $(GCFLAGS) -GO_GENERATE= $(GO) generate +CGO_ENABLED?= 0 +GOOS?= + +GO_BASE= CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) go +GO_BUILD= $(GO_BASE) build $(LDFLAGS) $(GCFLAGS) +GO_GENERATE= $(GO_BASE) generate +GO_TEST= $(GO_BASE) test $(TEST_FLAGS) + +TEST_FLAGS?= -race -cover -coverprofile=coverage.out DOCKER_IMAGE_NAME= ghcr.io/getprobo/probo DOCKER_TAG_NAME?= latest @@ -34,6 +41,27 @@ lint: fmt-check vet vet: $(GO) vet ./... +.PHONY: test +test: ## Run tests with race detection and coverage (usage: make test [MODULE=./pkg/some/module]) + $(GO_TEST) $(if $(MODULE),$(MODULE),./...) + +.PHONY: test-verbose +test-verbose: TEST_FLAGS+=-v +test-verbose: test ## Run tests with verbose output + +.PHONY: test-short +test-short: TEST_FLAGS+=-short +test-short: test ## Run short tests only + +.PHONY: coverage-report +coverage-report: test ## Generate HTML coverage report + $(GO) tool cover -html=coverage.out -o coverage.html + @echo "Coverage report generated: coverage.html" + +.PHONY: test-bench +test-bench: TEST_FLAGS+=-bench=. +test-bench: test ## Run benchmark tests + .PHONY: build build: @probo/console bin/probod @@ -106,6 +134,7 @@ clean: ## Clean the project (node_modules and build artifacts) $(RM) -rf node_modules $(RM) -rf apps/console/{dist,node_modules} $(RM) -rf sbom-docker.json sbom.json + $(RM) -rf coverage.out coverage.html .PHONY: stack-up stack-up: ## Start the docker stack as a deamon