github.com/kovansky/hugo@v0.92.3-0.20220224232819-63076e4ff19f/tpl/tplimpl/integration_test.go (about) 1 package tplimpl_test 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 qt "github.com/frankban/quicktest" 8 "github.com/gohugoio/hugo/hugolib" 9 "github.com/gohugoio/hugo/tpl" 10 ) 11 12 func TestPrintUnusedTemplates(t *testing.T) { 13 t.Parallel() 14 15 files := ` 16 -- config.toml -- 17 baseURL = 'http://example.com/' 18 printUnusedTemplates=true 19 -- content/p1.md -- 20 --- 21 title: "P1" 22 --- 23 {{< usedshortcode >}} 24 -- layouts/baseof.html -- 25 {{ block "main" . }}{{ end }} 26 -- layouts/baseof.json -- 27 {{ block "main" . }}{{ end }} 28 -- layouts/index.html -- 29 {{ define "main" }}FOO{{ end }} 30 -- layouts/_default/single.json -- 31 -- layouts/_default/single.html -- 32 {{ define "main" }}MAIN{{ end }} 33 -- layouts/post/single.html -- 34 {{ define "main" }}MAIN{{ end }} 35 -- layouts/partials/usedpartial.html -- 36 -- layouts/partials/unusedpartial.html -- 37 -- layouts/shortcodes/usedshortcode.html -- 38 {{ partial "usedpartial.html" }} 39 -- layouts/shortcodes/unusedshortcode.html -- 40 41 ` 42 43 b := hugolib.NewIntegrationTestBuilder( 44 hugolib.IntegrationTestConfig{ 45 T: t, 46 TxtarString: files, 47 NeedsOsFS: true, 48 }, 49 ) 50 b.Build() 51 52 unused := b.H.Tmpl().(tpl.UnusedTemplatesProvider).UnusedTemplates() 53 54 var names []string 55 for _, tmpl := range unused { 56 names = append(names, tmpl.Name()) 57 } 58 59 b.Assert(names, qt.DeepEquals, []string{"_default/single.json", "baseof.json", "partials/unusedpartial.html", "post/single.html", "shortcodes/unusedshortcode.html"}) 60 b.Assert(unused[0].Filename(), qt.Equals, filepath.Join(b.Cfg.WorkingDir, "layouts/_default/single.json")) 61 }