diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-02-15 15:26:18 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-02-15 20:01:57 +0100 |
commit | f2e7b49acfaeab4e1a28cb1096f6461b555900fa (patch) | |
tree | 1dbcdfe580801a81f978ee0b5dd7b89523da2b9c /tpl/tplimpl/integration_test.go | |
parent | 923419d7fde2056f47668acb0981135bce543b7e (diff) |
Add --printUnusedTemplates
Fixes #9502
Diffstat (limited to 'tpl/tplimpl/integration_test.go')
-rw-r--r-- | tpl/tplimpl/integration_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tpl/tplimpl/integration_test.go b/tpl/tplimpl/integration_test.go new file mode 100644 index 000000000..f71e28bc1 --- /dev/null +++ b/tpl/tplimpl/integration_test.go @@ -0,0 +1,61 @@ +package tplimpl_test + +import ( + "path/filepath" + "testing" + + qt "github.com/frankban/quicktest" + "github.com/gohugoio/hugo/hugolib" + "github.com/gohugoio/hugo/tpl" +) + +func TestPrintUnusedTemplates(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +baseURL = 'http://example.com/' +printUnusedTemplates=true +-- content/p1.md -- +--- +title: "P1" +--- +{{< usedshortcode >}} +-- layouts/baseof.html -- +{{ block "main" . }}{{ end }} +-- layouts/baseof.json -- +{{ block "main" . }}{{ end }} +-- layouts/index.html -- +{{ define "main" }}FOO{{ end }} +-- layouts/_default/single.json -- +-- layouts/_default/single.html -- +{{ define "main" }}MAIN{{ end }} +-- layouts/post/single.html -- +{{ define "main" }}MAIN{{ end }} +-- layouts/partials/usedpartial.html -- +-- layouts/partials/unusedpartial.html -- +-- layouts/shortcodes/usedshortcode.html -- +{{ partial "usedpartial.html" }} +-- layouts/shortcodes/unusedshortcode.html -- + + ` + + b := hugolib.NewIntegrationTestBuilder( + hugolib.IntegrationTestConfig{ + T: t, + TxtarString: files, + NeedsOsFS: true, + }, + ) + b.Build() + + unused := b.H.Tmpl().(tpl.UnusedTemplatesProvider).UnusedTemplates() + + var names []string + for _, tmpl := range unused { + names = append(names, tmpl.Name()) + } + + b.Assert(names, qt.DeepEquals, []string{"_default/single.json", "baseof.json", "partials/unusedpartial.html", "post/single.html", "shortcodes/unusedshortcode.html"}) + b.Assert(unused[0].Filename(), qt.Equals, filepath.Join(b.Cfg.WorkingDir, "layouts/_default/single.json")) +} |