mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
internal/lsp: fix patch tests on builders
Fixes golang/go#34620 Change-Id: Id8e2310c27d5697a8988b9e8dc85be979f9b8d40 Reviewed-on: https://go-review.googlesource.com/c/tools/+/199737 Run-TryBot: Ian Cottrell <iancottrell@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
parent
8abd424004
commit
7822de7a2d
@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/tools/internal/lsp/cmd"
|
"golang.org/x/tools/internal/lsp/cmd"
|
||||||
"golang.org/x/tools/internal/span"
|
"golang.org/x/tools/internal/span"
|
||||||
|
"golang.org/x/tools/internal/testenv"
|
||||||
"golang.org/x/tools/internal/tool"
|
"golang.org/x/tools/internal/tool"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,9 +59,7 @@ func fixFileHeader(s string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkUnified(t *testing.T, filename string, expect string, patch string) {
|
func checkUnified(t *testing.T, filename string, expect string, patch string) {
|
||||||
if testing.Short() {
|
testenv.NeedsTool(t, "patch")
|
||||||
t.Skip("running patch is expensive")
|
|
||||||
}
|
|
||||||
if strings.Count(patch, "\n+++ ") > 1 {
|
if strings.Count(patch, "\n+++ ") > 1 {
|
||||||
// TODO(golang/go/#34580)
|
// TODO(golang/go/#34580)
|
||||||
t.Skip("multi-file patch tests not supported yet")
|
t.Skip("multi-file patch tests not supported yet")
|
||||||
|
@ -8,6 +8,7 @@ package testenv
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -31,6 +32,28 @@ type helperer interface {
|
|||||||
// be development versions.
|
// be development versions.
|
||||||
var packageMainIsDevel = func() bool { return true }
|
var packageMainIsDevel = func() bool { return true }
|
||||||
|
|
||||||
|
func hasTool(tool string) error {
|
||||||
|
_, err := exec.LookPath(tool)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch tool {
|
||||||
|
case "patch":
|
||||||
|
// check that the patch tools supports the -o argument
|
||||||
|
temp, err := ioutil.TempFile("", "patch-test")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
temp.Close()
|
||||||
|
defer os.Remove(temp.Name())
|
||||||
|
cmd := exec.Command(tool, "-o", temp.Name())
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func allowMissingTool(tool string) bool {
|
func allowMissingTool(tool string) bool {
|
||||||
if runtime.GOOS == "android" {
|
if runtime.GOOS == "android" {
|
||||||
// Android builds generally run tests on a separate machine from the build,
|
// Android builds generally run tests on a separate machine from the build,
|
||||||
@ -38,10 +61,21 @@ func allowMissingTool(tool string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if tool == "go" && os.Getenv("GO_BUILDER_NAME") == "illumos-amd64-joyent" {
|
switch tool {
|
||||||
|
case "go":
|
||||||
|
if os.Getenv("GO_BUILDER_NAME") == "illumos-amd64-joyent" {
|
||||||
// Work around a misconfigured builder (see https://golang.org/issue/33950).
|
// Work around a misconfigured builder (see https://golang.org/issue/33950).
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
case "diff":
|
||||||
|
if os.Getenv("GO_BUILDER_NAME") != "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
case "patch":
|
||||||
|
if os.Getenv("GO_BUILDER_NAME") != "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If a developer is actively working on this test, we expect them to have all
|
// If a developer is actively working on this test, we expect them to have all
|
||||||
// of its dependencies installed. However, if it's just a dependency of some
|
// of its dependencies installed. However, if it's just a dependency of some
|
||||||
@ -52,14 +86,13 @@ func allowMissingTool(tool string) bool {
|
|||||||
|
|
||||||
// NeedsTool skips t if the named tool is not present in the path.
|
// NeedsTool skips t if the named tool is not present in the path.
|
||||||
func NeedsTool(t Testing, tool string) {
|
func NeedsTool(t Testing, tool string) {
|
||||||
_, err := exec.LookPath(tool)
|
|
||||||
if err == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if t, ok := t.(helperer); ok {
|
if t, ok := t.(helperer); ok {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
}
|
}
|
||||||
|
err := hasTool(tool)
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
if allowMissingTool(tool) {
|
if allowMissingTool(tool) {
|
||||||
t.Skipf("skipping because %s tool not available: %v", tool, err)
|
t.Skipf("skipping because %s tool not available: %v", tool, err)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user