Fix baseof block regression

From Hugo 0.74.0.

Fixes #7478
This commit is contained in:
Bjørn Erik Pedersen
2020-07-13 13:40:35 +02:00
parent 6e0452e189
commit c91dbe4ce9
3 changed files with 94 additions and 65 deletions

View File

@@ -65,7 +65,8 @@ func TestSiteBuildErrors(t *testing.T) {
fileFixer: func(content string) string {
return strings.Replace(content, ".Title }}", ".Title }", 1)
},
assertCreateError: func(a testSiteBuildErrorAsserter, err error) {
// Base templates gets parsed at build time.
assertBuildError: func(a testSiteBuildErrorAsserter, err error) {
a.assertLineNumber(4, err)
},
},
@@ -90,7 +91,7 @@ func TestSiteBuildErrors(t *testing.T) {
a.c.Assert(fe.Position().LineNumber, qt.Equals, 5)
a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 1)
a.c.Assert(fe.ChromaLexer, qt.Equals, "go-html-template")
a.assertErrorMessage("\"layouts/_default/single.html:5:1\": parse failed: template: _default/single.html.___b:5: unexpected \"}\" in operand", fe.Error())
a.assertErrorMessage("\"layouts/foo/single.html:5:1\": parse failed: template: foo/single.html:5: unexpected \"}\" in operand", fe.Error())
},
},

View File

@@ -677,3 +677,46 @@ P3: Inline: p3
)
}
// https://github.com/gohugoio/hugo/issues/7478
func TestBaseWithAndWithoutDefine(t *testing.T) {
b := newTestSitesBuilder(t)
b.WithContent("p1.md", "---\ntitle: P\n---\nContent")
b.WithTemplates(
"_default/baseof.html", `
::Header Start:{{ block "header" . }}{{ end }}:Header End:
::{{ block "main" . }}Main{{ end }}::
`, "index.html", `
{{ define "header" }}
Home Header
{{ end }}
{{ define "main" }}
This is home main
{{ end }}
`,
"_default/single.html", `
{{ define "main" }}
This is single main
{{ end }}
`,
)
b.CreateSites().Build(BuildCfg{})
b.AssertFileContent("public/index.html", `
Home Header
This is home main
`,
)
b.AssertFileContent("public/p1/index.html", `
::Header Start::Header End:
This is single main
`,
)
}