mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
@@ -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
|
||||
|
Reference in New Issue
Block a user