-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (139 loc) · 3.65 KB
/
Makefile
File metadata and controls
165 lines (139 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
# Package name
PACKAGE=github.com/costa92/genericmap
# Default target
.PHONY: all
all: test
# Test commands
.PHONY: test
test:
@echo "Running tests..."
$(GOTEST) -v ./...
.PHONY: test-short
test-short:
@echo "Running short tests..."
$(GOTEST) -short -v ./...
.PHONY: test-race
test-race:
@echo "Running tests with race detection..."
$(GOTEST) -race -v ./...
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
.PHONY: test-coverage-func
test-coverage-func:
@echo "Running tests with function coverage..."
$(GOTEST) -coverprofile=coverage.out ./...
$(GOCMD) tool cover -func=coverage.out
# Benchmark commands
.PHONY: bench
bench:
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
.PHONY: bench-cpu
bench-cpu:
@echo "Running CPU benchmarks..."
$(GOTEST) -bench=. -benchmem -cpuprofile=cpu.prof ./...
.PHONY: bench-mem
bench-mem:
@echo "Running memory benchmarks..."
$(GOTEST) -bench=. -benchmem -memprofile=mem.prof ./...
.PHONY: bench-compare
bench-compare:
@echo "Running benchmarks for comparison..."
$(GOTEST) -bench=. -benchmem -count=5 ./... | tee bench.txt
# Code quality
.PHONY: fmt
fmt:
@echo "Formatting code..."
$(GOFMT) -s -w .
.PHONY: vet
vet:
@echo "Running go vet..."
$(GOCMD) vet ./...
.PHONY: lint
lint:
@echo "Running golint..."
@which golint > /dev/null || (echo "Installing golint..." && $(GOGET) golang.org/x/lint/golint)
golint ./...
.PHONY: check
check: fmt vet test
@echo "All checks passed!"
# Module management
.PHONY: mod-tidy
mod-tidy:
@echo "Tidying modules..."
$(GOMOD) tidy
.PHONY: mod-verify
mod-verify:
@echo "Verifying modules..."
$(GOMOD) verify
.PHONY: mod-download
mod-download:
@echo "Downloading modules..."
$(GOMOD) download
# Build commands
.PHONY: build
build:
@echo "Building..."
$(GOBUILD) -v ./...
# Clean commands
.PHONY: clean
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -f coverage.out coverage.html
rm -f cpu.prof mem.prof
rm -f bench.txt
.PHONY: clean-cache
clean-cache:
@echo "Cleaning build cache..."
$(GOCMD) clean -cache
# Development workflow
.PHONY: dev
dev: fmt vet test
@echo "Development checks complete!"
.PHONY: ci
ci: mod-verify fmt vet test-race test-coverage
@echo "CI pipeline complete!"
# Performance analysis
.PHONY: profile-cpu
profile-cpu: bench-cpu
@echo "Analyzing CPU profile..."
$(GOCMD) tool pprof cpu.prof
.PHONY: profile-mem
profile-mem: bench-mem
@echo "Analyzing memory profile..."
$(GOCMD) tool pprof mem.prof
# Help
.PHONY: help
help:
@echo "Available targets:"
@echo " test - Run all tests"
@echo " test-short - Run short tests"
@echo " test-race - Run tests with race detection"
@echo " test-coverage - Run tests with coverage report"
@echo " bench - Run benchmarks"
@echo " bench-compare - Run benchmarks for comparison"
@echo " fmt - Format code"
@echo " vet - Run go vet"
@echo " lint - Run golint"
@echo " check - Run fmt, vet, and test"
@echo " dev - Development workflow (fmt, vet, test)"
@echo " ci - CI pipeline (verify, fmt, vet, race, coverage)"
@echo " build - Build the package"
@echo " clean - Clean build artifacts"
@echo " mod-tidy - Tidy modules"
@echo " profile-cpu - Run CPU profiling"
@echo " profile-mem - Run memory profiling"
@echo " help - Show this help message"