diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-07-13 13:40:35 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-07-13 20:45:09 +0200 |
commit | c91dbe4ce9c30623ba6e686fd17efae935aa0cc5 (patch) | |
tree | c41378c6d2cb1885b0d4248c7356fccefc53980e /hugolib | |
parent | 6e0452e189884667cb58778768136ad28ac31688 (diff) |
Fix baseof block regression
From Hugo 0.74.0.
Fixes #7478
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/hugo_sites_build_errors_test.go | 5 | ||||
-rw-r--r-- | hugolib/template_test.go | 43 |
2 files changed, 46 insertions, 2 deletions
diff --git a/hugolib/hugo_sites_build_errors_test.go b/hugolib/hugo_sites_build_errors_test.go index 4de98a788..d90a8b364 100644 --- a/hugolib/hugo_sites_build_errors_test.go +++ b/hugolib/hugo_sites_build_errors_test.go @@ -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()) }, }, diff --git a/hugolib/template_test.go b/hugolib/template_test.go index 673d91b5c..a215f09dc 100644 --- a/hugolib/template_test.go +++ b/hugolib/template_test.go @@ -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 +`, + ) + +} |