func newScriptEngine() *script.Engine {
conds := script.DefaultConds()
+ add := func(name string, cond script.Cond) {
+ if _, ok := conds[name]; ok {
+ panic(fmt.Sprintf("condition %q is already registered", name))
+ }
+ conds[name] = cond
+ }
+ lazyBool := func(summary string, f func() bool) script.Cond {
+ return script.OnceCondition(summary, func() (bool, error) { return f(), nil })
+ }
+ add("bzr", lazyBool("the 'bzr' executable exists and provides the standard CLI", hasWorkingBzr))
+
interrupt := func(cmd *exec.Cmd) error { return cmd.Process.Signal(os.Interrupt) }
gracePeriod := 30 * time.Second // arbitrary
cmds["hg"] = script.Program("hg", interrupt, gracePeriod)
cmds["handle"] = scriptHandle()
cmds["modzip"] = scriptModzip()
+ cmds["skip"] = scriptSkip()
cmds["svnadmin"] = script.Program("svnadmin", interrupt, gracePeriod)
cmds["svn"] = script.Program("svn", interrupt, gracePeriod)
cmds["unquote"] = scriptUnquote()
})
}
+func scriptSkip() script.Cmd {
+ return script.Command(
+ script.CmdUsage{
+ Summary: "skip the current test",
+ Args: "[msg]",
+ },
+ func(_ *script.State, args ...string) (script.WaitFunc, error) {
+ if len(args) > 1 {
+ return nil, script.ErrUsage
+ }
+ if len(args) == 0 {
+ return nil, SkipError{""}
+ }
+ return nil, SkipError{args[0]}
+ })
+}
+
+type SkipError struct {
+ Msg string
+}
+
+func (s SkipError) Error() string {
+ if s.Msg == "" {
+ return "skip"
+ }
+ return s.Msg
+}
+
func scriptUnquote() script.Cmd {
return script.Command(
script.CmdUsage{
return wait, nil
})
}
+
+func hasWorkingBzr() bool {
+ bzr, err := exec.LookPath("bzr")
+ if err != nil {
+ return false
+ }
+ // Check that 'bzr help' exits with code 0.
+ // See go.dev/issue/71504 for an example where 'bzr' exists in PATH but doesn't work.
+ err = exec.Command(bzr, "help").Run()
+ return err == nil
+}
if notInstalled := (vcweb.ServerNotInstalledError{}); errors.As(err, ¬Installed) || errors.Is(err, exec.ErrNotFound) {
t.Skip(err)
}
-
- // For issue #71504 ignore an error about
- // bzr not being able to find dependencies.
- if strings.Contains(buf.String(), "brz: ERROR: Couldn't import breezy and dependencies.") {
- t.Skip("skipping test due to bzr installation problem")
+ if skip := (vcweb.SkipError{}); errors.As(err, &skip) {
+ if skip.Msg == "" {
+ t.Skip("SKIP")
+ } else {
+ t.Skipf("SKIP: %v", skip.Msg)
+ }
}
-
t.Error(err)
}
})
}
add("abscc", script.Condition("default $CC path is absolute and exists", defaultCCIsAbsolute))
+ add("bzr", lazyBool("the 'bzr' executable exists and provides the standard CLI", hasWorkingBzr))
add("case-sensitive", script.OnceCondition("$WORK filesystem is case-sensitive", isCaseSensitive))
add("cc", script.PrefixCondition("go env CC = <suffix> (ignoring the go/env file)", ccIs))
add("git", lazyBool("the 'git' executable exists and provides the standard CLI", hasWorkingGit))
_, err := exec.LookPath("git")
return err == nil
}
+
+func hasWorkingBzr() bool {
+ bzr, err := exec.LookPath("bzr")
+ if err != nil {
+ return false
+ }
+ // Check that 'bzr help' exits with code 0.
+ // See go.dev/issue/71504 for an example where 'bzr' exists in PATH but doesn't work.
+ err = exec.Command(bzr, "help").Run()
+ return err == nil
+}