@@ -9,6 +9,7 @@ GOCLEAN=$(GOCMD) clean
99GOTEST =$(GOCMD ) test
1010GOTOOL =$(GOCMD ) tool
1111GOMOD =$(GOCMD ) mod
12+ GOGENERATE =$(GOCMD ) generate
1213GOPATH =$(shell $(GOCMD ) env GOPATH)
1314GOBIN =$(shell $(GOCMD ) env GOBIN)
1415
@@ -31,7 +32,7 @@ COVERAGE_FILE=coverage.out
3132COVERAGE_SSH_FILE =coverage-ssh.out
3233JUNIT_FILE =unit-tests.xml
3334
34- BUILD =build/
35+ BUILD =$( realpath build) /
3536
3637RESTIC_GEN =$(BUILD ) restic-generator
3738RESTIC_DIR =$(BUILD ) restic-
@@ -122,8 +123,27 @@ prepare_build: verify download
122123
123124prepare_test : verify download $(GOBIN ) /mockery # # Generate mocks
124125 @echo " [*] $@ "
125- find . -path " */mocks/*" -exec rm {} \;
126- " $( GOBIN) /mockery" --config .mockery.yml
126+ @find . -path " */mocks/*" -exec rm {} \;
127+ @" $( GOBIN) /mockery" --config .mockery.yml
128+
129+ $(BUILD ) test-args : ./testhelpers/args/* .go # # Build the test-args binary
130+ @echo " [*] $@ "
131+ @$(GOBUILD ) -v -o $(BUILD ) test-args ./testhelpers/args
132+
133+ $(BUILD ) test-echo : ./testhelpers/echo/* .go # # Build the test-echo binary
134+ @echo " [*] $@ "
135+ @$(GOBUILD ) -v -o $(BUILD ) test-echo ./testhelpers/echo
136+
137+ $(BUILD ) test-crontab : ./testhelpers/crontab/* .go # # Build the test-crontab binary
138+ @echo " [*] $@ "
139+ @$(GOBUILD ) -v -o $(BUILD ) test-crontab ./testhelpers/crontab
140+
141+ $(BUILD ) test-shell : ./testhelpers/shell/* .go # # Build the test-shell binary
142+ @echo " [*] $@ "
143+ @$(GOBUILD ) -v -o $(BUILD ) test-shell ./testhelpers/shell
144+
145+ .PHONY : test-helpers
146+ test-helpers : $(BUILD ) test-args $(BUILD ) test-echo $(BUILD ) test-crontab $(BUILD ) test-shell # # Build all test helper binaries
127147
128148download : verify # # Download dependencies
129149 @echo " [*] $@ "
@@ -178,13 +198,26 @@ build-windows: prepare_build ## Build the binary for Windows
178198
179199build-all : build-mac build-linux build-pi build-windows # # Build the binary for all platforms
180200
181- test : $(GOBIN ) /gotestsum prepare_test # # Run unit tests
201+ test : export TEST_HELPERS=$(BUILD )
202+ test : $(GOBIN ) /gotestsum prepare_test test-helpers # # Run unit tests
203+ @echo " [*] $@ "
204+ @$(GOBIN ) /gotestsum -- -count=1 $(TESTS )
205+
206+ test-short : export TEST_HELPERS=$(BUILD )
207+ test-short : $(GOBIN ) /gotestsum prepare_test test-helpers # # Run unit tests in short mode
182208 @echo " [*] $@ "
183- $(GOBIN ) /gotestsum $(TESTS )
209+ @ $(GOBIN ) /gotestsum -- -short -count=1 $(TESTS )
184210
185- test-ci : $(GOBIN ) /gotestsum prepare_test # # Run unit tests with coverage (for CI)
211+ test-race : export TEST_HELPERS=$(BUILD )
212+ test-race : $(GOBIN ) /gotestsum prepare_test test-helpers # # Run unit tests with race detector
186213 @echo " [*] $@ "
187- $(GOBIN ) /gotestsum --junitfile $(JUNIT_FILE ) -- -race -short -tags=fuse -coverprofile=' $(COVERAGE_FILE)' ./...
214+ @$(GOBIN ) /gotestsum -- -short -race -count=1 $(TESTS )
215+
216+ test-ci : export TEST_HELPERS=$(BUILD )
217+ test-ci : $(GOBIN ) /gotestsum prepare_test test-helpers # # Run unit tests with coverage (for CI)
218+ @echo " [*] $@ "
219+ @$(GOGENERATE ) ./...
220+ @$(GOBIN ) /gotestsum --junitfile $(JUNIT_FILE ) -- -race -short -count=1 -tags=fuse -coverprofile=' $(COVERAGE_FILE)' ./...
188221
189222coverage : # # Generate coverage report
190223 @echo " [*] $@ "
@@ -209,6 +242,11 @@ clean: ## Clean up the build artifacts
209242 restic_* _linux_amd64* \
210243 ${BUILD} restic* \
211244 ${BUILD} rclone* \
245+ ${BUILD} test* \
246+ * .test \
247+ * .log \
248+ * .out \
249+ * .xml \
212250 dist/*
213251 find . -path " */mocks/*" -exec rm {} \;
214252 restic cache --cleanup
@@ -385,3 +423,10 @@ stop-ssh-server: ## Stop the SSH server and clean up temporary files
385423ssh-test : # # Run SSH client tests
386424 @echo " [*] $@ "
387425 @go test -run TestSSHClient -v -race -tags ssh -coverprofile=' $(COVERAGE_SSH_FILE)' ./ssh
426+
427+ .PHONY : compile-tests
428+ compile-tests : export TEST_HELPERS=$(BUILD )
429+ compile-tests : test-helpers # # Pre-compile all tests for running on BSD VMs
430+ @echo " [*] $@ "
431+ @$(GOGENERATE ) ./...
432+ @$(GOTEST ) -c . ./batt ./calendar ./config/... ./crond ./dial ./filesearch ./lock ./monitor ./priority ./remote ./restic ./schedule ./shell ./ssh ./term ./user ./util/...
0 commit comments