From 982d9513e71b3d48e20cfa38454a0e1215a8d963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 28 Jan 2024 22:11:05 +0100 Subject: testing: Simplify some integration tests --- .../codeblocks/codeblocks_integration_test.go | 46 ++--------- markup/goldmark/goldmark_integration_test.go | 89 +++------------------- markup/goldmark/images/images_integration_test.go | 32 +------- markup/highlight/highlight_integration_test.go | 16 +--- 4 files changed, 23 insertions(+), 160 deletions(-) (limited to 'markup') diff --git a/markup/goldmark/codeblocks/codeblocks_integration_test.go b/markup/goldmark/codeblocks/codeblocks_integration_test.go index 5597fc507..8ed691302 100644 --- a/markup/goldmark/codeblocks/codeblocks_integration_test.go +++ b/markup/goldmark/codeblocks/codeblocks_integration_test.go @@ -87,13 +87,7 @@ echo "l8"; §§§ ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` Goat SVG:fmt.Println("Hello, World!");|", @@ -188,13 +176,7 @@ title: "p1" ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` # Issue 9627: For the Position in code blocks we try to match the .Inner with the original source. This isn't always possible. @@ -223,13 +205,7 @@ echo "p1"; ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "|echo \"p1\";|") } @@ -257,12 +233,7 @@ Position: {{ .Position | safeHTML }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", filepath.FromSlash("Position: \"/content/p1.md:7:1\"")) } @@ -290,12 +261,7 @@ Hello, World! Attributes: {{ .Attributes }}|Type: {{ .Type }}| ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "

Issue 10118

\nAttributes: map[foo:bar]|Type: |") } diff --git a/markup/goldmark/goldmark_integration_test.go b/markup/goldmark/goldmark_integration_test.go index c9c6ef338..ffeb763a7 100644 --- a/markup/goldmark/goldmark_integration_test.go +++ b/markup/goldmark/goldmark_integration_test.go @@ -50,13 +50,7 @@ foo {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", `

@@ -85,13 +79,7 @@ title: "p1" >{{ .Text | safeHTML }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", `

Heading

@@ -111,13 +99,7 @@ title: "p1" {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` class="a < b" @@ -141,13 +123,7 @@ safeHTML: |{{- range $k, $v := .Attributes -}}{{ $k }}: {{ $v | safeHTML }}|{{ e {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` plain: |class: Smith & Wesson|id: heading-attribute-which-needs-escaping| @@ -178,13 +154,7 @@ title: "p1" ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "

\n Hello Test\n\n #\n

", @@ -252,12 +222,7 @@ LINE8 ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "
LINE1\n
", @@ -397,7 +362,6 @@ FENCE runBenchmark(files, b) }) - } // Iisse #8959 @@ -406,7 +370,6 @@ func TestHookInfiniteRecursion(t *testing.T) { for _, renderFunc := range []string{"markdownify", ".Page.RenderString"} { t.Run(renderFunc, func(t *testing.T) { - files := ` -- config.toml -- -- layouts/_default/_markup/render-link.html -- @@ -436,11 +399,8 @@ a@b.com b.Assert(err, qt.IsNotNil) b.Assert(err.Error(), qt.Contains, "text is already rendered, repeating it may cause infinite recursion") - }) - } - } // Issue 9594 @@ -460,12 +420,7 @@ title: "p1" {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` "a" @@ -476,7 +431,6 @@ func TestLinkifyProtocol(t *testing.T) { t.Parallel() runTest := func(protocol string, withHook bool) *hugolib.IntegrationTestBuilder { - files := ` -- config.toml -- [markup.goldmark] @@ -507,7 +461,6 @@ Link https procol: https://www.example.org TxtarString: files, }, ).Build() - } for _, withHook := range []bool{false, true} { @@ -564,12 +517,7 @@ a c {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContentExact("public/p1/index.html", // Issue 9650 @@ -621,12 +569,7 @@ sc3_begin|{{ .Inner }}|sc3_end {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContentExact("public/p1/index.html", // Issue #7332 @@ -657,12 +600,7 @@ title: "p1" {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContentExact("public/p1/index.html", "

:x:

") } @@ -680,12 +618,7 @@ title: "p1" {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContentExact("public/p1/index.html", "

:x:

") } diff --git a/markup/goldmark/images/images_integration_test.go b/markup/goldmark/images/images_integration_test.go index 8b0ba99c1..387287e7a 100644 --- a/markup/goldmark/images/images_integration_test.go +++ b/markup/goldmark/images/images_integration_test.go @@ -45,13 +45,7 @@ This is an inline image: ![Inline Image](/inline.jpg). Some more text. {{ .Text }}|{{ .Ordinal }} {{ end }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "This is an inline image: \n\t\"Inline\n. Some more text.

", @@ -70,13 +64,7 @@ This is an inline image: ![Inline Image](/inline.jpg). Some more text. {{ .Text }} {{ end }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "This is an inline image: \n\t\"Inline\n. Some more text.

", @@ -86,26 +74,14 @@ This is an inline image: ![Inline Image](/inline.jpg). Some more text. t.Run("No Hook, no wrap", func(t *testing.T) { files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "false") - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "

This is an inline image: \"Inline. Some more text.

\n\"Block") }) t.Run("No Hook, wrap", func(t *testing.T) { files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "true") - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "

\"Block

") }) diff --git a/markup/highlight/highlight_integration_test.go b/markup/highlight/highlight_integration_test.go index b53b585c0..d36bc820a 100644 --- a/markup/highlight/highlight_integration_test.go +++ b/markup/highlight/highlight_integration_test.go @@ -67,13 +67,7 @@ HighlightCodeBlock: Wrapped:{{ $result.Wrapped }}|Inner:{{ $result.Inner }} {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "Inline:(message "this highlight shortcode"):End.", @@ -103,13 +97,7 @@ xəx := 0 {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/index.html", ` xəx -- cgit v1.2.3