mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
3b724462c2
commit
8731d88222
7 changed files with 53 additions and 23 deletions
|
@ -323,11 +323,13 @@ func (l *logAdapter) Errors() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logAdapter) Erroridf(id, format string, v ...any) {
|
func (l *logAdapter) Erroridf(id, format string, v ...any) {
|
||||||
|
id = strings.ToLower(id)
|
||||||
format += l.idfInfoStatement("error", id, format)
|
format += l.idfInfoStatement("error", id, format)
|
||||||
l.errorl.WithField(FieldNameStatementID, id).Logf(format, v...)
|
l.errorl.WithField(FieldNameStatementID, id).Logf(format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logAdapter) Warnidf(id, format string, v ...any) {
|
func (l *logAdapter) Warnidf(id, format string, v ...any) {
|
||||||
|
id = strings.ToLower(id)
|
||||||
format += l.idfInfoStatement("warning", id, format)
|
format += l.idfInfoStatement("warning", id, format)
|
||||||
l.warnl.WithField(FieldNameStatementID, id).Logf(format, v...)
|
l.warnl.WithField(FieldNameStatementID, id).Logf(format, v...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,9 +315,13 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i, s := range c.IgnoreLogs {
|
||||||
|
c.IgnoreLogs[i] = strings.ToLower(s)
|
||||||
|
}
|
||||||
|
|
||||||
ignoredLogIDs := make(map[string]bool)
|
ignoredLogIDs := make(map[string]bool)
|
||||||
for _, err := range c.IgnoreLogs {
|
for _, err := range c.IgnoreLogs {
|
||||||
ignoredLogIDs[strings.ToLower(err)] = true
|
ignoredLogIDs[err] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
baseURL, err := urls.NewBaseURLFromString(c.BaseURL)
|
baseURL, err := urls.NewBaseURLFromString(c.BaseURL)
|
||||||
|
|
|
@ -779,7 +779,7 @@ title: "Post 1"
|
||||||
{{ .Title }}|{{ .Params.foo }}$
|
{{ .Title }}|{{ .Params.foo }}$
|
||||||
`
|
`
|
||||||
b := Test(t, files)
|
b := Test(t, files)
|
||||||
b.AssertLogNotContains(`looks like a path with an extension`)
|
b.AssertLogContains(`! looks like a path with an extension`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCascadConfigExtensionInPath(t *testing.T) {
|
func TestCascadConfigExtensionInPath(t *testing.T) {
|
||||||
|
@ -813,7 +813,7 @@ foo = 'bar'
|
||||||
path = '/p1.md'
|
path = '/p1.md'
|
||||||
`
|
`
|
||||||
b := Test(t, files)
|
b := Test(t, files)
|
||||||
b.AssertLogNotContains(`looks like a path with an extension`)
|
b.AssertLogContains(`! looks like a path with an extension`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCascadeIssue12172(t *testing.T) {
|
func TestCascadeIssue12172(t *testing.T) {
|
||||||
|
|
|
@ -206,24 +206,34 @@ func (b *lockingBuffer) Write(p []byte) (n int, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssertLogContains asserts that the last build log contains the given strings.
|
||||||
|
// Each string can be negated with a "! " prefix.
|
||||||
func (s *IntegrationTestBuilder) AssertLogContains(els ...string) {
|
func (s *IntegrationTestBuilder) AssertLogContains(els ...string) {
|
||||||
s.Helper()
|
s.Helper()
|
||||||
for _, el := range els {
|
for _, el := range els {
|
||||||
s.Assert(s.lastBuildLog, qt.Contains, el)
|
var negate bool
|
||||||
}
|
el, negate = s.negate(el)
|
||||||
}
|
check := qt.Contains
|
||||||
|
if negate {
|
||||||
func (s *IntegrationTestBuilder) AssertLogNotContains(els ...string) {
|
check = qt.Not(qt.Contains)
|
||||||
s.Helper()
|
}
|
||||||
for _, el := range els {
|
s.Assert(s.lastBuildLog, check, el)
|
||||||
s.Assert(s.lastBuildLog, qt.Not(qt.Contains), el)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssertLogNotContains asserts that the last build log does matches the given regular expressions.
|
||||||
|
// The regular expressions can be negated with a "! " prefix.
|
||||||
func (s *IntegrationTestBuilder) AssertLogMatches(expression string) {
|
func (s *IntegrationTestBuilder) AssertLogMatches(expression string) {
|
||||||
s.Helper()
|
s.Helper()
|
||||||
|
var negate bool
|
||||||
|
expression, negate = s.negate(expression)
|
||||||
re := regexp.MustCompile(expression)
|
re := regexp.MustCompile(expression)
|
||||||
s.Assert(re.MatchString(s.lastBuildLog), qt.IsTrue, qt.Commentf(s.lastBuildLog))
|
checker := qt.IsTrue
|
||||||
|
if negate {
|
||||||
|
checker = qt.IsFalse
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Assert(re.MatchString(s.lastBuildLog), checker, qt.Commentf(s.lastBuildLog))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IntegrationTestBuilder) AssertBuildCountData(count int) {
|
func (s *IntegrationTestBuilder) AssertBuildCountData(count int) {
|
||||||
|
@ -258,6 +268,15 @@ func (s *IntegrationTestBuilder) AssertFileCount(dirname string, expected int) {
|
||||||
s.Assert(count, qt.Equals, expected)
|
s.Assert(count, qt.Equals, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *IntegrationTestBuilder) negate(match string) (string, bool) {
|
||||||
|
var negate bool
|
||||||
|
if strings.HasPrefix(match, "! ") {
|
||||||
|
negate = true
|
||||||
|
match = strings.TrimPrefix(match, "! ")
|
||||||
|
}
|
||||||
|
return match, negate
|
||||||
|
}
|
||||||
|
|
||||||
func (s *IntegrationTestBuilder) AssertFileContent(filename string, matches ...string) {
|
func (s *IntegrationTestBuilder) AssertFileContent(filename string, matches ...string) {
|
||||||
s.Helper()
|
s.Helper()
|
||||||
content := strings.TrimSpace(s.FileContent(filename))
|
content := strings.TrimSpace(s.FileContent(filename))
|
||||||
|
@ -270,10 +289,7 @@ func (s *IntegrationTestBuilder) AssertFileContent(filename string, matches ...s
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var negate bool
|
var negate bool
|
||||||
if strings.HasPrefix(match, "! ") {
|
match, negate = s.negate(match)
|
||||||
negate = true
|
|
||||||
match = strings.TrimPrefix(match, "! ")
|
|
||||||
}
|
|
||||||
if negate {
|
if negate {
|
||||||
s.Assert(content, qt.Not(qt.Contains), match, cm)
|
s.Assert(content, qt.Not(qt.Contains), match, cm)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -674,7 +674,7 @@ menu: main
|
||||||
|
|
||||||
b.AssertFileContent("public/en/index.html", `<a href="/en/p1/">p1</a><a href="/en/p2/">p2</a>`)
|
b.AssertFileContent("public/en/index.html", `<a href="/en/p1/">p1</a><a href="/en/p2/">p2</a>`)
|
||||||
b.AssertFileContent("public/fr/index.html", `<a href="/fr/p1/">p1</a>`)
|
b.AssertFileContent("public/fr/index.html", `<a href="/fr/p1/">p1</a>`)
|
||||||
b.AssertLogNotContains("WARN")
|
b.AssertLogContains("! WARN")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSectionPagesIssue12399(t *testing.T) {
|
func TestSectionPagesIssue12399(t *testing.T) {
|
||||||
|
|
|
@ -562,7 +562,7 @@ title: "p1"
|
||||||
|
|
||||||
b = hugolib.Test(t, files, hugolib.TestOptWarn())
|
b = hugolib.Test(t, files, hugolib.TestOptWarn())
|
||||||
|
|
||||||
b.AssertLogNotContains("WARN")
|
b.AssertLogContains("! WARN")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPagesFromGoTmplPathWarningsPathResource(t *testing.T) {
|
func TestPagesFromGoTmplPathWarningsPathResource(t *testing.T) {
|
||||||
|
@ -597,7 +597,7 @@ value: data1
|
||||||
|
|
||||||
b = hugolib.Test(t, files, hugolib.TestOptWarn())
|
b = hugolib.Test(t, files, hugolib.TestOptWarn())
|
||||||
|
|
||||||
b.AssertLogNotContains("WARN")
|
b.AssertLogContains("! WARN")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPagesFromGoTmplShortcodeNoPreceddingCharacterIssue12544(t *testing.T) {
|
func TestPagesFromGoTmplShortcodeNoPreceddingCharacterIssue12544(t *testing.T) {
|
||||||
|
|
|
@ -27,16 +27,22 @@ func TestErroridf(t *testing.T) {
|
||||||
files := `
|
files := `
|
||||||
-- hugo.toml --
|
-- hugo.toml --
|
||||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||||
ignoreErrors = ['error-b']
|
ignoreErrors = ['error-b','error-C']
|
||||||
-- layouts/index.html --
|
-- layouts/index.html --
|
||||||
{{ erroridf "error-a" "%s" "a"}}
|
{{ erroridf "error-a" "%s" "a"}}
|
||||||
{{ erroridf "error-b" "%s" "b"}}
|
{{ erroridf "error-b" "%s" "b"}}
|
||||||
|
{{ erroridf "error-C" "%s" "C"}}
|
||||||
|
{{ erroridf "error-c" "%s" "c"}}
|
||||||
|
{{ erroridf "error-d" "%s" "D"}}
|
||||||
`
|
`
|
||||||
|
|
||||||
b, err := hugolib.TestE(t, files)
|
b, err := hugolib.TestE(t, files)
|
||||||
|
|
||||||
b.Assert(err, qt.IsNotNil)
|
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$`)
|
b.AssertLogMatches(`ERROR a\nYou can suppress this error by adding the following to your site configuration:\nignoreLogs = \['error-a'\]`)
|
||||||
|
b.AssertLogMatches(`ERROR D`)
|
||||||
|
b.AssertLogMatches(`! ERROR C`)
|
||||||
|
b.AssertLogMatches(`! ERROR c`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWarnidf(t *testing.T) {
|
func TestWarnidf(t *testing.T) {
|
||||||
|
@ -45,13 +51,15 @@ func TestWarnidf(t *testing.T) {
|
||||||
files := `
|
files := `
|
||||||
-- hugo.toml --
|
-- hugo.toml --
|
||||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||||
ignoreLogs = ['warning-b']
|
ignoreLogs = ['warning-b', 'WarniNg-C']
|
||||||
-- layouts/index.html --
|
-- layouts/index.html --
|
||||||
{{ warnidf "warning-a" "%s" "a"}}
|
{{ warnidf "warning-a" "%s" "a"}}
|
||||||
{{ warnidf "warning-b" "%s" "b"}}
|
{{ warnidf "warning-b" "%s" "b"}}
|
||||||
|
{{ warnidf "warNing-C" "%s" "c"}}
|
||||||
`
|
`
|
||||||
|
|
||||||
b := hugolib.Test(t, files, hugolib.TestOptWarn())
|
b := hugolib.Test(t, files, hugolib.TestOptWarn())
|
||||||
b.AssertLogContains("WARN a", "You can suppress this warning", "ignoreLogs", "['warning-a']")
|
b.AssertLogContains("WARN a", "You can suppress this warning", "ignoreLogs", "['warning-a']")
|
||||||
b.AssertLogNotContains("['warning-b']")
|
b.AssertLogContains("! ['warning-b']")
|
||||||
|
b.AssertLogContains("! ['warning-c']")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue