Skip to content

Commit a7cbea8

Browse files
dmitshurgopherbot
authored andcommitted
cmd/go: skip bzr tests if 'bzr help' has non-zero exit code
It appears to be quite easy to end up with a broken 'bzr' installation. For example, if bzr was installed via a system-wide package manager and intends to work with a system-wide Python installation, it may break if another 'python3' binary is added to PATH. If something as simple as 'bzr help' fails to exit with zero code, consider it broken and skip tests that require a working bzr binary just like if the 'bzr' binary isn't present in PATH at all. This makes these tests more robust and capable of producing useful signal in more environments. Separately from this, we'll want to restore a working bzr installation on the linux-arm64 builders, but at least there's still one on linux-amd64 builders. For #71563. Fixes #71504. Change-Id: Ia147196f12b90a0731ebbfab63b5de308212ed65 Cq-Include-Trybots: luci.golang.try:gotip-linux-arm64-longtest,gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/646715 Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent f6ea062 commit a7cbea8

File tree

6 files changed

+73
-7
lines changed

6 files changed

+73
-7
lines changed

src/cmd/go/internal/vcweb/script.go

+51
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ import (
3232
func newScriptEngine() *script.Engine {
3333
conds := script.DefaultConds()
3434

35+
add := func(name string, cond script.Cond) {
36+
if _, ok := conds[name]; ok {
37+
panic(fmt.Sprintf("condition %q is already registered", name))
38+
}
39+
conds[name] = cond
40+
}
41+
lazyBool := func(summary string, f func() bool) script.Cond {
42+
return script.OnceCondition(summary, func() (bool, error) { return f(), nil })
43+
}
44+
add("bzr", lazyBool("the 'bzr' executable exists and provides the standard CLI", hasWorkingBzr))
45+
3546
interrupt := func(cmd *exec.Cmd) error { return cmd.Process.Signal(os.Interrupt) }
3647
gracePeriod := 30 * time.Second // arbitrary
3748

@@ -43,6 +54,7 @@ func newScriptEngine() *script.Engine {
4354
cmds["hg"] = script.Program("hg", interrupt, gracePeriod)
4455
cmds["handle"] = scriptHandle()
4556
cmds["modzip"] = scriptModzip()
57+
cmds["skip"] = scriptSkip()
4658
cmds["svnadmin"] = script.Program("svnadmin", interrupt, gracePeriod)
4759
cmds["svn"] = script.Program("svn", interrupt, gracePeriod)
4860
cmds["unquote"] = scriptUnquote()
@@ -321,6 +333,34 @@ func scriptModzip() script.Cmd {
321333
})
322334
}
323335

336+
func scriptSkip() script.Cmd {
337+
return script.Command(
338+
script.CmdUsage{
339+
Summary: "skip the current test",
340+
Args: "[msg]",
341+
},
342+
func(_ *script.State, args ...string) (script.WaitFunc, error) {
343+
if len(args) > 1 {
344+
return nil, script.ErrUsage
345+
}
346+
if len(args) == 0 {
347+
return nil, SkipError{""}
348+
}
349+
return nil, SkipError{args[0]}
350+
})
351+
}
352+
353+
type SkipError struct {
354+
Msg string
355+
}
356+
357+
func (s SkipError) Error() string {
358+
if s.Msg == "" {
359+
return "skip"
360+
}
361+
return s.Msg
362+
}
363+
324364
func scriptUnquote() script.Cmd {
325365
return script.Command(
326366
script.CmdUsage{
@@ -343,3 +383,14 @@ func scriptUnquote() script.Cmd {
343383
return wait, nil
344384
})
345385
}
386+
387+
func hasWorkingBzr() bool {
388+
bzr, err := exec.LookPath("bzr")
389+
if err != nil {
390+
return false
391+
}
392+
// Check that 'bzr help' exits with code 0.
393+
// See go.dev/issue/71504 for an example where 'bzr' exists in PATH but doesn't work.
394+
err = exec.Command(bzr, "help").Run()
395+
return err == nil
396+
}

src/cmd/go/internal/vcweb/vcstest/vcstest_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ func TestScripts(t *testing.T) {
158158
if notInstalled := (vcweb.ServerNotInstalledError{}); errors.As(err, &notInstalled) || errors.Is(err, exec.ErrNotFound) {
159159
t.Skip(err)
160160
}
161-
162-
// For issue #71504 ignore an error about
163-
// bzr not being able to find dependencies.
164-
if strings.Contains(buf.String(), "brz: ERROR: Couldn't import breezy and dependencies.") {
165-
t.Skip("skipping test due to bzr installation problem")
161+
if skip := (vcweb.SkipError{}); errors.As(err, &skip) {
162+
if skip.Msg == "" {
163+
t.Skip("SKIP")
164+
} else {
165+
t.Skipf("SKIP: %v", skip.Msg)
166+
}
166167
}
167-
168168
t.Error(err)
169169
}
170170
})

src/cmd/go/scriptconds_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func scriptConditions(t *testing.T) map[string]script.Cond {
3737
}
3838

3939
add("abscc", script.Condition("default $CC path is absolute and exists", defaultCCIsAbsolute))
40+
add("bzr", lazyBool("the 'bzr' executable exists and provides the standard CLI", hasWorkingBzr))
4041
add("case-sensitive", script.OnceCondition("$WORK filesystem is case-sensitive", isCaseSensitive))
4142
add("cc", script.PrefixCondition("go env CC = <suffix> (ignoring the go/env file)", ccIs))
4243
add("git", lazyBool("the 'git' executable exists and provides the standard CLI", hasWorkingGit))
@@ -151,3 +152,14 @@ func hasWorkingGit() bool {
151152
_, err := exec.LookPath("git")
152153
return err == nil
153154
}
155+
156+
func hasWorkingBzr() bool {
157+
bzr, err := exec.LookPath("bzr")
158+
if err != nil {
159+
return false
160+
}
161+
// Check that 'bzr help' exits with code 0.
162+
// See go.dev/issue/71504 for an example where 'bzr' exists in PATH but doesn't work.
163+
err = exec.Command(bzr, "help").Run()
164+
return err == nil
165+
}

src/cmd/go/testdata/script/README

+2
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ The available conditions are:
377377
GOOS/GOARCH supports -asan
378378
[buildmode:*]
379379
go supports -buildmode=<suffix>
380+
[bzr]
381+
the 'bzr' executable exists and provides the standard CLI
380382
[case-sensitive]
381383
$WORK filesystem is case-sensitive
382384
[cc:*]

src/cmd/go/testdata/script/version_buildvcs_bzr.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# controlled with -buildvcs. This test focuses on Bazaar specifics.
33
# The Git test covers common functionality.
44

5-
[!exec:bzr] skip
65
[short] skip
6+
[!bzr] skip 'requires a working bzr client'
77
env GOBIN=$WORK/gopath/bin
88
env oldpath=$PATH
99
env HOME=$WORK

src/cmd/go/testdata/vcstest/bzr/hello.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[!bzr] skip 'requires a working bzr client'
12
handle bzr
23

34
env BZR_EMAIL='Russ Cox <[email protected]>'

0 commit comments

Comments
 (0)