ref: fc06d5c18bb1e47f90f0297aa8121ee0775e047d
parent: 9a367d9d06db6f6cf22121d0397c464ae36e7089
author: Cameron Moore <[email protected]>
date: Sun Feb 4 17:09:14 EST 2018
hugolib: Add additional test to TestTemplateLookupOrder Add an additional test to "Variant 4, theme, use site base" to also test for the index.html base (from by testing of #3505). Also add a "name" field to the test cases to make it easier to know which test is failing versus just getting a slice index.
--- a/hugolib/template_test.go
+++ b/hugolib/template_test.go
@@ -37,12 +37,13 @@
// 2. <current-path>/baseof.<suffix>
// 3. _default/<template-name>-baseof.<suffix>, e.g. list-baseof.<suffix>.
// 4. _default/baseof.<suffix>
- for i, this := range []struct {
+ for _, this := range []struct {
+ name string
setup func(t *testing.T)
assert func(t *testing.T)
}{
{
- // Variant 1
+ "Variant 1",
func(t *testing.T) {
writeSource(t, fs, filepath.Join("layouts", "section", "sect1-baseof.html"), `Base: {{block "main" .}}block{{end}}`)
writeSource(t, fs, filepath.Join("layouts", "section", "sect1.html"), `{{define "main"}}sect{{ end }}`)
@@ -53,7 +54,7 @@
},
},
{
- // Variant 2
+ "Variant 2",
func(t *testing.T) {
writeSource(t, fs, filepath.Join("layouts", "baseof.html"), `Base: {{block "main" .}}block{{end}}`)
writeSource(t, fs, filepath.Join("layouts", "index.html"), `{{define "main"}}index{{ end }}`)
@@ -64,7 +65,7 @@
},
},
{
- // Variant 3
+ "Variant 3",
func(t *testing.T) {
writeSource(t, fs, filepath.Join("layouts", "_default", "list-baseof.html"), `Base: {{block "main" .}}block{{end}}`)
writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`)
@@ -75,7 +76,7 @@
},
},
{
- // Variant 4
+ "Variant 4",
func(t *testing.T) {
writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), `Base: {{block "main" .}}block{{end}}`)
writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`)
@@ -86,7 +87,7 @@
},
},
{
- // Variant 1, theme, use project's base
+ "Variant 1, theme, use site base",
func(t *testing.T) {
cfg.Set("theme", "mytheme")
writeSource(t, fs, filepath.Join("layouts", "section", "sect1-baseof.html"), `Base: {{block "main" .}}block{{end}}`)
@@ -99,7 +100,7 @@
},
},
{
- // Variant 1, theme, use theme's base
+ "Variant 1, theme, use theme base",
func(t *testing.T) {
cfg.Set("theme", "mytheme")
writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "section", "sect1-baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`)
@@ -111,20 +112,22 @@
},
},
{
- // Variant 4, theme, use project's base
+ "Variant 4, theme, use site base",
func(t *testing.T) {
cfg.Set("theme", "mytheme")
writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), `Base: {{block "main" .}}block{{end}}`)
writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`)
writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`)
+ writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "index.html"), `{{define "main"}}index{{ end }}`)
},
func(t *testing.T) {
th.assertFileContent(filepath.Join("public", "sect1", "index.html"), "Base: list")
+ th.assertFileContent(filepath.Join("public", "index.html"), "Base: index") // Issue #3505
},
},
{
- // Variant 4, theme, use themes's base
+ "Variant 4, theme, use themes base",
func(t *testing.T) {
cfg.Set("theme", "mytheme")
writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`)
@@ -136,8 +139,8 @@
},
},
{
- // Test section list and single template selection.
// Issue #3116
+ "Test section list and single template selection",
func(t *testing.T) {
cfg.Set("theme", "mytheme")
@@ -160,8 +163,8 @@
},
},
{
- // Test section list and single template selection with base template.
// Issue #2995
+ "Test section list and single template selection with base template",
func(t *testing.T) {
writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), `Base Default: {{block "main" .}}block{{end}}`)
@@ -204,7 +207,7 @@
this.setup(t)
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
- t.Log("Template Lookup test", i)
+ t.Log(this.name)
this.assert(t)
}