diff options
| author | Michael Stapelberg <michael@stapelberg.de> | 2013-03-23 11:28:53 +0100 | 
|---|---|---|
| committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-23 11:28:53 +0100 | 
| commit | b39e15dde5ec7b96c15da9faf4ab5892501c1aae (patch) | |
| tree | 718cede1f6ca97d082c6c40b7dc3f4f6148253c0 /src/pkg/text/template/exec_test.go | |
| parent | 04b08da9af0c450d645ab7389d1467308cfc2db8 (diff) | |
| download | golang-upstream/1.1_hg20130323.tar.gz | |
Imported Upstream version 1.1~hg20130323upstream/1.1_hg20130323
Diffstat (limited to 'src/pkg/text/template/exec_test.go')
| -rw-r--r-- | src/pkg/text/template/exec_test.go | 37 | 
1 files changed, 37 insertions, 0 deletions
| diff --git a/src/pkg/text/template/exec_test.go b/src/pkg/text/template/exec_test.go index 683e9ac76..0f8beec5e 100644 --- a/src/pkg/text/template/exec_test.go +++ b/src/pkg/text/template/exec_test.go @@ -816,3 +816,40 @@ func TestExecuteOnNewTemplate(t *testing.T) {  	// This is issue 3872.  	_ = New("Name").Templates()  } + +const testTemplates = `{{define "one"}}one{{end}}{{define "two"}}two{{end}}` + +func TestMessageForExecuteEmpty(t *testing.T) { +	// Test a truly empty template. +	tmpl := New("empty") +	var b bytes.Buffer +	err := tmpl.Execute(&b, 0) +	if err == nil { +		t.Fatal("expected initial error") +	} +	got := err.Error() +	want := `template: empty: "empty" is an incomplete or empty template` +	if got != want { +		t.Errorf("expected error %s got %s", want, got) +	} +	// Add a non-empty template to check that the error is helpful. +	tests, err := New("").Parse(testTemplates) +	if err != nil { +		t.Fatal(err) +	} +	tmpl.AddParseTree("secondary", tests.Tree) +	err = tmpl.Execute(&b, 0) +	if err == nil { +		t.Fatal("expected second error") +	} +	got = err.Error() +	want = `template: empty: "empty" is an incomplete or empty template; defined templates are: "secondary"` +	if got != want { +		t.Errorf("expected error %s got %s", want, got) +	} +	// Make sure we can execute the secondary. +	err = tmpl.ExecuteTemplate(&b, "secondary", 0) +	if err != nil { +		t.Fatal(err) +	} +} | 
