"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tpl/internal/go_templates/texttemplate/exec_test.go" between
hugo-0.80.0.tar.gz and hugo-0.81.0.tar.gz

About: Hugo is a static site generator that takes a source directory of Markdown files and templates and uses these as input to create a complete website (written in Go).

exec_test.go  (hugo-0.80.0):exec_test.go  (hugo-0.81.0)
skipping to change at line 14 skipping to change at line 14
// +build go1.13,!windows // +build go1.13,!windows
package template package template
import ( import (
"bytes" "bytes"
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
) )
var debug = flag.Bool("debug", false, "show the errors produced by the tests") var debug = flag.Bool("debug", false, "show the errors produced by the tests")
// T has lots of interesting pieces to use to test execution. // T has lots of interesting pieces to use to test execution.
type T struct { type T struct {
// Basics // Basics
skipping to change at line 1300 skipping to change at line 1300
} }
// Test that the error message for multiline unterminated string // Test that the error message for multiline unterminated string
// refers to the line number of the opening quote. // refers to the line number of the opening quote.
func TestUnterminatedStringError(t *testing.T) { func TestUnterminatedStringError(t *testing.T) {
_, err := New("X").Parse("hello\n\n{{`unterminated\n\n\n\n}}\n some more\ n\n") _, err := New("X").Parse("hello\n\n{{`unterminated\n\n\n\n}}\n some more\ n\n")
if err == nil { if err == nil {
t.Fatal("expected error") t.Fatal("expected error")
} }
str := err.Error() str := err.Error()
if !strings.Contains(str, "X:3: unexpected unterminated raw quoted string ") { if !strings.Contains(str, "X:3: unterminated raw quoted string") {
t.Fatalf("unexpected error: %s", str) t.Fatalf("unexpected error: %s", str)
} }
} }
const alwaysErrorText = "always be failing" const alwaysErrorText = "always be failing"
var alwaysError = errors.New(alwaysErrorText) var alwaysError = errors.New(alwaysErrorText)
type ErrorWriter int type ErrorWriter int
skipping to change at line 1333 skipping to change at line 1333
t.Fatal("expected error; got none") t.Fatal("expected error; got none")
} }
if err.Error() != alwaysErrorText { if err.Error() != alwaysErrorText {
t.Errorf("expected %q error; got %q", alwaysErrorText, err) t.Errorf("expected %q error; got %q", alwaysErrorText, err)
} }
// This one should be an ExecError. // This one should be an ExecError.
tmpl, err = New("X").Parse("hello, {{.X.Y}}") tmpl, err = New("X").Parse("hello, {{.X.Y}}")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = tmpl.Execute(ioutil.Discard, 0) err = tmpl.Execute(io.Discard, 0)
if err == nil { if err == nil {
t.Fatal("expected error; got none") t.Fatal("expected error; got none")
} }
eerr, ok := err.(ExecError) eerr, ok := err.(ExecError)
if !ok { if !ok {
t.Fatalf("did not expect ExecError %s", eerr) t.Fatalf("did not expect ExecError %s", eerr)
} }
expect := "field X in type int" expect := "field X in type int"
if !strings.Contains(err.Error(), expect) { if !strings.Contains(err.Error(), expect) {
t.Errorf("expected %q; got %q", expect, err) t.Errorf("expected %q; got %q", expect, err)
skipping to change at line 1479 skipping to change at line 1479
{ {
"MissingKeyOnMapPtrToNil", "MissingKeyOnMapPtrToNil",
"{{.MissingKey}}", "{{.MissingKey}}",
&map[string]string{}, &map[string]string{},
"<nil>", "<nil>",
}, },
} }
for _, tc := range tests { for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
tmpl := Must(New("tmpl").Parse(tc.src)) tmpl := Must(New("tmpl").Parse(tc.src))
err := tmpl.Execute(ioutil.Discard, tc.value) err := tmpl.Execute(io.Discard, tc.value)
got := "<nil>" got := "<nil>"
if err != nil { if err != nil {
got = err.Error() got = err.Error()
} }
if !strings.HasSuffix(got, tc.want) { if !strings.HasSuffix(got, tc.want) {
t.Fatalf("got error %q, want %q", got, tc.want) t.Fatalf("got error %q, want %q", got, tc.want)
} }
}) })
} }
} }
func TestMaxExecDepth(t *testing.T) { func TestMaxExecDepth(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("skipping in -short mode") t.Skip("skipping in -short mode")
} }
tmpl := Must(New("tmpl").Parse(`{{template "tmpl" .}}`)) tmpl := Must(New("tmpl").Parse(`{{template "tmpl" .}}`))
err := tmpl.Execute(ioutil.Discard, nil) err := tmpl.Execute(io.Discard, nil)
got := "<nil>" got := "<nil>"
if err != nil { if err != nil {
got = err.Error() got = err.Error()
} }
const want = "exceeded maximum template depth" const want = "exceeded maximum template depth"
if !strings.Contains(got, want) { if !strings.Contains(got, want) {
t.Errorf("got error %q; want %q", got, want) t.Errorf("got error %q; want %q", got, want)
} }
} }
skipping to change at line 1702 skipping to change at line 1702
tmpl, err = New("").Parse(textCall) tmpl, err = New("").Parse(textCall)
b.Reset() b.Reset()
err = tmpl.Execute(&b, f) err = tmpl.Execute(&b, f)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if b.String() != "result" { if b.String() != "result" {
t.Errorf("%s got %q, expected %q", textCall, b.String(), "result" ) 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)
}
}
 End of changes. 6 change blocks. 
5 lines changed or deleted 5 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)