cmd/age: fix testscript setup races

This commit is contained in:
Filippo Valsorda
2025-12-07 21:58:13 +01:00
committed by Filippo Valsorda
parent ed44098807
commit ad7bb569eb

View File

@@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"sync"
"testing"
"filippo.io/age"
@@ -50,12 +51,9 @@ func (testPlugin) Unwrap(ss []*age.Stanza) ([]byte, error) {
return nil, age.ErrIncorrectIdentity
}
func TestScript(t *testing.T) {
testscript.Run(t, testscript.Params{
Dir: "testdata",
Setup: func(e *testscript.Env) error {
var buildExtraCommands = sync.OnceValue(func() error {
bindir := filepath.SplitList(os.Getenv("PATH"))[0]
// Build age-keygen and age-plugin-pq into the test binary directory
// Build age-keygen and age-plugin-pq into the test binary directory.
cmd := exec.Command("go", "build", "-o", bindir)
if testing.CoverMode() != "" {
cmd.Args = append(cmd.Args, "-cover")
@@ -65,6 +63,13 @@ func TestScript(t *testing.T) {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
})
func TestScript(t *testing.T) {
testscript.Run(t, testscript.Params{
Dir: "testdata",
Setup: func(e *testscript.Env) error {
return buildExtraCommands()
},
// TODO: enable AGEDEBUG=plugin without breaking stderr checks.
})