From 9494223413648d2b96c331c8a98e2a4615b6f8d4 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 25 Jul 2018 16:43:58 +0000 Subject: [PATCH] godoc: fix tests on Go 1.9 Updates golang/go#11811 Updates golang/go#26531 Change-Id: I9cc7daf551b76c3f06b9dd827c5733513c06895e Reviewed-on: https://go-review.googlesource.com/125816 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Agniva De Sarker Reviewed-by: Brad Fitzpatrick --- versions_test.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/versions_test.go b/versions_test.go index 81dc3e5..ad2d5e4 100644 --- a/versions_test.go +++ b/versions_test.go @@ -4,7 +4,10 @@ package godoc -import "testing" +import ( + "go/build" + "testing" +) func TestParseVersionRow(t *testing.T) { tests := []struct { @@ -73,6 +76,17 @@ func TestParseVersionRow(t *testing.T) { } } +// hasTag checks whether a given release tag is contained in the current version +// of the go binary. +func hasTag(t string) bool { + for _, v := range build.Default.ReleaseTags { + if t == v { + return true + } + } + return false +} + func TestAPIVersion(t *testing.T) { av, err := parsePackageAPIInfo() if err != nil { @@ -108,6 +122,9 @@ func TestAPIVersion(t *testing.T) { {"type", "archive/tar", "Header", "", ""}, {"method", "archive/tar", "Next", "*Reader", ""}, } { + if tc.want != "" && !hasTag("go"+tc.want) { + continue + } if got := av.sinceVersionFunc(tc.kind, tc.receiver, tc.name, tc.pkg); got != tc.want { t.Errorf(`sinceFunc("%s", "%s", "%s", "%s") = "%s"; want "%s"`, tc.kind, tc.receiver, tc.name, tc.pkg, got, tc.want) }