-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
162 lines (130 loc) · 4.4 KB
/
Makefile
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
# vim: ts=4 sw=4 ft=make
# Packages to run exhaustive tests against
EXHAUSTIVE_PKGS = github.com/charlievieth/strcase \
github.com/charlievieth/strcase/bytcase
# Run tests and linters. If this passes then CI tests
# should also pass.
.PHONY: all
all: install test testbenchmarks testgenerate testgenpkg vet golangci-lint
include common.mk
# Install pre-commit hooks and download modules
.PHONY: install
install: pre-commit
@$(GO) mod download
@$(GO) install
# Run verbose tests
testverbose: override GO_TEST_FLAGS += -v
# Run short tests
testshort: override GO_TEST_FLAGS += -short
testshort: override GO_COVER_FLAGS = ''
# TODO: add back "testinvalid" once we find an easy way
# to construct fuzz tests with invalid UTF-8 sequences.
.PHONY: test testshort testverbose
test testshort testverbose:
@GOGC=$(GO_GOGC) $(GO_TEST) ./...
# Run exhaustive fuzz tests
.PHONY: exhaustive
exhaustive:
@GOGC=$(GO_GOGC) $(GO_TEST) $(EXHAUSTIVE_PKGS) -exhaustive
# Generate code coverage report for strcase/bytecase
.PHONY: codecov
codecov: override GO_COVER_FLAGS = -covermode=count
codecov: override GO_COVER_FLAGS += -coverprofile=coverage.txt
codecov: exhaustive
# Assert that there are no skipped tests
.PHONY: testskipped
testskipped:
@if $(MAKE) testverbose | $(xgrep) --fixed-strings -- '--- SKIP:'; then \
echo ''; \
echo '$(red)FAIL: $(cyan)^^^ skipped tests ^^^$(term-reset)'; \
echo ''; \
exit 1; \
fi
# The gen package is separate from the strcase package (so we don't pollute
# our go.mod with its dependencies) so we need to cd into its directory to
# run the tests.
.PHONY: testgenpkg
testgenpkg:
@$(MAKE) -C $(MAKEFILE_DIR)/internal/gen --quiet test
# Test that `go generate` does not change tables.go
.PHONY: testgenerate
testgenerate: bin/gen
@if ! $(GEN_TARGET) -dry-run -skip-tests >/dev/null; then \
$(GEN_TARGET) -dry-run -skip-tests; \
fi;
# Make sure the benchmarks pass (we run them with a short benchtime)
.PHONY: testbenchmarks
testbenchmarks:
@cd $(MAKEFILE_DIR) && ./scripts/test-benchmarks.bash
# Run all tests (slow)
.PHONY: testall
testall: exhaustive testskipped testgenerate testgenpkg
# CI tests
.PHONY: ci
ci: test
ci: testbenchmarks
ci: vet
# Calibrate brute-force cutover
.PHONY: calibrate
calibrate: GO_COVER_FLAGS =
calibrate: GO_TEST_FLAGS += -v
calibrate:
@$(GO_TEST) -run 'Test.*Calibrate' -calibrate
.PHONY: vet-strcase
vet-strcase:
@$(GO) vet ./...
.PHONY: vet-gen
vet-gen:
@$(GO) vet -tags gen gen.go
.PHONY: vet-genpkg
vet-genpkg:
@cd $(MAKEFILE_DIR)/internal/gen && $(MAKE) --quiet vet
# NOTE: we don't run vet-genpkg here since it requires Go version 1.20
# and we run this against Go 1.19 in CI.
.PHONY: vet
vet: vet-strcase vet-gen
golangci-lint-gen: override GOLANGCI_EXTRA_FLAGS += --build-tags=gen gen.go
golangci-lint-gen: override GOLANGCI_SKIP =
# Run golangci-lint
.PHONY: golangci-lint-strcase golangci-lint-gen
golangci-lint-strcase golangci-lint-gen: bin/golangci-lint
@$(GOLANGCI_TARGET) run $(GOLANGCI_FLAGS)
.PHONY: golangci-lint
golangci-lint: golangci-lint-strcase golangci-lint-gen
.PHONY: lint
lint: vet golangci-lint golangci-lint-gen
# Make sure there aren't any comments that need addressing (TODO or WARN)
#
# NOTE: not currently part of the "lint" target.
.PHONY: lint-comments
lint-comments:
@if $(xgrep) $(GREP_COMMENTS) $(COMMENTS); then \
echo ''; \
echo '$(red)FAIL: $(cyan)address comments!$(term-reset)'; \
exit 1; \
fi
# Generate tables.go file
.PHONY: generate
generate:
@$(GO) generate
# Install pre-commit hook
# TODO: omit on Windows ???
.git/hooks/pre-commit: scripts/pre-commit
@mkdir -p $(MAKEFILE_DIR)/.git/hooks
ln -s $(MAKEFILE_DIR)/scripts/pre-commit $(MAKEFILE_DIR)/.git/hooks/pre-commit
# Install pre-commit hooks
# TODO: omit on Windows ???
pre-commit: .git/hooks/pre-commit
# Run pre-release tests (excluding: golangci-lint)
.PHONY: release
release: exhaustive testgenpkg testgenerate testbenchmarks calibrate vet
# Print information about the version of go being used
.PHONY: env
env:
@$(GO) env
.PHONY: clean
clean:
@rm -f cpu*.out mem*.out
@rm -rf DATA bin
@$(GO) -i ./...
@cd $(MAKEFILE_DIR)/internal/gen && $(MAKE) --quiet clean