Pull in the latest code from Go's template packages (#11771)

Fixes #10707
Fixes #11507
This commit is contained in:
Bjørn Erik Pedersen
2023-12-04 12:07:54 +01:00
committed by GitHub
parent 14d85ec136
commit 9f978d387f
25 changed files with 417 additions and 190 deletions

View File

@@ -5,13 +5,13 @@
package testenv_test
import (
"github.com/gohugoio/hugo/tpl/internal/go_templates/testenv"
//"internal/platform"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/gohugoio/hugo/tpl/internal/go_templates/testenv"
)
func TestGoToolLocation(t *testing.T) {
@@ -83,3 +83,26 @@ func TestMustHaveExec(t *testing.T) {
}
}
}
func TestCleanCmdEnvPWD(t *testing.T) {
// Test that CleanCmdEnv sets PWD if cmd.Dir is set.
switch runtime.GOOS {
case "plan9", "windows":
t.Skipf("PWD is not used on %s", runtime.GOOS)
}
dir := t.TempDir()
cmd := testenv.Command(t, testenv.GoToolPath(t), "help")
cmd.Dir = dir
cmd = testenv.CleanCmdEnv(cmd)
for _, env := range cmd.Env {
if strings.HasPrefix(env, "PWD=") {
pwd := strings.TrimPrefix(env, "PWD=")
if pwd != dir {
t.Errorf("unexpected PWD: want %s, got %s", dir, pwd)
}
return
}
}
t.Error("PWD not set in cmd.Env")
}