aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-06-22 18:41:18 +0200
committerBjørn Erik Pedersen <[email protected]>2024-06-22 19:01:56 +0200
commit8731d8822216dd3c7587769e3cf5d98690717b0c (patch)
tree8661a711d403756c65c1a8a3bea0bdbc5aa8b12f /hugolib
parent3b724462c24b6824c8ac4a3a9ec8dbe274809032 (diff)
downloadhugo-8731d8822216dd3c7587769e3cf5d98690717b0c.tar.gz
hugo-8731d8822216dd3c7587769e3cf5d98690717b0c.zip
Fix Erroridf/Warnidf mixed case issue
Fixes #12617
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/cascade_test.go4
-rw-r--r--hugolib/integrationtest_builder.go42
-rw-r--r--hugolib/menu_test.go2
-rw-r--r--hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go4
4 files changed, 34 insertions, 18 deletions
diff --git a/hugolib/cascade_test.go b/hugolib/cascade_test.go
index 7a4b6e6be..cbceaaed5 100644
--- a/hugolib/cascade_test.go
+++ b/hugolib/cascade_test.go
@@ -779,7 +779,7 @@ title: "Post 1"
{{ .Title }}|{{ .Params.foo }}$
`
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) {
@@ -813,7 +813,7 @@ foo = 'bar'
path = '/p1.md'
`
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) {
diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go
index 7495d3341..758fc4ec9 100644
--- a/hugolib/integrationtest_builder.go
+++ b/hugolib/integrationtest_builder.go
@@ -206,24 +206,34 @@ func (b *lockingBuffer) Write(p []byte) (n int, err error) {
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) {
s.Helper()
for _, el := range els {
- s.Assert(s.lastBuildLog, qt.Contains, el)
- }
-}
-
-func (s *IntegrationTestBuilder) AssertLogNotContains(els ...string) {
- s.Helper()
- for _, el := range els {
- s.Assert(s.lastBuildLog, qt.Not(qt.Contains), el)
+ var negate bool
+ el, negate = s.negate(el)
+ check := qt.Contains
+ if negate {
+ check = qt.Not(qt.Contains)
+ }
+ s.Assert(s.lastBuildLog, check, 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) {
s.Helper()
+ var negate bool
+ expression, negate = s.negate(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) {
@@ -258,6 +268,15 @@ func (s *IntegrationTestBuilder) AssertFileCount(dirname string, expected int) {
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) {
s.Helper()
content := strings.TrimSpace(s.FileContent(filename))
@@ -270,10 +289,7 @@ func (s *IntegrationTestBuilder) AssertFileContent(filename string, matches ...s
continue
}
var negate bool
- if strings.HasPrefix(match, "! ") {
- negate = true
- match = strings.TrimPrefix(match, "! ")
- }
+ match, negate = s.negate(match)
if negate {
s.Assert(content, qt.Not(qt.Contains), match, cm)
continue
diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go
index 9e73a8dc3..304b4fbf4 100644
--- a/hugolib/menu_test.go
+++ b/hugolib/menu_test.go
@@ -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/fr/index.html", `<a href="/fr/p1/">p1</a>`)
- b.AssertLogNotContains("WARN")
+ b.AssertLogContains("! WARN")
}
func TestSectionPagesIssue12399(t *testing.T) {
diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
index 3c50f87f7..709d6db7b 100644
--- a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
+++ b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
@@ -562,7 +562,7 @@ title: "p1"
b = hugolib.Test(t, files, hugolib.TestOptWarn())
- b.AssertLogNotContains("WARN")
+ b.AssertLogContains("! WARN")
}
func TestPagesFromGoTmplPathWarningsPathResource(t *testing.T) {
@@ -597,7 +597,7 @@ value: data1
b = hugolib.Test(t, files, hugolib.TestOptWarn())
- b.AssertLogNotContains("WARN")
+ b.AssertLogContains("! WARN")
}
func TestPagesFromGoTmplShortcodeNoPreceddingCharacterIssue12544(t *testing.T) {