From fc06d5c18bb1e47f90f0297aa8121ee0775e047d Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Sun, 4 Feb 2018 22:09:14 -0600 Subject: [PATCH] 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. --- hugolib/template_test.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/hugolib/template_test.go b/hugolib/template_test.go index 4117d0f47..eed3ee8ed 100644 --- a/hugolib/template_test.go +++ b/hugolib/template_test.go @@ -37,12 +37,13 @@ func TestTemplateLookupOrder(t *testing.T) { // 2. /baseof. // 3. _default/-baseof., e.g. list-baseof.. // 4. _default/baseof. - 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 @@ func TestTemplateLookupOrder(t *testing.T) { }, }, { - // 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 @@ func TestTemplateLookupOrder(t *testing.T) { }, }, { - // 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 @@ func TestTemplateLookupOrder(t *testing.T) { }, }, { - // 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 @@ func TestTemplateLookupOrder(t *testing.T) { }, }, { - // 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 @@ func TestTemplateLookupOrder(t *testing.T) { }, }, { - // 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 @@ func TestTemplateLookupOrder(t *testing.T) { }, }, { - // 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 @@ func TestTemplateLookupOrder(t *testing.T) { }, }, { - // 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 @@ func TestTemplateLookupOrder(t *testing.T) { }, }, { - // 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 @@ Some content 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) }