diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-01-10 01:36:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-10 01:36:59 +0100 |
commit | d6000a208c7687ca3a3efd6961ac941ce325e199 (patch) | |
tree | 9644609a0d19894b46d065faec2cfe2aaeb410bd /tpl/template_test.go | |
parent | 4ea4359ac17a3b5304fb0d73773f99a07975ee1e (diff) |
all: Refactor to nonglobal template handling
Updates #2701
Diffstat (limited to 'tpl/template_test.go')
-rw-r--r-- | tpl/template_test.go | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/tpl/template_test.go b/tpl/template_test.go index 2f4946598..cf691858b 100644 --- a/tpl/template_test.go +++ b/tpl/template_test.go @@ -55,8 +55,6 @@ html lang=en for _, root := range []string{"", os.TempDir()} { - templ := New(logger) - basePath := this.basePath innerPath := this.innerPath @@ -70,17 +68,20 @@ html lang=en d := "DATA" - err := templ.AddAceTemplate("mytemplate.ace", basePath, innerPath, - []byte(this.baseContent), []byte(this.innerContent)) + templ := New(logger, func(templ Template) error { + return templ.AddAceTemplate("mytemplate.ace", basePath, innerPath, + []byte(this.baseContent), []byte(this.innerContent)) - if err != nil && this.expectErr == 0 { - t.Errorf("Test %d with root '%s' errored: %s", i, root, err) - } else if err == nil && this.expectErr == 1 { + }) + + if len(templ.errors) > 0 && this.expectErr == 0 { + t.Errorf("Test %d with root '%s' errored: %v", i, root, templ.errors) + } else if len(templ.errors) == 0 && this.expectErr == 1 { t.Errorf("#1 Test %d with root '%s' should have errored", i, root) } var buff bytes.Buffer - err = templ.ExecuteTemplate(&buff, "mytemplate.html", d) + err := templ.ExecuteTemplate(&buff, "mytemplate.html", d) if err != nil && this.expectErr == 0 { t.Errorf("Test %d with root '%s' errored: %s", i, root, err) @@ -245,7 +246,6 @@ func TestTplGoFuzzReports(t *testing.T) { // Issue #1095 {"{{apply .C \"urlize\" " + "\".\"}}", 2}} { - templ := New(logger) d := &Data{ A: 42, @@ -258,15 +258,17 @@ func TestTplGoFuzzReports(t *testing.T) { H: "a,b,c,d,e,f", } - err := templ.AddTemplate("fuzz", this.data) + templ := New(logger, func(templ Template) error { + return templ.AddTemplate("fuzz", this.data) - if err != nil && this.expectErr == 0 { - t.Fatalf("Test %d errored: %s", i, err) - } else if err == nil && this.expectErr == 1 { - t.Fatalf("#1 Test %d should have errored", i) - } + }) - err = templ.ExecuteTemplate(ioutil.Discard, "fuzz", d) + if len(templ.errors) > 0 && this.expectErr == 0 { + t.Errorf("Test %d errored: %v", i, templ.errors) + } else if len(templ.errors) == 0 && this.expectErr == 1 { + t.Errorf("#1 Test %d should have errored", i) + } + err := templ.ExecuteTemplate(ioutil.Discard, "fuzz", d) if err != nil && this.expectErr == 0 { t.Fatalf("Test %d errored: %s", i, err) |