зеркало из https://github.com/golang/tools.git
cmd/godoc: fix TestWeb for versions < 1.11
The test was looking for strings found in specific Go versions without checking for the actual Go version running the test. Used ReleaseTags to check whether the current go version should execute a test or not. P.S. The version info is inferred from the binary running the test. But the test builds godoc using the "go" binary in $PATH. In case one is testing different go versions, please ensure to run tests by changing the $PATH variable to point to different go versions, rather than using a custom go binary in a different path. Fixes golang/go#26531 Change-Id: I16dda81518021e865e79c9c29fc2d9e8a83e7057 Reviewed-on: https://go-review.googlesource.com/125755 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Родитель
526516e9c4
Коммит
4d8a0ac9f6
|
@ -8,6 +8,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go/build"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
|
@ -202,6 +203,17 @@ func waitForServer(t *testing.T, url, match string, timeout time.Duration, rever
|
||||||
t.Fatalf("Server failed to respond in %v", timeout)
|
t.Fatalf("Server failed to respond in %v", timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 killAndWait(cmd *exec.Cmd) {
|
func killAndWait(cmd *exec.Cmd) {
|
||||||
cmd.Process.Kill()
|
cmd.Process.Kill()
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
|
@ -260,6 +272,7 @@ func testWeb(t *testing.T, withIndex bool) {
|
||||||
match []string // regexp
|
match []string // regexp
|
||||||
notContains []string
|
notContains []string
|
||||||
needIndex bool
|
needIndex bool
|
||||||
|
releaseTag string // optional release tag that must be in go/build.ReleaseTags
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
|
@ -338,6 +351,7 @@ func testWeb(t *testing.T, withIndex bool) {
|
||||||
match: []string{
|
match: []string{
|
||||||
`Got1xxResponse.*// Go 1\.11`,
|
`Got1xxResponse.*// Go 1\.11`,
|
||||||
},
|
},
|
||||||
|
releaseTag: "go1.11",
|
||||||
},
|
},
|
||||||
// Verify we don't add version info to a struct field added the same time
|
// Verify we don't add version info to a struct field added the same time
|
||||||
// as the struct itself:
|
// as the struct itself:
|
||||||
|
@ -354,6 +368,7 @@ func testWeb(t *testing.T, withIndex bool) {
|
||||||
"The number of connections currently in use; added in Go 1.11",
|
"The number of connections currently in use; added in Go 1.11",
|
||||||
"The number of idle connections; added in Go 1.11",
|
"The number of idle connections; added in Go 1.11",
|
||||||
},
|
},
|
||||||
|
releaseTag: "go1.11",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
@ -374,12 +389,18 @@ func testWeb(t *testing.T, withIndex bool) {
|
||||||
}
|
}
|
||||||
isErr := false
|
isErr := false
|
||||||
for _, substr := range test.contains {
|
for _, substr := range test.contains {
|
||||||
|
if test.releaseTag != "" && !hasTag(test.releaseTag) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if !bytes.Contains(body, []byte(substr)) {
|
if !bytes.Contains(body, []byte(substr)) {
|
||||||
t.Errorf("GET %s: wanted substring %q in body", url, substr)
|
t.Errorf("GET %s: wanted substring %q in body", url, substr)
|
||||||
isErr = true
|
isErr = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, re := range test.match {
|
for _, re := range test.match {
|
||||||
|
if test.releaseTag != "" && !hasTag(test.releaseTag) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if ok, err := regexp.MatchString(re, strBody); !ok || err != nil {
|
if ok, err := regexp.MatchString(re, strBody); !ok || err != nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Bad regexp %q: %v", re, err)
|
t.Fatalf("Bad regexp %q: %v", re, err)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче