1
- # We list packages with shell scripts and loop through them to avoid testing with ./...
2
- # Running go test ./... will run tests in all packages concurrently which can lead to
3
- # unexpected errors.
4
- #
5
- # TODO(GODRIVER-2093): Use ./... to run tests in all packages with parallelism and remove
6
- # these PKG variables and loops from all make targets.
7
- PKGS = $(shell etc/list_pkgs.sh)
8
- TEST_PKGS = $(shell etc/list_test_pkgs.sh)
9
-
10
1
ATLAS_URIS = "$(ATLAS_FREE ) " "$(ATLAS_REPLSET ) " "$(ATLAS_SHARD ) " "$(ATLAS_TLS11 ) " "$(ATLAS_TLS12 ) " "$(ATLAS_FREE_SRV ) " "$(ATLAS_REPLSET_SRV ) " "$(ATLAS_SHARD_SRV ) " "$(ATLAS_TLS11_SRV ) " "$(ATLAS_TLS12_SRV ) " "$(ATLAS_SERVERLESS ) " "$(ATLAS_SERVERLESS_SRV ) "
11
- GODISTS =linux/amd64 linux/386 linux/arm64 linux/arm linux/s390x
12
2
TEST_TIMEOUT = 1800
13
3
14
4
# ## Utility targets. ###
15
5
.PHONY : default
16
- default : add-license build build-examples check-env check-fmt check-modules lint test-short
6
+ default : add-license build check-fmt check-modules lint test-short
17
7
8
+ # Find all .go files not in the vendor directory and try to write a license notice. Then check for
9
+ # any changes made with -G. to ignore permissions changes. Exit with a non-zero exit code if there
10
+ # is a diff.
18
11
.PHONY : add-license
19
12
add-license :
20
- # Find all .go files not in the vendor directory and try to write a license notice.
21
13
find . -path ./vendor -prune -o -type f -name " *.go" -print | xargs ./etc/add_license.sh
22
- # Check for any changes made with -G. to ignore permissions changes. Exit with a non-zero
23
- # exit code if there is a diff.
24
14
git diff -G. --quiet
25
15
26
16
.PHONY : build
27
- build :
28
- go build $(BUILD_TAGS ) $(PKGS )
29
-
30
- .PHONY : build-examples
31
- build-examples :
32
- go build $(BUILD_TAGS ) ./examples/...
33
-
34
- .PHONY : build-no-tags
35
- build-no-tags :
36
- go build $(PKGS )
17
+ build : build-tests
18
+ go build $(BUILD_TAGS ) ./...
37
19
20
+ # Use ^$ to match no tests so that no tests are actually run but all tests are
21
+ # compiled. Run with -short to ensure none of the TestMain functions try to
22
+ # connect to a server.
38
23
.PHONY : build-tests
39
24
build-tests :
40
- for TEST in $( TEST_PKGS) ; do \
41
- go test $(BUILD_TAGS ) -c $$ TEST ; \
42
- if [ $$ ? -ne 0 ]; \
43
- then \
44
- exit 1; \
45
- fi \
46
- done
25
+ go test -short $(BUILD_TAGS ) -run ^$$ ./...
26
+
27
+ .PHONY : install-lll
28
+ install-lll :
29
+ go install github.com/walle/lll/...@latest
47
30
48
31
.PHONY : check-fmt
49
- check-fmt :
32
+ check-fmt : install-lll
50
33
etc/check_fmt.sh
51
34
52
35
# check-modules runs "go mod tidy" then "go mod vendor" and exits with a non-zero exit code if there
71
54
fmt :
72
55
go fmt ./...
73
56
57
+ .PHONY : install-golangci-lint
58
+ install-golangci-lint :
59
+ go install github.com/golangci/golangci-lint/cmd/
[email protected]
60
+
61
+ # Lint with various GOOS and GOARCH targets to catch static analysis failures that may only affect
62
+ # specific operating systems or architectures. For example, staticcheck will only check for 64-bit
63
+ # alignment of atomically accessed variables on 32-bit architectures (see
64
+ # https://staticcheck.io/docs/checks#SA1027)
74
65
.PHONY : lint
75
- lint :
76
- for dist in $( GODISTS) ; do \
77
- goos=$$(echo $$dist | cut -d/ -f 1 ) ; \
78
- goarch=$$(echo $$dist | cut -d/ -f 2 ) ; \
79
- command=" GOOS=$$ goos GOARCH=$$ goarch golangci-lint run --config .golangci.yml ./..." ; \
80
- echo $$ command ; \
81
- eval $$ command ; \
82
- done
66
+ lint : install-golangci-lint
67
+ GOOS=linux GOARCH=amd64 golangci-lint run --config .golangci.yml ./...
68
+ GOOS=linux GOARCH=386 golangci-lint run --config .golangci.yml ./...
69
+ GOOS=linux GOARCH=arm64 golangci-lint run --config .golangci.yml ./...
70
+ GOOS=linux GOARCH=arm golangci-lint run --config .golangci.yml ./...
71
+ GOOS=linux GOARCH=s390x golangci-lint run --config .golangci.yml ./...
83
72
84
73
.PHONY : update-notices
85
74
update-notices :
@@ -88,25 +77,19 @@ update-notices:
88
77
# ## Local testing targets. ###
89
78
.PHONY : test
90
79
test :
91
- for TEST in $( TEST_PKGS) ; do \
92
- go test $(BUILD_TAGS ) -timeout $(TEST_TIMEOUT ) s $$ TEST ; \
93
- done
80
+ go test $(BUILD_TAGS ) -timeout $(TEST_TIMEOUT ) s -p 1 ./...
94
81
95
82
.PHONY : test-cover
96
83
test-cover :
97
- for TEST in $( TEST_PKGS) ; do \
98
- go test $(BUILD_TAGS ) -timeout $(TEST_TIMEOUT ) s -cover $(COVER_ARGS ) $$ TEST ; \
99
- done
84
+ go test $(BUILD_TAGS ) -timeout $(TEST_TIMEOUT ) s -cover $(COVER_ARGS ) -p 1 ./...
100
85
101
86
.PHONY : test-race
102
87
test-race :
103
- for TEST in $( TEST_PKGS) ; do \
104
- go test $(BUILD_TAGS ) -timeout $(TEST_TIMEOUT ) s -race $$ TEST ; \
105
- done
88
+ go test $(BUILD_TAGS ) -timeout $(TEST_TIMEOUT ) s -race -p 1 ./...
106
89
107
90
.PHONY : test-short
108
91
test-short :
109
- go test $(BUILD_TAGS ) -timeout 60s -short $( TEST_PKGS )
92
+ go test $(BUILD_TAGS ) -timeout 60s -short ./...
110
93
111
94
# ## Evergreen specific targets. ###
112
95
.PHONY : build-aws-ecs-test
@@ -115,9 +98,7 @@ build-aws-ecs-test:
115
98
116
99
.PHONY : evg-test
117
100
evg-test :
118
- for TEST in $( TEST_PKGS) ; do \
119
- go test -exec " env PKG_CONFIG_PATH=$( PKG_CONFIG_PATH) LD_LIBRARY_PATH=$( LD_LIBRARY_PATH) " $(BUILD_TAGS ) -v -timeout $(TEST_TIMEOUT ) s $$ TEST >> test.suite ; \
120
- done
101
+ go test -exec " env PKG_CONFIG_PATH=$( PKG_CONFIG_PATH) LD_LIBRARY_PATH=$( LD_LIBRARY_PATH) " $(BUILD_TAGS ) -v -timeout $(TEST_TIMEOUT ) s -p 1 ./... >> test.suite
121
102
122
103
.PHONY : evg-test-atlas
123
104
evg-test-atlas :
@@ -186,9 +167,9 @@ evg-test-serverless:
186
167
.PHONY : evg-test-versioned-api
187
168
evg-test-versioned-api :
188
169
# Versioned API related tests are in the mongo, integration and unified packages.
189
- for TEST_PKG in ./mongo ./mongo/integration ./mongo/integration/unified ; do \
190
- go test -exec " env PKG_CONFIG_PATH=$( PKG_CONFIG_PATH) LD_LIBRARY_PATH=$( LD_LIBRARY_PATH) " $(BUILD_TAGS ) -v -timeout $(TEST_TIMEOUT ) s $$ TEST_PKG >> test.suite ; \
191
- done
170
+ go test -exec " env PKG_CONFIG_PATH= $( PKG_CONFIG_PATH ) LD_LIBRARY_PATH= $( LD_LIBRARY_PATH ) " $( BUILD_TAGS ) -v -timeout $( TEST_TIMEOUT ) s ./mongo >> test.suite
171
+ go test -exec " env PKG_CONFIG_PATH=$( PKG_CONFIG_PATH) LD_LIBRARY_PATH=$( LD_LIBRARY_PATH) " $(BUILD_TAGS ) -v -timeout $(TEST_TIMEOUT ) s ./mongo/integration >> test.suite
172
+ go test -exec " env PKG_CONFIG_PATH= $( PKG_CONFIG_PATH ) LD_LIBRARY_PATH= $( LD_LIBRARY_PATH ) " $( BUILD_TAGS ) -v -timeout $( TEST_TIMEOUT ) s ./mongo/integration/unified >> test.suite
192
173
193
174
.PHONY : build-gcpkms-test
194
175
build-gcpkms-test :
0 commit comments