Skip to content

Commit

Permalink
Add breaking tests for "map read and map write in templates"
Browse files Browse the repository at this point in the history
The fix upstream in Go was reverted, so we apply a temporary patch for this in Hugo.

Updates #7293
  • Loading branch information
bep committed Feb 18, 2021
1 parent ccb822e commit b5485ae
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 61 deletions.
60 changes: 0 additions & 60 deletions hugolib/embedded_templates_norace_test.go

This file was deleted.

39 changes: 39 additions & 0 deletions hugolib/embedded_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ package hugolib

import (
"testing"

qt "github.com/frankban/quicktest"
)

func TestInternalTemplatesImage(t *testing.T) {
Expand Down Expand Up @@ -77,3 +79,40 @@ title: My Site
<meta itemprop="image" content="https://example.org/siteimg1.jpg"/>
`)
}

// Just some simple test of the embedded templates to avoid
// https://github.com/gohugoio/hugo/issues/4757 and similar.
func TestEmbeddedTemplates(t *testing.T) {
t.Parallel()

c := qt.New(t)
c.Assert(true, qt.Equals, true)

home := []string{"index.html", `
GA:
{{ template "_internal/google_analytics.html" . }}
GA async:
{{ template "_internal/google_analytics_async.html" . }}
Disqus:
{{ template "_internal/disqus.html" . }}
`}

b := newTestSitesBuilder(t)
b.WithSimpleConfigFile().WithTemplatesAdded(home...)

b.Build(BuildCfg{})

// Gheck GA regular and async
b.AssertFileContent("public/index.html",
"'anonymizeIp', true",
"'script','https://www.google-analytics.com/analytics.js','ga');\n\tga('create', 'ga_id', 'auto')",
"<script async src='https://www.google-analytics.com/analytics.js'>")

// Disqus
b.AssertFileContent("public/index.html", "\"disqus_shortname\" + '.disqus.com/embed.js';")
}
1 change: 1 addition & 0 deletions scripts/fork_go_templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var (
"\"text/template\"\n", "template \"github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate\"\n",
`"html/template"`, `htmltemplate "html/template"`,
`"fmt"`, `htmltemplate "html/template"`,
`t.Skip("this test currently fails with -race; see issue #39807")`, `// t.Skip("this test currently fails with -race; see issue #39807")`,
)
)

Expand Down
2 changes: 1 addition & 1 deletion tpl/internal/go_templates/htmltemplate/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ var v = "v";
`

func TestEscapeRace(t *testing.T) {
t.Skip("this test currently fails with -race; see issue #39807")
// t.Skip("this test currently fails with -race; see issue #39807")

tmpl := New("")
_, err := tmpl.New("templ.html").Parse(raceText)
Expand Down

0 comments on commit b5485ae

Please sign in to comment.