Files
w3cjandClaude Opus 5.5 2545de19f3 test(e2e): the Go runner is the entry point, mise run e2e -- FLAGS, and tests/e2e.sh goes
TestE2E already set up the sandbox, slots, locks and flags itself, so the
898-line script only handed over. The run is now `mise run e2e -- FLAGS`
(go test -tags e2e from tests/e2e, CGO_ENABLED=0) with the same flags:
--only, --from, --clean, --every-feature, --slots, --slot, --newest-base,
--golden, plus --reuse.

- options: the flags named as the script's options; the hand-over flags
  (lock-holder, count, total, started, summary) and the ported/unported
  split are gone.
- e2eUbuntuRelease, a const in sandbox_test.go, holds the Ubuntu pin;
  scripts/bump.sh e2e-ubuntu moves it (get_const), and TestE2EUbuntuPins,
  bump.txtar and the E2E workflow read it there.
- From the script into Go: the OpenSSL-not-LibreSSL host check, and
  --newest-base's start line and its UPSTREAM DRIFT summary.
- The script's leftover bash helpers (perl vm_state, no_leak, ca_*,
  lima_listens, the retry list, its heartbeat) are gone with it.
- mise's e2e:go task merges into e2e; TestCommandLines drops its $D rule.
- Docs (contributing, testing, maintaining, internals) and AGENTS.md name
  mise run e2e; testing.md's "Porting a section" becomes "Adding a section".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 01:56:50 -07:00

73 lines
2.4 KiB
Go

//go:build e2e
package e2e
import (
"fmt"
"os"
"os/exec"
"os/user"
"path/filepath"
"regexp"
"runtime"
"strings"
)
// Golden captures a golden fixture with --golden: what args printed,
// output and errors, as testdata/golden/<os>/name in the checkout, this
// machine's home, user name, full name and timezone replaced and a VM's
// environment made up. A capture isn't a check, so a run without
// --golden runs as many checks; one that fails
// says so and keeps the fixture it had.
func (s *S) Golden(name string, args ...string) {
if !s.sb.o.golden {
return
}
dir := filepath.Join(s.sb.root, "testdata", "golden", runtime.GOOS)
r, err := s.Run(Cmd{Args: args})
if err == nil {
err = os.MkdirAll(dir, 0o700)
}
if err == nil {
err = os.WriteFile(filepath.Join(dir, name), []byte(anonymous(r.Out, os.Getenv("HOME"))), 0o600)
}
if err != nil {
s.r.out.line("golden: capturing %s failed", name)
return
}
s.r.out.line("golden: %s", name)
}
// anonymous is out with home as /home/me, this user's name as me, and
// Lima's comment, timezone and a VM's environment made up.
func anonymous(out, home string) string {
if home != "" {
out = strings.ReplaceAll(out, home, "/home/me")
}
if u, err := user.Current(); err == nil && u.Username != "" {
out = regexp.MustCompile(`\b`+regexp.QuoteMeta(u.Username)+`\b`).ReplaceAllString(out, "me")
}
out = regexp.MustCompile(`"comment":"[^"]*"`).ReplaceAllString(out, `"comment":"me"`)
out = regexp.MustCompile(`"timezone":"[^"]*"`).ReplaceAllString(out, `"timezone":"UTC"`)
return regexp.MustCompile(`"env":\{[^{}]*\}`).ReplaceAllString(out, `"env":{"NAME":"value"}`)
}
// GoE2E runs the Go test test in internal/pkg from the checkout, with
// vars (VAR=VALUE) in its environment, so no value is in a process's
// arguments: the tests that need a real VM or desktop, which skip unless
// their DEVVM_E2E_* variables are set. It fails unless test passed.
func (s *S) GoE2E(test, pkg string, vars ...string) error {
args := []string{"go", "test", "-count=1", "-v", "-run", "^" + test + "$", "./internal/" + pkg}
if _, err := exec.LookPath("go"); err != nil {
args = append([]string{"mise", "exec", "--"}, args...)
}
r, err := s.Run(Cmd{Args: args, Dir: s.sb.root, Env: append([]string{"CGO_ENABLED=0"}, vars...)})
switch {
case err != nil:
return err
case !strings.Contains(r.Out, "--- PASS: "+test+" ("):
return fmt.Errorf("go test %s didn't pass (did it skip?)", test)
}
return nil
}