Improve LookPath

This commit is contained in:
Bjørn Erik Pedersen
2020-12-18 18:20:12 +01:00
parent ae2d1bd52d
commit 10ae7c3210
18 changed files with 129 additions and 42 deletions

View File

@@ -13,7 +13,6 @@ package testenv
import (
"errors"
"flag"
"github.com/gohugoio/hugo/tpl/internal/go_templates/cfg"
"os"
"os/exec"
"path/filepath"
@@ -22,6 +21,9 @@ import (
"strings"
"sync"
"testing"
"github.com/cli/safeexec"
"github.com/gohugoio/hugo/tpl/internal/go_templates/cfg"
)
// Builder reports the name of the builder running this test
@@ -111,7 +113,7 @@ func GoTool() (string, error) {
if _, err := os.Stat(path); err == nil {
return path, nil
}
goBin, err := exec.LookPath("go" + exeSuffix)
goBin, err := safeexec.LookPath("go" + exeSuffix)
if err != nil {
return "", errors.New("cannot find go tool: " + err.Error())
}
@@ -162,7 +164,7 @@ func MustHaveExecPath(t testing.TB, path string) {
err, found := execPaths.Load(path)
if !found {
_, err = exec.LookPath(path)
_, err = safeexec.LookPath(path)
err, _ = execPaths.LoadOrStore(path, err)
}
if err != nil {