Add warnidf template function

Also rename config `ignoreErrors` => `ignoreLogs`

But the old still works.

Closes #9189
This commit is contained in:
Bjørn Erik Pedersen
2024-01-30 09:23:21 +01:00
parent f31a6db797
commit 4e84f57efb
11 changed files with 83 additions and 29 deletions

View File

@@ -16,6 +16,7 @@ package fmt_test
import (
"testing"
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/hugolib"
)
@@ -32,13 +33,25 @@ ignoreErrors = ['error-b']
{{ erroridf "error-b" "%s" "b"}}
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
)
b, err := hugolib.TestE(t, files)
b.BuildE()
b.AssertLogMatches(`^ERROR a\nYou can suppress this error by adding the following to your site configuration:\nignoreErrors = \['error-a'\]\n$`)
b.Assert(err, qt.IsNotNil)
b.AssertLogMatches(`^ERROR a\nYou can suppress this error by adding the following to your site configuration:\nignoreLogs = \['error-a'\]\n$`)
}
func TestWarnidf(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
ignoreLogs = ['warning-b']
-- layouts/index.html --
{{ warnidf "warning-a" "%s" "a"}}
{{ warnidf "warning-b" "%s" "b"}}
`
b := hugolib.Test(t, files, hugolib.TestOptWarn())
b.AssertLogContains("WARN a", "You can suppress this warning", "ignoreLogs", "['warning-a']")
b.AssertLogNotContains("['warning-b']")
}