all: Replace NewIntegrationTestBuilder with Test/TestE/TestRunning

This commit is contained in:
Bjørn Erik Pedersen
2026-04-03 20:11:23 +02:00
parent 43aad7118d
commit 481baa0896
47 changed files with 230 additions and 1130 deletions
@@ -74,12 +74,7 @@ Desc: {{ sort (sort $values "b" "desc") "a" "desc" }}
for range 4 {
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := hugolib.Test(t, files)
b.AssertFileContent("public/index.html", `
Asc: [map[a:0 b:0] map[a:0 b:0] map[a:0 b:3] map[a:1 b:0] map[a:1 b:1] map[a:1 b:2] map[a:1 b:2] map[a:2 b:0] map[a:2 b:0] map[a:2 b:0] map[a:2 b:1] map[a:2 b:2] map[a:3 b:0] map[a:3 b:0] map[a:3 b:0] map[a:3 b:0] map[a:3 b:1] map[a:3 b:1] map[a:3 b:1] map[a:3 b:3]]
@@ -144,12 +139,7 @@ func TestAppendNilsToSliceWithNils(t *testing.T) {
for range 4 {
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := hugolib.Test(t, files)
b.AssertFileContent("public/index.html", "[a <nil> c <nil>]")
+1 -8
View File
@@ -16,7 +16,6 @@ package debug_test
import (
"testing"
"github.com/bep/logg"
"github.com/gohugoio/hugo/hugolib"
)
@@ -33,13 +32,7 @@ disableKinds = ["taxonomy", "term"]
{{ end }}
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
LogLevel: logg.LevelInfo,
},
).Build()
b := hugolib.Test(t, files, hugolib.TestOptInfo())
b.AssertLogContains("timer: name foo count 5 duration")
}
+2 -14
View File
@@ -37,13 +37,7 @@ START:|{{ range $entry := $entries }}{{ if not $entry.IsDir }}{{ $entry.Name }}|
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
).Build()
b := hugolib.Test(t, files, hugolib.TestOptOsFs())
b.AssertFileContent("public/index.html", `
START:|hugo.toml|myproject.txt|:END:
@@ -63,13 +57,7 @@ func TestReadFileNotExists(t *testing.T) {
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
).Build()
b := hugolib.Test(t, files, hugolib.TestOptOsFs())
b.AssertFileContent("public/index.html", `
OK
+6 -10
View File
@@ -26,7 +26,7 @@ import (
func TestReadFile(t *testing.T) {
t.Parallel()
b := newFileTestBuilder(t).Build()
b := newFileTestBuilder(t)
// helpers.PrintFs(b.H.PathSpec.BaseFs.Work, "", _os.Stdout)
@@ -59,7 +59,7 @@ func TestFileExists(t *testing.T) {
t.Parallel()
c := qt.New(t)
b := newFileTestBuilder(t).Build()
b := newFileTestBuilder(t)
ns := os.New(b.H.Deps)
for _, test := range []struct {
@@ -86,7 +86,7 @@ func TestFileExists(t *testing.T) {
func TestStat(t *testing.T) {
t.Parallel()
b := newFileTestBuilder(t).Build()
b := newFileTestBuilder(t)
ns := os.New(b.H.Deps)
for _, test := range []struct {
@@ -118,11 +118,7 @@ f1-content
f2-content
`
return hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
WorkingDir: "/mywork",
},
)
return hugolib.Test(t, files, hugolib.TestOptWithConfig(func(c *hugolib.IntegrationTestConfig) {
c.WorkingDir = "/mywork"
}))
}
+1 -6
View File
@@ -140,12 +140,7 @@ weight = 2
for range 1 {
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := hugolib.Test(t, files)
b.AssertFileContent("public/index.html", `
Heading OK.
+2 -12
View File
@@ -261,12 +261,7 @@ baseURL = 'http://example.com/'
{{ partial "foo.html" . }}
`
b, err := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
).BuildE()
b, err := hugolib.TestE(t, files)
b.Assert(err, qt.Not(qt.IsNil))
b.Assert(err.Error(), qt.Contains, "maximum template call stack size exceeded")
@@ -287,12 +282,7 @@ timeout = '200ms'
{{ partialCached "foo.html" . }}
`
b, err := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
).BuildE()
b, err := hugolib.TestE(t, files)
b.Assert(err, qt.Not(qt.IsNil))
b.Assert(err.Error(), qt.Contains, `error calling partialCached: circular call stack detected in partial`)
+1 -5
View File
@@ -85,11 +85,7 @@ func TestCopyPageShouldFail(t *testing.T) {
`
b, err := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
}).BuildE()
b, err := hugolib.TestE(t, files)
b.Assert(err, qt.IsNotNil)
}
+5 -15
View File
@@ -29,9 +29,7 @@ import (
func TestTimeLocation(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
loc, _ := gtime.LoadLocation("America/Antigua")
ns := time.New(htime.NewTimeFormatter(golocales.New("en")), loc, b.H.Deps)
@@ -91,9 +89,7 @@ func TestTimeLocation(t *testing.T) {
func TestFormat(t *testing.T) {
c := qt.New(t)
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
c.Run("UTC", func(c *qt.C) {
c.Parallel()
@@ -153,9 +149,7 @@ func TestFormat(t *testing.T) {
func TestDuration(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := time.New(htime.NewTimeFormatter(golocales.New("en")), gtime.UTC, b.H.Deps)
@@ -200,9 +194,7 @@ func TestDuration(t *testing.T) {
func TestIn(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := time.New(htime.NewTimeFormatter(golocales.New("en")), gtime.UTC, b.H.Deps)
@@ -241,9 +233,7 @@ func TestIn(t *testing.T) {
var timeZoneNames []string = []string{"America/New_York", "Europe/Oslo", "Australia/Sydney", "UTC", "Local"}
func BenchmarkInWithCaching(b *testing.B) {
bb := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: b},
).Build()
bb := hugolib.Test(b, "")
ns := time.New(htime.NewTimeFormatter(golocales.New("en")), gtime.UTC, bb.H.Deps)
+2 -14
View File
@@ -46,13 +46,7 @@ title: "**BatMan**"
---
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
).Build()
b := hugolib.Test(t, files, hugolib.TestOptOsFs())
d := b.H.Sites[0].Deps
@@ -78,13 +72,7 @@ title: "**BatMan**"
}
files += fmt.Sprintf("-- layouts/single.html --\n%s\n", strings.Join(templates, "\n"))
b = hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
).Build()
b = hugolib.Test(t, files, hugolib.TestOptOsFs())
b.AssertFileContent("public/blog/hugo-rocks/index.html", expected...)
}
@@ -379,14 +379,7 @@ title: "P1"
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
)
b.Build()
b := hugolib.Test(t, files, hugolib.TestOptOsFs())
b.AssertFileContent("public/p1/index.html", "MAIN /_default/single.html")
+4 -28
View File
@@ -55,14 +55,7 @@ counter2: {{ .Scratch.Get "counter" }}
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
)
b.Build()
b := hugolib.Test(t, files, hugolib.TestOptOsFs())
b.AssertFileContent("public/p1/index.html", `
continue:1345:END:
@@ -124,13 +117,7 @@ title: "S3P1"
{{ define "main" }}{{ .Title }}{{ end }}
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
)
b.Build()
b := hugolib.Test(t, files)
b.AssertFileContent("public/s1/p1/index.html", `S1P1`)
b.AssertFileContent("public/s2/p1/index.html", `S2P1`)
@@ -152,13 +139,7 @@ func TestGoTemplateBugs(t *testing.T) {
{{ end }}
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
)
b.Build()
b := hugolib.Test(t, files)
b.AssertFileContent("public/index.html", `key = value`)
})
@@ -176,12 +157,7 @@ var a = §§{{.Title }}§§;
files := strings.ReplaceAll(filesTemplate, "SECURITYCONFIG", "")
b, err := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
).BuildE()
b, err := hugolib.TestE(t, files)
// This used to fail, but not in >= Hugo 0.121.0.
b.Assert(err, qt.IsNil)
+2 -6
View File
@@ -26,9 +26,7 @@ import (
func TestRemarshal(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := transform.New(b.H.Deps)
c := qt.New(t)
@@ -241,9 +239,7 @@ c: &c [*b, *b, *b, *b, *b, *b, *b, *b, *b, *b]
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := transform.New(b.H.Deps)
+1 -8
View File
@@ -99,14 +99,7 @@ disableKinds = ['page','rss','section','sitemap','taxonomy','term']
-- layouts/home.html --
{{ highlight "a" "b" 0 }}
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
)
_, err := b.BuildE()
b, err := hugolib.TestE(t, files)
b.Assert(err.Error(), qt.Contains, "error calling highlight: invalid Highlight option: 0")
}
+7 -21
View File
@@ -29,9 +29,7 @@ type tstNoStringer struct{}
func TestEmojify(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := transform.New(b.H.Deps)
@@ -59,9 +57,7 @@ func TestEmojify(t *testing.T) {
func TestHighlight(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := transform.New(b.H.Deps)
@@ -104,9 +100,7 @@ func TestCanHighlight(t *testing.T) {
func TestHTMLEscape(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := transform.New(b.H.Deps)
@@ -134,9 +128,7 @@ func TestHTMLEscape(t *testing.T) {
func TestHTMLUnescape(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := transform.New(b.H.Deps)
@@ -164,9 +156,7 @@ func TestHTMLUnescape(t *testing.T) {
func TestMarkdownify(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := transform.New(b.H.Deps)
@@ -194,9 +184,7 @@ func TestMarkdownify(t *testing.T) {
// Issue #3040
func TestMarkdownifyBlocksOfText(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := transform.New(b.H.Deps)
@@ -220,9 +208,7 @@ And then some.
func TestPlainify(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := transform.New(b.H.Deps)
+3 -9
View File
@@ -82,9 +82,7 @@ func (t testContentResource) Key() string {
}
func TestUnmarshal(t *testing.T) {
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: t},
).Build()
b := hugolib.Test(t, "")
ns := transform.New(b.H.Deps)
@@ -191,9 +189,7 @@ a;b;c`, mime: media.Builtin.CSVType}, map[string]any{"DElimiter": ";", "Comment"
}
func BenchmarkUnmarshalString(b *testing.B) {
bb := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: b},
).Build()
bb := hugolib.Test(b, "")
ns := transform.New(bb.H.Deps)
@@ -218,9 +214,7 @@ func BenchmarkUnmarshalString(b *testing.B) {
}
func BenchmarkUnmarshalResource(b *testing.B) {
bb := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{T: b},
).Build()
bb := hugolib.Test(b, "")
ns := transform.New(bb.H.Deps)