move garble binary setup with $PATH to Setup

This way, it's ready for multiple scripts.
pull/22/head
Daniel Martí 5 years ago
parent 8119fa0e62
commit 63f58242fb

@ -5,6 +5,7 @@ package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"testing"
@ -26,7 +27,15 @@ func TestScripts(t *testing.T) {
testscript.Run(t, testscript.Params{
Dir: filepath.Join("testdata", "scripts"),
Setup: func(env *testscript.Env) error {
env.Vars = append(env.Vars, "TESTBIN="+os.Args[0])
bindir := filepath.Join(env.WorkDir, ".bin")
if err := os.Mkdir(bindir, 0777); err != nil {
return err
}
if err := os.Symlink(os.Args[0], filepath.Join(bindir, "garble")); err != nil {
return err
}
env.Vars = append(env.Vars, fmt.Sprintf("PATH=%s%c%s", bindir, filepath.ListSeparator, os.Getenv("PATH")))
env.Vars = append(env.Vars, "TESTSCRIPT_COMMAND=garble")
for _, name := range [...]string{
"HOME",

@ -1,16 +1,5 @@
# TODO: make this script run on mac and windows
[!exec:go] skip
[!symlink] skip
# We want to use the current garble, not whichever happens to be globally
# installed. Use the test binary with TESTSCRIPT_COMMAND, which we know will
# correctly run garble thanks to go-internal/testscript.
mkdir .bin
symlink .bin/garble$exe -> $TESTBIN
env PATH=$WORK/.bin${:}$PATH
env TESTSCRIPT_COMMAND=garble
# Check that the program works as expected without garble.
exec go build main.go
exec ./main

Loading…
Cancel
Save