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 <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Brad Fitzpatrick 2018-07-25 16:43:58 +00:00
parent 14e571052b
commit 65cc56d756

View File

@ -4,7 +4,10 @@
package godoc package godoc
import "testing" import (
"go/build"
"testing"
)
func TestParseVersionRow(t *testing.T) { func TestParseVersionRow(t *testing.T) {
tests := []struct { 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) { func TestAPIVersion(t *testing.T) {
av, err := parsePackageAPIInfo() av, err := parsePackageAPIInfo()
if err != nil { if err != nil {
@ -108,6 +122,9 @@ func TestAPIVersion(t *testing.T) {
{"type", "archive/tar", "Header", "", ""}, {"type", "archive/tar", "Header", "", ""},
{"method", "archive/tar", "Next", "*Reader", ""}, {"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 { 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) t.Errorf(`sinceFunc("%s", "%s", "%s", "%s") = "%s"; want "%s"`, tc.kind, tc.receiver, tc.name, tc.pkg, got, tc.want)
} }