Skip to content

Commit 813a903

Browse files
olavmrkjohnweldon
authored andcommitted
Fix tests on Go 1.12 (#207)
* Fix format error in tests When running the tests on Go 1.12, we get the following error: > ./search_test.go:27:4: Fatalf format %s has arg executedEntry of wrong type *github.com/go-ldap/ldap.Entry This patch fixes this by using the correct format verb. * Makefile: Clarify which Go version support the `-race` flag This patch updates the comment for the `RACE_FLAG` variable, to indicate which Go version it is supported on. * Makefile: Test for Go versions using release tags Go doesn't really provide a stable interface to get its version. `go version` fails when using `tip`. This patch adds version detection using the release tags list. This list is populated with a tag for each release of Go. See: https://github.com/golang/go/blob/go1.12/src/go/build/build.go#L295-L305 * Makefile: Use Go version to check for `go tool vet` Instead of checking for `go tool vet` using `go tool -n vet`, use a version test. This makes the Makefile more readable, and will also make it easier to change the behavior for newer versions of Go. * Makefile: Fix `go vet` on Go version 1.12 Go version 1.12 does not allow `go vet` to be run through `go tool vet`. Instead we must run `go vet`. In addition the experimental `-shadow` option has been removed, so that check is not executed when running `go vet`. See: https://golang.org/doc/go1.12#vet * Travis CI: Run tests on Go 1.12 This patch adds Go 1.12 to the test matrix.
1 parent 214f299 commit 813a903

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ go:
99
- "1.9.x"
1010
- "1.10.x"
1111
- "1.11.x"
12+
- "1.12.x"
1213
- tip
1314

1415
git:

Makefile

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
11
.PHONY: default install build test quicktest fmt vet lint
22

3-
GO_VERSION := $(shell go version | cut -d' ' -f3 | cut -d. -f2)
3+
# List of all release tags "supported" by our current Go version
4+
# E.g. ":go1.1:go1.2:go1.3:go1.4:go1.5:go1.6:go1.7:go1.8:go1.9:go1.10:go1.11:go1.12:"
5+
GO_RELEASE_TAGS := $(shell go list -f ':{{join (context.ReleaseTags) ":"}}:' runtime)
46

5-
# Only use the `-race` flag on newer versions of Go
6-
IS_OLD_GO := $(shell test $(GO_VERSION) -le 2 && echo true)
7-
ifeq ($(IS_OLD_GO),true)
7+
# Only use the `-race` flag on newer versions of Go (version 1.3 and newer)
8+
ifeq (,$(findstring :go1.3:,$(GO_RELEASE_TAGS)))
89
RACE_FLAG :=
910
else
1011
RACE_FLAG := -race -cpu 1,2,4
1112
endif
1213

14+
# Run `go vet` on Go 1.12 and newer. For Go 1.5-1.11, use `go tool vet`
15+
ifneq (,$(findstring :go1.12:,$(GO_RELEASE_TAGS)))
16+
GO_VET := go vet \
17+
-atomic \
18+
-bool \
19+
-copylocks \
20+
-nilfunc \
21+
-printf \
22+
-rangeloops \
23+
-unreachable \
24+
-unsafeptr \
25+
-unusedresult \
26+
.
27+
else ifneq (,$(findstring :go1.5:,$(GO_RELEASE_TAGS)))
28+
GO_VET := go tool vet \
29+
-atomic \
30+
-bool \
31+
-copylocks \
32+
-nilfunc \
33+
-printf \
34+
-shadow \
35+
-rangeloops \
36+
-unreachable \
37+
-unsafeptr \
38+
-unusedresult \
39+
.
40+
else
41+
GO_VET := @echo "go vet skipped -- not supported on this version of Go"
42+
endif
43+
1344
default: fmt vet lint build quicktest
1445

1546
install:
@@ -34,25 +65,8 @@ fmt:
3465
exit 1; \
3566
fi
3667

37-
# Only run on go1.5+
3868
vet:
39-
@go tool -n vet >/dev/null 2>&1; \
40-
if [ $$? -eq 0 ]; then \
41-
echo "go vet" ; \
42-
go tool vet \
43-
-atomic \
44-
-bool \
45-
-copylocks \
46-
-nilfunc \
47-
-printf \
48-
-shadow \
49-
-rangeloops \
50-
-unreachable \
51-
-unsafeptr \
52-
-unusedresult \
53-
. ; \
54-
fi ;
55-
69+
$(GO_VET)
5670

5771
# https://github.com/golang/lint
5872
# go get github.com/golang/lint/golint

search_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestNewEntry(t *testing.T) {
2424
}
2525
testEntry := NewEntry(dn, attributes)
2626
if !reflect.DeepEqual(executedEntry, testEntry) {
27-
t.Fatalf("subsequent calls to NewEntry did not yield the same result:\n\texpected:\n\t%s\n\tgot:\n\t%s\n", executedEntry, testEntry)
27+
t.Fatalf("subsequent calls to NewEntry did not yield the same result:\n\texpected:\n\t%v\n\tgot:\n\t%v\n", executedEntry, testEntry)
2828
}
2929
iteration = iteration + 1
3030
}

0 commit comments

Comments
 (0)