mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
Pull in latest Go template source
This commit is contained in:
@@ -8,7 +8,6 @@ package template_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -22,7 +21,7 @@ type templateFile struct {
|
||||
}
|
||||
|
||||
func createTestDir(files []templateFile) string {
|
||||
dir, err := ioutil.TempDir("", "template")
|
||||
dir, err := os.MkdirTemp("", "template")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@@ -373,6 +373,10 @@ func (s *state) walkRange(dot reflect.Value, r *parse.RangeNode) {
|
||||
if val.IsNil() {
|
||||
break
|
||||
}
|
||||
if val.Type().ChanDir() == reflect.SendDir {
|
||||
s.errorf("range over send-only channel %v", val)
|
||||
break
|
||||
}
|
||||
i := 0
|
||||
for ; ; i++ {
|
||||
elem, ok := val.Recv()
|
||||
|
@@ -1699,3 +1699,16 @@ func TestIssue31810(t *testing.T) {
|
||||
t.Errorf("%s got %q, expected %q", textCall, b.String(), "result")
|
||||
}
|
||||
}
|
||||
|
||||
// Issue 43065, range over send only channel
|
||||
func TestIssue43065(t *testing.T) {
|
||||
var b bytes.Buffer
|
||||
tmp := Must(New("").Parse(`{{range .}}{{end}}`))
|
||||
ch := make(chan<- int)
|
||||
err := tmp.Execute(&b, ch)
|
||||
if err == nil {
|
||||
t.Error("expected err got nil")
|
||||
} else if !strings.Contains(err.Error(), "range over send-only channel") {
|
||||
t.Errorf("%s", err)
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ package template
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
@@ -164,7 +164,7 @@ func parseFS(t *Template, fsys fs.FS, patterns []string) (*Template, error) {
|
||||
|
||||
func readFileOS(file string) (name string, b []byte, err error) {
|
||||
name = filepath.Base(file)
|
||||
b, err = ioutil.ReadFile(file)
|
||||
b, err = os.ReadFile(file)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,6 @@ package template_test
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/gohugoio/hugo/tpl/internal/go_templates/testenv"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -42,13 +41,13 @@ func main() {
|
||||
t.Used()
|
||||
}
|
||||
`
|
||||
td, err := ioutil.TempDir("", "text_template_TestDeadCodeElimination")
|
||||
td, err := os.MkdirTemp("", "text_template_TestDeadCodeElimination")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(td)
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(td, "x.go"), []byte(prog), 0644); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(td, "x.go"), []byte(prog), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "x.exe", "x.go")
|
||||
@@ -56,7 +55,7 @@ func main() {
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("go build: %v, %s", err, out)
|
||||
}
|
||||
slurp, err := ioutil.ReadFile(filepath.Join(td, "x.exe"))
|
||||
slurp, err := os.ReadFile(filepath.Join(td, "x.exe"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user