diff options
author | Bjørn Erik Pedersen <[email protected]> | 2019-08-10 21:05:17 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2019-08-12 13:26:32 +0200 |
commit | 9e571827055dedb46b78c5db3d17d6913f14870b (patch) | |
tree | f5f0108afe0c9385ff6dc27664943d9f719f57ad /hugolib | |
parent | 6027ee11082d0b9d72de1d4d1980a702be294ad2 (diff) | |
download | hugo-9e571827055dedb46b78c5db3d17d6913f14870b.tar.gz hugo-9e571827055dedb46b78c5db3d17d6913f14870b.zip |
tests: Convert from testify to quicktest
Diffstat (limited to 'hugolib')
43 files changed, 1051 insertions, 1021 deletions
diff --git a/hugolib/alias_test.go b/hugolib/alias_test.go index 095ae1be2..b0491c13e 100644 --- a/hugolib/alias_test.go +++ b/hugolib/alias_test.go @@ -20,7 +20,7 @@ import ( "github.com/gohugoio/hugo/common/loggers" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) const pageWithAlias = `--- @@ -43,14 +43,14 @@ const aliasTemplate = "<html><body>ALIASTEMPLATE</body></html>" func TestAlias(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) b := newTestSitesBuilder(t) b.WithSimpleConfigFile().WithContent("blog/page.md", pageWithAlias) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 1) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 1) // the real page b.AssertFileContent("public/blog/page/index.html", "For some moments the old man") @@ -62,7 +62,7 @@ func TestAlias(t *testing.T) { func TestAliasMultipleOutputFormats(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) b := newTestSitesBuilder(t) b.WithSimpleConfigFile().WithContent("blog/page.md", pageWithAliasMultipleOutputs) @@ -82,7 +82,7 @@ func TestAliasMultipleOutputFormats(t *testing.T) { // the alias redirectors b.AssertFileContent("public/foo/bar/index.html", "<meta http-equiv=\"refresh\" content=\"0; ") b.AssertFileContent("public/amp/foo/bar/index.html", "<meta http-equiv=\"refresh\" content=\"0; ") - assert.False(b.CheckExists("public/foo/bar/index.json")) + c.Assert(b.CheckExists("public/foo/bar/index.json"), qt.Equals, false) } func TestAliasTemplate(t *testing.T) { diff --git a/hugolib/cascade_test.go b/hugolib/cascade_test.go index aebd7a825..d6701cf28 100644 --- a/hugolib/cascade_test.go +++ b/hugolib/cascade_test.go @@ -19,10 +19,9 @@ import ( "path" "testing" - "github.com/alecthomas/assert" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/parser" "github.com/gohugoio/hugo/parser/metadecoders" - "github.com/stretchr/testify/require" ) func BenchmarkCascade(b *testing.B) { @@ -31,7 +30,7 @@ func BenchmarkCascade(b *testing.B) { for i := 1; i <= len(allLangs); i += 2 { langs := allLangs[0:i] b.Run(fmt.Sprintf("langs-%d", len(langs)), func(b *testing.B) { - assert := require.New(b) + c := qt.New(b) b.StopTimer() builders := make([]*sitesBuilder, b.N) for i := 0; i < b.N; i++ { @@ -42,16 +41,15 @@ func BenchmarkCascade(b *testing.B) { for i := 0; i < b.N; i++ { builder := builders[i] err := builder.BuildE(BuildCfg{}) - assert.NoError(err) + c.Assert(err, qt.IsNil) first := builder.H.Sites[0] - assert.NotNil(first) + c.Assert(first, qt.Not(qt.IsNil)) } }) } } func TestCascade(t *testing.T) { - assert := assert.New(t) allLangs := []string{"en", "nn", "nb", "sv"} @@ -93,7 +91,7 @@ func TestCascade(t *testing.T) { // Check output formats set in cascade b.AssertFileContent("public/sect4/index.xml", `<link>https://example.org/sect4/index.xml</link>`) b.AssertFileContent("public/sect4/p1/index.xml", `<link>https://example.org/sect4/p1/index.xml</link>`) - assert.False(b.CheckExists("public/sect2/index.xml")) + b.C.Assert(b.CheckExists("public/sect2/index.xml"), qt.Equals, false) // Check cascade into bundled page b.AssertFileContent("public/bundle1/index.html", `Resources: bp1.md|home.png|`) diff --git a/hugolib/case_insensitive_test.go b/hugolib/case_insensitive_test.go index 8c94bf5db..bffffb6be 100644 --- a/hugolib/case_insensitive_test.go +++ b/hugolib/case_insensitive_test.go @@ -21,9 +21,9 @@ import ( "github.com/gohugoio/hugo/hugofs" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/spf13/afero" - "github.com/stretchr/testify/require" ) var ( @@ -135,6 +135,8 @@ Partial Site Global: {{ site.Params.COLOR }}|{{ site.Params.COLORS.YELLOW }} func TestCaseInsensitiveConfigurationVariations(t *testing.T) { t.Parallel() + c := qt.New(t) + // See issues 2615, 1129, 2590 and maybe some others // Also see 2598 // @@ -152,11 +154,11 @@ func TestCaseInsensitiveConfigurationVariations(t *testing.T) { caseMixingTestsWriteCommonSources(t, mm) cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Filename: "config.toml"}) - require.NoError(t, err) + c.Assert(err, qt.IsNil) fs := hugofs.NewFrom(mm, cfg) - th := testHelper{cfg, fs, t} + th := newTestHelper(cfg, fs, t) writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), ` Block Page Colors: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }} @@ -258,17 +260,17 @@ func TestCaseInsensitiveConfigurationForAllTemplateEngines(t *testing.T) { } func doTestCaseInsensitiveConfigurationForTemplateEngine(t *testing.T, suffix string, templateFixer func(s string) string) { - + c := qt.New(t) mm := afero.NewMemMapFs() caseMixingTestsWriteCommonSources(t, mm) cfg, err := LoadConfigDefault(mm) - require.NoError(t, err) + c.Assert(err, qt.IsNil) fs := hugofs.NewFrom(mm, cfg) - th := testHelper{cfg, fs, t} + th := newTestHelper(cfg, fs, t) t.Log("Testing", suffix) diff --git a/hugolib/collections_test.go b/hugolib/collections_test.go index 804c0cae1..6925d41cd 100644 --- a/hugolib/collections_test.go +++ b/hugolib/collections_test.go @@ -17,11 +17,11 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestGroupFunc(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageContent := ` --- @@ -39,14 +39,14 @@ title: "Page" `) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 2) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 2) b.AssertFileContent("public/index.html", "cool: 2") } func TestSliceFunc(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageContent := ` --- @@ -78,8 +78,8 @@ tags_weight: %d `) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 2) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 2) b.AssertFileContent("public/index.html", "pages:2:page.Pages:Page(/page1.md)/Page(/page2.md)", @@ -88,7 +88,7 @@ tags_weight: %d } func TestUnionFunc(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageContent := ` --- @@ -110,8 +110,8 @@ tags_weight: %d `) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 3) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 3) b.AssertFileContent("public/index.html", "unionPages: page.Pages 3", @@ -119,7 +119,7 @@ tags_weight: %d } func TestCollectionsFuncs(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageContent := ` --- @@ -151,8 +151,8 @@ Symdiff: {{ range $symdiff }}{{ .RelPermalink }}|{{ end }} `) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 3) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 3) b.AssertFileContent("public/index.html", "uniqPages: page.Pages 3", @@ -164,7 +164,7 @@ Symdiff: {{ range $symdiff }}{{ .RelPermalink }}|{{ end }} } func TestAppendFunc(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageContent := ` --- @@ -203,8 +203,8 @@ tags_weight: %d `) b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - assert.Len(b.H.Sites[0].RegularPages(), 2) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 2) b.AssertFileContent("public/index.html", "pages:2:page.Pages:Page(/page2.md)/Page(/page1.md)", diff --git a/hugolib/config_test.go b/hugolib/config_test.go index bd980235f..a52e3f061 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -19,15 +19,15 @@ import ( "path/filepath" "testing" + qt "github.com/frankban/quicktest" "github.com/spf13/afero" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) func TestLoadConfig(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) // Add a random config variable for testing. // side = page in Norwegian. @@ -40,16 +40,16 @@ func TestLoadConfig(t *testing.T) { writeToFs(t, mm, "hugo.toml", configContent) cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Filename: "hugo.toml"}) - require.NoError(t, err) + c.Assert(err, qt.IsNil) - assert.Equal("side", cfg.GetString("paginatePath")) + c.Assert(cfg.GetString("paginatePath"), qt.Equals, "side") } func TestLoadMultiConfig(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) // Add a random config variable for testing. // side = page in Norwegian. @@ -67,16 +67,16 @@ func TestLoadMultiConfig(t *testing.T) { writeToFs(t, mm, "override.toml", configContentSub) cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Filename: "base.toml,override.toml"}) - require.NoError(t, err) + c.Assert(err, qt.IsNil) - assert.Equal("top", cfg.GetString("paginatePath")) - assert.Equal("same", cfg.GetString("DontChange")) + c.Assert(cfg.GetString("paginatePath"), qt.Equals, "top") + c.Assert(cfg.GetString("DontChange"), qt.Equals, "same") } func TestLoadConfigFromTheme(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) mainConfigBasic := ` theme = "test-theme" @@ -291,7 +291,7 @@ map[string]interface {}{ } `, got["menus"]) - assert.Equal("https://example.com/", got["baseurl"]) + c.Assert(got["baseurl"], qt.Equals, "https://example.com/") if true { return @@ -314,7 +314,7 @@ map[string]interface {}{ }, }`, got["params"]) - assert.Nil(got["languages"]) + c.Assert(got["languages"], qt.IsNil) b.AssertObject(` map[string]interface {}{ "text/m1": map[string]interface {}{ @@ -365,7 +365,7 @@ map[string]interface {}{ func TestPrivacyConfig(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) tomlConfig := ` @@ -380,14 +380,14 @@ privacyEnhanced = true b.WithConfigFile("toml", tomlConfig) b.Build(BuildCfg{SkipRender: true}) - assert.True(b.H.Sites[0].Info.Config().Privacy.YouTube.PrivacyEnhanced) + c.Assert(b.H.Sites[0].Info.Config().Privacy.YouTube.PrivacyEnhanced, qt.Equals, true) } func TestLoadConfigModules(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) // https://github.com/gohugoio/hugoThemes#themetoml @@ -469,18 +469,20 @@ path="n4" var graphb bytes.Buffer modulesClient.Graph(&graphb) - assert.Equal(`project n1 + expected := `project n1 n1 o1 o1 n2 n1 n3 project n4 -`, graphb.String()) +` + + c.Assert(graphb.String(), qt.Equals, expected) } func TestLoadConfigWithOsEnvOverrides(t *testing.T) { - assert := require.New(t) + c := qt.New(t) baseConfig := ` @@ -512,13 +514,13 @@ resamplefilter = "CatmullRom" cfg := b.H.Cfg - assert.Equal("test", cfg.Get("environment")) - assert.Equal(false, cfg.GetBool("enablegitinfo")) - assert.Equal("new", cfg.Get("new")) - assert.Equal("top", cfg.Get("imaging.anchor")) - assert.Equal(int64(75), cfg.Get("imaging.quality")) - assert.Equal([]interface{}{"c", "d"}, cfg.Get("stringSlice")) - assert.Equal([]interface{}{5.32}, cfg.Get("floatSlice")) - assert.Equal([]interface{}{5, 8, 9}, cfg.Get("intSlice")) + c.Assert(cfg.Get("environment"), qt.Equals, "test") + c.Assert(cfg.GetBool("enablegitinfo"), qt.Equals, false) + c.Assert(cfg.Get("new"), qt.Equals, "new") + c.Assert(cfg.Get("imaging.anchor"), qt.Equals, "top") + c.Assert(cfg.Get("imaging.quality"), qt.Equals, int64(75)) + c.Assert(cfg.Get("stringSlice"), qt.DeepEquals, []interface{}{"c", "d"}) + c.Assert(cfg.Get("floatSlice"), qt.DeepEquals, []interface{}{5.32}) + c.Assert(cfg.Get("intSlice"), qt.DeepEquals, []interface{}{5, 8, 9}) } diff --git a/hugolib/configdir_test.go b/hugolib/configdir_test.go index c1afbb14e..bc1732fb2 100644 --- a/hugolib/configdir_test.go +++ b/hugolib/configdir_test.go @@ -19,15 +19,15 @@ import ( "github.com/gohugoio/hugo/common/herrors" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/htesting" "github.com/spf13/afero" - "github.com/stretchr/testify/require" ) func TestLoadConfigDir(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) configContent := ` baseURL = "https://example.org" @@ -107,29 +107,29 @@ p3 = "p3params_no_production" fb.Build() cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Environment: "development", Filename: "hugo.toml", AbsConfigDir: "config"}) - assert.NoError(err) + c.Assert(err, qt.IsNil) - assert.Equal("pag_development", cfg.GetString("paginatePath")) // /config/development/config.toml + c.Assert(cfg.GetString("paginatePath"), qt.Equals, "pag_development") // /config/development/config.toml - assert.Equal(10, cfg.GetInt("languages.no.weight")) // /config.toml - assert.Equal("Norsk_no_default", cfg.GetString("languages.no.languageName")) // /config/_default/languages.no.toml + c.Assert(cfg.GetInt("languages.no.weight"), qt.Equals, 10) // /config.toml + c.Assert(cfg.GetString("languages.no.languageName"), qt.Equals, "Norsk_no_default") // /config/_default/languages.no.toml - assert.Equal("p1_base", cfg.GetString("params.p1")) - assert.Equal("p2params_default", cfg.GetString("params.p2")) // Is in both _default and production - assert.Equal("p3params_development", cfg.GetString("params.p3")) - assert.Equal("p3params_no_development", cfg.GetString("languages.no.params.p3")) + c.Assert(cfg.GetString("params.p1"), qt.Equals, "p1_base") + c.Assert(cfg.GetString("params.p2"), qt.Equals, "p2params_default") // Is in both _default and production + c.Assert(cfg.GetString("params.p3"), qt.Equals, "p3params_development") + c.Assert(cfg.GetString("languages.no.params.p3"), qt.Equals, "p3params_no_development") - assert.Equal(2, len(cfg.Get("menus.docs").(([]map[string]interface{})))) + c.Assert(len(cfg.Get("menus.docs").(([]map[string]interface{}))), qt.Equals, 2) noMenus := cfg.Get("languages.no.menus.docs") - assert.NotNil(noMenus) - assert.Equal(1, len(noMenus.(([]map[string]interface{})))) + c.Assert(noMenus, qt.Not(qt.IsNil)) + c.Assert(len(noMenus.(([]map[string]interface{}))), qt.Equals, 1) } func TestLoadConfigDirError(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) configContent := ` baseURL = "https://example.org" @@ -145,10 +145,10 @@ baseURL = "https://example.org" fb.Add("config.toml", `invalid & syntax`).Build() _, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Environment: "development", Filename: "hugo.toml", AbsConfigDir: "config"}) - assert.Error(err) + c.Assert(err, qt.Not(qt.IsNil)) fe := herrors.UnwrapErrorWithFileContext(err) - assert.NotNil(fe) - assert.Equal(filepath.FromSlash("config/development/config.toml"), fe.Position().Filename) + c.Assert(fe, qt.Not(qt.IsNil)) + c.Assert(fe.Position().Filename, qt.Equals, filepath.FromSlash("config/development/config.toml")) } diff --git a/hugolib/datafiles_test.go b/hugolib/datafiles_test.go index b65183a8a..699cf9cd8 100644 --- a/hugolib/datafiles_test.go +++ b/hugolib/datafiles_test.go @@ -16,7 +16,6 @@ package hugolib import ( "path/filepath" "reflect" - "strings" "testing" "github.com/gohugoio/hugo/common/loggers" @@ -26,7 +25,7 @@ import ( "fmt" "runtime" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestDataDir(t *testing.T) { @@ -377,6 +376,7 @@ func TestDataFromShortcode(t *testing.T) { var ( cfg, fs = newTestCfg() + c = qt.New(t) ) writeSource(t, fs, "data/hugo.toml", "slogan = \"Hugo Rocks!\"") @@ -392,7 +392,7 @@ Slogan from shortcode: {{< d >}} buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) content := readSource(t, fs, "public/c/index.html") - require.True(t, strings.Contains(content, "Slogan from template: Hugo Rocks!"), content) - require.True(t, strings.Contains(content, "Slogan from shortcode: Hugo Rocks!"), content) + c.Assert(content, qt.Contains, "Slogan from template: Hugo Rocks!") + c.Assert(content, qt.Contains, "Slogan from shortcode: Hugo Rocks!") } diff --git a/hugolib/disableKinds_test.go b/hugolib/disableKinds_test.go index c191dfef1..b26385cc3 100644 --- a/hugolib/disableKinds_test.go +++ b/hugolib/disableKinds_test.go @@ -18,10 +18,10 @@ import ( "fmt" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/helpers" - "github.com/stretchr/testify/require" ) func TestDisableKindsNoneDisabled(t *testing.T) { @@ -104,8 +104,6 @@ categories: b.Build(BuildCfg{}) h := b.H - require.Len(t, h.Sites, 1) - assertDisabledKinds(b, h.Sites[0], disabled...) } @@ -181,7 +179,7 @@ func assertDisabledKinds(b *sitesBuilder, s *Site, disabled ...string) { func assertDisabledKind(b *sitesBuilder, kindAssert func(bool) bool, disabled []string, kind, path, matcher string) { isDisabled := stringSliceContains(kind, disabled...) - require.True(b.T, kindAssert(isDisabled), fmt.Sprintf("%s: %t", kind, isDisabled)) + b.Assert(kindAssert(isDisabled), qt.Equals, true) if kind == kindRSS && !isDisabled { // If the home page is also disabled, there is not RSS to look for. @@ -193,8 +191,8 @@ func assertDisabledKind(b *sitesBuilder, kindAssert func(bool) bool, disabled [] if isDisabled { // Path should not exist fileExists, err := helpers.Exists(path, b.Fs.Destination) - require.False(b.T, fileExists) - require.NoError(b.T, err) + b.Assert(err, qt.IsNil) + b.Assert(fileExists, qt.Equals, false) } else { b.AssertFileContent(path, matcher) diff --git a/hugolib/embedded_shortcodes_test.go b/hugolib/embedded_shortcodes_test.go index 8056b9842..a6f38d8f7 100644 --- a/hugolib/embedded_shortcodes_test.go +++ b/hugolib/embedded_shortcodes_test.go @@ -26,8 +26,8 @@ import ( "github.com/gohugoio/hugo/deps" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/tpl" - "github.com/stretchr/testify/require" ) const ( @@ -45,6 +45,7 @@ func TestShortcodeCrossrefs(t *testing.T) { func doTestShortcodeCrossrefs(t *testing.T, relative bool) { var ( cfg, fs = newTestCfg() + c = qt.New(t) ) cfg.Set("baseURL", testBaseURL) @@ -69,10 +70,10 @@ func doTestShortcodeCrossrefs(t *testing.T, relative bool) { s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) - require.Len(t, s.RegularPages(), 1) + c.Assert(len(s.RegularPages()), qt.Equals, 1) content, err := s.RegularPages()[0].Content() - require.NoError(t, err) + c.Assert(err, qt.IsNil) output := cast.ToString(content) if !strings.Contains(output, expected) { @@ -100,7 +101,7 @@ void do(); var ( cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} + th = newTestHelper(cfg, fs, t) ) cfg.Set("pygmentsStyle", "bw") @@ -148,7 +149,7 @@ func TestShortcodeFigure(t *testing.T) { var ( cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} + th = newTestHelper(cfg, fs, t) ) writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`--- @@ -187,7 +188,7 @@ func TestShortcodeYoutube(t *testing.T) { } { var ( cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} + th = newTestHelper(cfg, fs, t) ) writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`--- @@ -226,7 +227,7 @@ func TestShortcodeVimeo(t *testing.T) { } { var ( cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} + th = newTestHelper(cfg, fs, t) ) writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`--- @@ -259,7 +260,7 @@ func TestShortcodeGist(t *testing.T) { } { var ( cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} + th = newTestHelper(cfg, fs, t) ) writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`--- @@ -302,7 +303,7 @@ func TestShortcodeTweet(t *testing.T) { var ( cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} + th = newTestHelper(cfg, fs, t) ) withTemplate := func(templ tpl.TemplateHandler) error { @@ -357,7 +358,7 @@ func TestShortcodeInstagram(t *testing.T) { var ( cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} + th = newTestHelper(cfg, fs, t) ) withTemplate := func(templ tpl.TemplateHandler) error { diff --git a/hugolib/embedded_templates_test.go b/hugolib/embedded_templates_test.go index 2a1e2d3b2..a2debc253 100644 --- a/hugolib/embedded_templates_test.go +++ b/hugolib/embedded_templates_test.go @@ -16,7 +16,7 @@ package hugolib import ( "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) // Just some simple test of the embedded templates to avoid @@ -25,8 +25,8 @@ import ( func _TestEmbeddedTemplates(t *testing.T) { t.Parallel() - assert := require.New(t) - assert.True(true) + c := qt.New(t) + c.Assert(true, qt.Equals, true) home := []string{"index.html", ` GA: diff --git a/hugolib/fileInfo_test.go b/hugolib/fileInfo_test.go index c51ff5033..d8a70e9d3 100644 --- a/hugolib/fileInfo_test.go +++ b/hugolib/fileInfo_test.go @@ -16,16 +16,16 @@ package hugolib import ( "testing" + qt "github.com/frankban/quicktest" "github.com/spf13/cast" - "github.com/stretchr/testify/require" ) func TestFileInfo(t *testing.T) { t.Run("String", func(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) fi := &fileInfo{} _, err := cast.ToStringE(fi) - assert.NoError(err) + c.Assert(err, qt.IsNil) }) } diff --git a/hugolib/filesystems/basefs_test.go b/hugolib/filesystems/basefs_test.go index 62f968684..47aef63ce 100644 --- a/hugolib/filesystems/basefs_test.go +++ b/hugolib/filesystems/basefs_test.go @@ -27,11 +27,11 @@ import ( "github.com/spf13/afero" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/hugolib/paths" "github.com/gohugoio/hugo/modules" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) func initConfig(fs afero.Fs, cfg config.Provider) error { @@ -72,7 +72,7 @@ func initConfig(fs afero.Fs, cfg config.Provider) error { } func TestNewBaseFs(t *testing.T) { - assert := require.New(t) + c := qt.New(t) v := viper.New() fs := hugofs.NewMem(v) @@ -119,54 +119,52 @@ theme = ["atheme"] setConfigAndWriteSomeFilesTo(fs.Source, v, "resourceDir", "myrsesource", 10) v.Set("publishDir", "public") - assert.NoError(initConfig(fs.Source, v)) + c.Assert(initConfig(fs.Source, v), qt.IsNil) p, err := paths.New(fs, v) - assert.NoError(err) + c.Assert(err, qt.IsNil) bfs, err := NewBase(p, nil) - assert.NoError(err) - assert.NotNil(bfs) + c.Assert(err, qt.IsNil) + c.Assert(bfs, qt.Not(qt.IsNil)) root, err := bfs.I18n.Fs.Open("") - assert.NoError(err) + c.Assert(err, qt.IsNil) dirnames, err := root.Readdirnames(-1) - assert.NoError(err) - assert.Equal([]string{"f1.txt", "f2.txt", "f3.txt", "f4.txt", "f3.txt", "theme-file-btheme.txt", "f3.txt", "theme-file-atheme.txt"}, dirnames) + c.Assert(err, qt.IsNil) + c.Assert(dirnames, qt.DeepEquals, []string{"f1.txt", "f2.txt", "f3.txt", "f4.txt", "f3.txt", "theme-file-btheme.txt", "f3.txt", "theme-file-atheme.txt"}) root, err = bfs.Data.Fs.Open("") - assert.NoError(err) + c.Assert(err, qt.IsNil) dirnames, err = root.Readdirnames(-1) - assert.NoError(err) - assert.Equal([]string{"f1.txt", "f2.txt", "f3.txt", "f4.txt", "f5.txt", "f6.txt", "f7.txt", "f3.txt", "theme-file-btheme.txt", "f3.txt", "theme-file-atheme.txt"}, dirnames) + c.Assert(err, qt.IsNil) + c.Assert(dirnames, qt.DeepEquals, []string{"f1.txt", "f2.txt", "f3.txt", "f4.txt", "f5.txt", "f6.txt", "f7.txt", "f3.txt", "theme-file-btheme.txt", "f3.txt", "theme-file-atheme.txt"}) - //printFs(bfs.Work, "", os.Stdout) + checkFileCount(bfs.Layouts.Fs, "", c, 7) - checkFileCount(bfs.Layouts.Fs, "", assert, 7) + checkFileCount(bfs.Content.Fs, "", c, 3) + checkFileCount(bfs.I18n.Fs, "", c, 8) // 4 + 4 themes - checkFileCount(bfs.Content.Fs, "", assert, 3) - checkFileCount(bfs.I18n.Fs, "", assert, 8) // 4 + 4 themes + checkFileCount(bfs.Static[""].Fs, "", c, 6) + checkFileCount(bfs.Data.Fs, "", c, 11) // 7 + 4 themes + checkFileCount(bfs.Archetypes.Fs, "", c, 10) // 8 + 2 themes + checkFileCount(bfs.Assets.Fs, "", c, 9) + checkFileCount(bfs.Work, "", c, 82) - checkFileCount(bfs.Static[""].Fs, "", assert, 6) - checkFileCount(bfs.Data.Fs, "", assert, 11) // 7 + 4 themes - checkFileCount(bfs.Archetypes.Fs, "", assert, 10) // 8 + 2 themes - checkFileCount(bfs.Assets.Fs, "", assert, 9) - checkFileCount(bfs.Work, "", assert, 82) - - assert.True(bfs.IsData(filepath.Join(workingDir, "mydata", "file1.txt"))) - assert.True(bfs.IsI18n(filepath.Join(workingDir, "myi18n", "file1.txt"))) - assert.True(bfs.IsLayout(filepath.Join(workingDir, "mylayouts", "file1.txt"))) - assert.True(bfs.IsStatic(filepath.Join(workingDir, "mystatic", "file1.txt"))) - assert.True(bfs.IsAsset(filepath.Join(workingDir, "myassets", "file1.txt"))) + c.Assert(bfs.IsData(filepath.Join(workingDir, "mydata", "file1.txt")), qt.Equals, true) + c.Assert(bfs.IsI18n(filepath.Join(workingDir, "myi18n", "file1.txt")), qt.Equals, true) + c.Assert(bfs.IsLayout(filepath.Join(workingDir, "mylayouts", "file1.txt")), qt.Equals, true) + c.Assert(bfs.IsStatic(filepath.Join(workingDir, "mystatic", "file1.txt")), qt.Equals, true) + c.Assert(bfs.IsAsset(filepath.Join(workingDir, "myassets", "file1.txt")), qt.Equals, true) contentFilename := filepath.Join(workingDir, "mycontent", "file1.txt") - assert.True(bfs.IsContent(contentFilename)) + c.Assert(bfs.IsContent(contentFilename), qt.Equals, true) rel := bfs.RelContentDir(contentFilename) - assert.Equal("file1.txt", rel) + c.Assert(rel, qt.Equals, "file1.txt") // Check Work fs vs theme - checkFileContent(bfs.Work, "file-root.txt", assert, "content-project") - checkFileContent(bfs.Work, "theme-root-atheme.txt", assert, "content:atheme") + checkFileContent(bfs.Work, "file-root.txt", c, "content-project") + checkFileContent(bfs.Work, "theme-root-atheme.txt", c, "content:atheme") // https://github.com/gohugoio/hugo/issues/5318 // Check both project and theme. @@ -174,10 +172,10 @@ theme = ["atheme"] for _, filename := range []string{"/f1.txt", "/theme-file-atheme.txt"} { filename = filepath.FromSlash(filename) f, err := fs.Open(filename) - assert.NoError(err) + c.Assert(err, qt.IsNil) name := f.Name() f.Close() - assert.Equal(filename, name) + c.Assert(name, qt.Equals, filename) } } } @@ -199,35 +197,35 @@ func createConfig() *viper.Viper { } func TestNewBaseFsEmpty(t *testing.T) { - assert := require.New(t) + c := qt.New(t) v := createConfig() fs := hugofs.NewMem(v) - assert.NoError(initConfig(fs.Source, v)) + c.Assert(initConfig(fs.Source, v), qt.IsNil) p, err := paths.New(fs, v) - assert.NoError(err) + c.Assert(err, qt.IsNil) bfs, err := NewBase(p, nil) - assert.NoError(err) - assert.NotNil(bfs) - assert.NotNil(bfs.Archetypes.Fs) - assert.NotNil(bfs.Layouts.Fs) - assert.NotNil(bfs.Data.Fs) - assert.NotNil(bfs.I18n.Fs) - assert.NotNil(bfs.Work) - assert.NotNil(bfs.Content.Fs) - assert.NotNil(bfs.Static) + c.Assert(err, qt.IsNil) + c.Assert(bfs, qt.Not(qt.IsNil)) + c.Assert(bfs.Archetypes.Fs, qt.Not(qt.IsNil)) + c.Assert(bfs.Layouts.Fs, qt.Not(qt.IsNil)) + c.Assert(bfs.Data.Fs, qt.Not(qt.IsNil)) + c.Assert(bfs.I18n.Fs, qt.Not(qt.IsNil)) + c.Assert(bfs.Work, qt.Not(qt.IsNil)) + c.Assert(bfs.Content.Fs, qt.Not(qt.IsNil)) + c.Assert(bfs.Static, qt.Not(qt.IsNil)) } func TestRealDirs(t *testing.T) { - assert := require.New(t) + c := qt.New(t) v := createConfig() fs := hugofs.NewDefault(v) sfs := fs.Source root, err := afero.TempDir(sfs, "", "realdir") - assert.NoError(err) + c.Assert(err, qt.IsNil) themesDir, err := afero.TempDir(sfs, "", "themesDir") - assert.NoError(err) + c.Assert(err, qt.IsNil) defer func() { os.RemoveAll(root) os.RemoveAll(themesDir) @@ -237,14 +235,14 @@ func TestRealDirs(t *testing.T) { v.Set("themesDir", themesDir) v.Set("theme", "mytheme") - assert.NoError(sfs.MkdirAll(filepath.Join(root, "myassets", "scss", "sf1"), 0755)) - assert.NoError(sfs.MkdirAll(filepath.Join(root, "myassets", "scss", "sf2"), 0755)) - assert.NoError(sfs.MkdirAll(filepath.Join(themesDir, "mytheme", "assets", "scss", "sf2"), 0755)) - assert.NoError(sfs.MkdirAll(filepath.Join(themesDir, "mytheme", "assets", "scss", "sf3"), 0755)) - assert.NoError(sfs.MkdirAll(filepath.Join(root, "resources"), 0755)) - assert.NoError(sfs.MkdirAll(filepath.Join(themesDir, "mytheme", "resources"), 0755)) + c.Assert(sfs.MkdirAll(filepath.Join(root, "myassets", "scss", "sf1"), 0755), qt.IsNil) + c.Assert(sfs.MkdirAll(filepath.Join(root, "myassets", "scss", "sf2"), 0755), qt.IsNil) + c.Assert(sfs.MkdirAll(filepath.Join(themesDir, "mytheme", "assets", "scss", "sf2"), 0755), qt.IsNil) + c.Assert(sfs.MkdirAll(filepath.Join(themesDir, "mytheme", "assets", "scss", "sf3"), 0755), qt.IsNil) + c.Assert(sfs.MkdirAll(filepath.Join(root, "resources"), 0755), qt.IsNil) + c.Assert(sfs.MkdirAll(filepath.Join(themesDir, "mytheme", "resources"), 0755), qt.IsNil) - assert.NoError(sfs.MkdirAll(filepath.Join(root, "myassets", "js", "f2"), 0755)) + c.Assert(sfs.MkdirAll(filepath.Join(root, "myassets", "js", "f2"), 0755), qt.IsNil) afero.WriteFile(sfs, filepath.Join(filepath.Join(root, "myassets", "scss", "sf1", "a1.scss")), []byte("content"), 0755) afero.WriteFile(sfs, filepath.Join(filepath.Join(root, "myassets", "scss", "sf2", "a3.scss")), []byte("content"), 0755) @@ -259,27 +257,27 @@ func TestRealDirs(t *testing.T) { afero.WriteFile(sfs, filepath.Join(filepath.Join(root, "myassets", "js", "f2", "a1.js")), []byte("content"), 0755) afero.WriteFile(sfs, filepath.Join(filepath.Join(root, "myassets", "js", "a2.js")), []byte("content"), 0755) - assert.NoError(initConfig(fs.Source, v)) + c.Assert(initConfig(fs.Source, v), qt.IsNil) p, err := paths.New(fs, v) - assert.NoError(err) + c.Assert(err, qt.IsNil) bfs, err := NewBase(p, nil) - assert.NoError(err) - assert.NotNil(bfs) + c.Assert(err, qt.IsNil) + c.Assert(bfs, qt.Not(qt.IsNil)) - checkFileCount(bfs.Assets.Fs, "", assert, 6) + checkFileCount(bfs.Assets.Fs, "", c, 6) realDirs := bfs.Assets.RealDirs("scss") - assert.Equal(2, len(realDirs)) - assert.Equal(filepath.Join(root, "myassets/scss"), realDirs[0]) - assert.Equal(filepath.Join(themesDir, "mytheme/assets/scss"), realDirs[len(realDirs)-1]) + c.Assert(len(realDirs), qt.Equals, 2) + c.Assert(realDirs[0], qt.Equals, filepath.Join(root, "myassets/scss")) + c.Assert(realDirs[len(realDirs)-1], qt.Equals, filepath.Join(themesDir, "mytheme/assets/scss")) - assert.NotNil(bfs.theBigFs) + c.Assert(bfs.theBigFs, qt.Not(qt.IsNil)) } func TestStaticFs(t *testing.T) { - assert := require.New(t) + c := qt.New(t) v := createConfig() workDir := "mywork" v.Set("workingDir", workDir) @@ -296,21 +294,21 @@ func TestStaticFs(t *testing.T) { afero.WriteFile(fs.Source, filepath.Join(themeStaticDir, "f2.txt"), []byte("Hugo Themes Still Rocks!"), 0755) afero.WriteFile(fs.Source, filepath.Join(themeStaticDir2, "f2.txt"), []byte("Hugo Themes Rocks in t2!"), 0755) - assert.NoError(initConfig(fs.Source, v)) + c.Assert(initConfig(fs.Source, v), qt.IsNil) p, err := paths.New(fs, v) - assert.NoError(err) + c.Assert(err, qt.IsNil) bfs, err := NewBase(p, nil) - assert.NoError(err) + c.Assert(err, qt.IsNil) sfs := bfs.StaticFs("en") - checkFileContent(sfs, "f1.txt", assert, "Hugo Rocks!") - checkFileContent(sfs, "f2.txt", assert, "Hugo Themes Still Rocks!") + checkFileContent(sfs, "f1.txt", c, "Hugo Rocks!") + checkFileContent(sfs, "f2.txt", c, "Hugo Themes Still Rocks!") } func TestStaticFsMultiHost(t *testing.T) { - assert := require.New(t) + c := qt.New(t) v := createConfig() workDir := "mywork" v.Set("workingDir", workDir) @@ -340,30 +338,30 @@ func TestStaticFsMultiHost(t *testing.T) { afero.WriteFile(fs.Source, filepath.Join(themeStaticDir, "f1.txt"), []byte("Hugo Themes Rocks!"), 0755) afero.WriteFile(fs.Source, filepath.Join(themeStaticDir, "f2.txt"), []byte("Hugo Themes Still Rocks!"), 0755) - assert.NoError(initConfig(fs.Source, v)) + c.Assert(initConfig(fs.Source, v), qt.IsNil) p, err := paths.New(fs, v) - assert.NoError(err) + c.Assert(err, qt.IsNil) bfs, err := NewBase(p, nil) - assert.NoError(err) + c.Assert(err, qt.IsNil) enFs := bfs.StaticFs("en") - checkFileContent(enFs, "f1.txt", assert, "Hugo Rocks!") - checkFileContent(enFs, "f2.txt", assert, "Hugo Themes Still Rocks!") + checkFileContent(enFs, "f1.txt", c, "Hugo Rocks!") + checkFileContent(enFs, "f2.txt", c, "Hugo Themes Still Rocks!") noFs := bfs.StaticFs("no") - checkFileContent(noFs, "f1.txt", assert, "Hugo Rocks in Norway!") - checkFileContent(noFs, "f2.txt", assert, "Hugo Themes Still Rocks!") + checkFileContent(noFs, "f1.txt", c, "Hugo Rocks in Norway!") + checkFileContent(noFs, "f2.txt", c, "Hugo Themes Still Rocks!") } func TestMakePathRelative(t *testing.T) { - assert := require.New(t) + c := qt.New(t) v := createConfig() fs := hugofs.NewMem(v) workDir := "mywork" v.Set("workingDir", workDir) - assert.NoError(fs.Source.MkdirAll(filepath.Join(workDir, "dist"), 0777)) - assert.NoError(fs.Source.MkdirAll(filepath.Join(workDir, "static"), 0777)) + c.Assert(fs.Source.MkdirAll(filepath.Join(workDir, "dist"), 0777), qt.IsNil) + c.Assert(fs.Source.MkdirAll(filepath.Join(workDir, "static"), 0777), qt.IsNil) moduleCfg := map[string]interface{}{ "mounts": []interface{}{ @@ -380,35 +378,35 @@ func TestMakePathRelative(t *testing.T) { v.Set("module", moduleCfg) - assert.NoError(initConfig(fs.Source, v)) + c.Assert(initConfig(fs.Source, v), qt.IsNil) p, err := paths.New(fs, v) - assert.NoError(err) + c.Assert(err, qt.IsNil) bfs, err := NewBase(p, nil) - assert.NoError(err) + c.Assert(err, qt.IsNil) sfs := bfs.Static[""] - assert.NotNil(sfs) + c.Assert(sfs, qt.Not(qt.IsNil)) - assert.Equal(filepath.FromSlash("/foo.txt"), sfs.MakePathRelative(filepath.Join(workDir, "static", "foo.txt"))) - assert.Equal(filepath.FromSlash("/dist/foo.txt"), sfs.MakePathRelative(filepath.Join(workDir, "dist", "foo.txt"))) + c.Assert(sfs.MakePathRelative(filepath.Join(workDir, "static", "foo.txt")), qt.Equals, filepath.FromSlash("/foo.txt")) + c.Assert(sfs.MakePathRelative(filepath.Join(workDir, "dist", "foo.txt")), qt.Equals, filepath.FromSlash("/dist/foo.txt")) } -func checkFileCount(fs afero.Fs, dirname string, assert *require.Assertions, expected int) { - count, fnames, err := countFileaAndGetFilenames(fs, dirname) - assert.NoError(err, fnames) - assert.Equal(expected, count, fnames) +func checkFileCount(fs afero.Fs, dirname string, c *qt.C, expected int) { + count, _, err := countFileaAndGetFilenames(fs, dirname) + c.Assert(err, qt.IsNil) + c.Assert(count, qt.Equals, expected) } -func checkFileContent(fs afero.Fs, filename string, assert *require.Assertions, expected ...string) { +func checkFileContent(fs afero.Fs, filename string, c *qt.C, expected ...string) { b, err := afero.ReadFile(fs, filename) - assert.NoError(err) + c.Assert(err, qt.IsNil) content := string(b) for _, e := range expected { - assert.Contains(content, e) + c.Assert(content, qt.Contains, e) } } diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go index 66b3609af..58244049e 100644 --- a/hugolib/hugo_modules_test.go +++ b/hugolib/hugo_modules_test.go @@ -33,9 +33,9 @@ import ( "github.com/gohugoio/hugo/htesting" "github.com/gohugoio/hugo/hugofs" + qt "github.com/frankban/quicktest" "github.com/gohugoio/testmodBuilder/mods" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) // TODO(bep) this fails when testmodBuilder is also building ... @@ -60,12 +60,12 @@ func TestHugoModules(t *testing.T) { rnd.Shuffle(len(testmods), func(i, j int) { testmods[i], testmods[j] = testmods[j], testmods[i] }) for _, m := range testmods[:2] { - assert := require.New(t) + c := qt.New(t) v := viper.New() workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-test") - assert.NoError(err) + c.Assert(err, qt.IsNil) defer clean() configTemplate := ` @@ -375,9 +375,9 @@ min_version = "5.0.0" b.Build(BuildCfg{}) - assert := require.New(t) + c := qt.New(t) - assert.Equal(uint64(2), logger.WarnCounter.Count()) + c.Assert(logger.WarnCounter.Count(), qt.Equals, uint64(2)) } @@ -389,13 +389,13 @@ func TestModulesSymlinks(t *testing.T) { os.Chdir(wd) }() - assert := require.New(t) + c := qt.New(t) // We need to use the OS fs for this. cfg := viper.New() fs := hugofs.NewFrom(hugofs.Os, cfg) workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-mod-sym") - assert.NoError(err) + c.Assert(err, qt.IsNil) defer clean() @@ -406,11 +406,11 @@ Data: {{ .Site.Data }} createDirsAndFiles := func(baseDir string) { for _, dir := range files.ComponentFolders { realDir := filepath.Join(baseDir, dir, "real") - assert.NoError(os.MkdirAll(realDir, 0777)) - assert.NoError(afero.WriteFile(fs.Source, filepath.Join(realDir, "data.toml"), []byte("[hello]\nother = \"hello\""), 0777)) + c.Assert(os.MkdirAll(realDir, 0777), qt.IsNil) + c.Assert(afero.WriteFile(fs.Source, filepath.Join(realDir, "data.toml"), []byte("[hello]\nother = \"hello\""), 0777), qt.IsNil) } - assert.NoError(afero.WriteFile(fs.Source, filepath.Join(baseDir, "layouts", "index.html"), []byte(homeTemplate), 0777)) + c.Assert(afero.WriteFile(fs.Source, filepath.Join(baseDir, "layouts", "index.html"), []byte(homeTemplate), 0777), qt.IsNil) } // Create project dirs and files. @@ -421,10 +421,10 @@ Data: {{ .Site.Data }} createSymlinks := func(baseDir, id string) { for _, dir := range files.ComponentFolders { - assert.NoError(os.Chdir(filepath.Join(baseDir, dir))) - assert.NoError(os.Symlink("real", fmt.Sprintf("realsym%s", id))) - assert.NoError(os.Chdir(filepath.Join(baseDir, dir, "real"))) - assert.NoError(os.Symlink("data.toml", fmt.Sprintf(filepath.FromSlash("datasym%s.toml"), id))) + c.Assert(os.Chdir(filepath.Join(baseDir, dir)), qt.IsNil) + c.Assert(os.Symlink("real", fmt.Sprintf("realsym%s", id)), qt.IsNil) + c.Assert(os.Chdir(filepath.Join(baseDir, dir, "real")), qt.IsNil) + c.Assert(os.Symlink("data.toml", fmt.Sprintf(filepath.FromSlash("datasym%s.toml"), id)), qt.IsNil) } } @@ -451,7 +451,7 @@ weight = 2 b.Fs = fs b.WithConfigFile("toml", config) - assert.NoError(os.Chdir(workDir)) + c.Assert(os.Chdir(workDir), qt.IsNil) b.Build(BuildCfg{}) @@ -493,10 +493,10 @@ weight = 2 } if shouldFail { - assert.Error(err) - assert.Equal(hugofs.ErrPermissionSymlink, err, filename) + c.Assert(err, qt.Not(qt.IsNil)) + c.Assert(err, qt.Equals, hugofs.ErrPermissionSymlink) } else { - assert.NoError(err, filename) + c.Assert(err, qt.IsNil) } } diff --git a/hugolib/hugo_sites_build_errors_test.go b/hugolib/hugo_sites_build_errors_test.go index 993b4e613..6c9c8b089 100644 --- a/hugolib/hugo_sites_build_errors_test.go +++ b/hugolib/hugo_sites_build_errors_test.go @@ -11,31 +11,31 @@ import ( "github.com/fortytw2/leaktest" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/herrors" - "github.com/stretchr/testify/require" ) type testSiteBuildErrorAsserter struct { - name string - assert *require.Assertions + name string + c *qt.C } func (t testSiteBuildErrorAsserter) getFileError(err error) *herrors.ErrorWithFileContext { - t.assert.NotNil(err, t.name) + t.c.Assert(err, qt.Not(qt.IsNil), qt.Commentf(t.name)) ferr := herrors.UnwrapErrorWithFileContext(err) - t.assert.NotNil(ferr, fmt.Sprintf("[%s] got %T: %+v\n%s", t.name, err, err, stackTrace())) + t.c.Assert(ferr, qt.Not(qt.IsNil)) return ferr } func (t testSiteBuildErrorAsserter) assertLineNumber(lineNumber int, err error) { fe := t.getFileError(err) - t.assert.Equal(lineNumber, fe.Position().LineNumber, fmt.Sprintf("[%s] got => %s\n%s", t.name, fe, stackTrace())) + t.c.Assert(fe.Position().LineNumber, qt.Equals, lineNumber) } func (t testSiteBuildErrorAsserter) assertErrorMessage(e1, e2 string) { // The error message will contain filenames with OS slashes. Normalize before compare. e1, e2 = filepath.ToSlash(e1), filepath.ToSlash(e2) - t.assert.Contains(e2, e1, stackTrace()) + t.c.Assert(e2, qt.Contains, e1) } @@ -89,9 +89,9 @@ func TestSiteBuildErrors(t *testing.T) { }, assertCreateError: func(a testSiteBuildErrorAsserter, err error) { fe := a.getFileError(err) - a.assert.Equal(5, fe.Position().LineNumber) - a.assert.Equal(1, fe.Position().ColumnNumber) - a.assert.Equal("go-html-template", fe.ChromaLexer) + a.c.Assert(fe.Position().LineNumber, qt.Equals, 5) + a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 1) + a.c.Assert(fe.ChromaLexer, qt.Equals, "go-html-template") a.assertErrorMessage("\"layouts/_default/single.html:5:1\": parse failed: template: _default/single.html:5: unexpected \"}\" in operand", fe.Error()) }, @@ -104,9 +104,9 @@ func TestSiteBuildErrors(t *testing.T) { }, assertBuildError: func(a testSiteBuildErrorAsserter, err error) { fe := a.getFileError(err) - a.assert.Equal(5, fe.Position().LineNumber) - a.assert.Equal(14, fe.Position().ColumnNumber) - a.assert.Equal("go-html-template", fe.ChromaLexer) + a.c.Assert(fe.Position().LineNumber, qt.Equals, 5) + a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 14) + a.c.Assert(fe.ChromaLexer, qt.Equals, "go-html-template") a.assertErrorMessage("\"layouts/_default/single.html:5:14\": execute of template failed", fe.Error()) }, @@ -119,9 +119,9 @@ func TestSiteBuildErrors(t *testing.T) { }, assertBuildError: func(a testSiteBuildErrorAsserter, err error) { fe := a.getFileError(err) - a.assert.Equal(5, fe.Position().LineNumber) - a.assert.Equal(14, fe.Position().ColumnNumber) - a.assert.Equal("go-html-template", fe.ChromaLexer) + a.c.Assert(fe.Position().LineNumber, qt.Equals, 5) + a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 14) + a.c.Assert(fe.ChromaLexer, qt.Equals, "go-html-template") a.assertErrorMessage("\"layouts/_default/single.html:5:14\": execute of template failed", fe.Error()) }, @@ -144,8 +144,8 @@ func TestSiteBuildErrors(t *testing.T) { }, assertBuildError: func(a testSiteBuildErrorAsserter, err error) { fe := a.getFileError(err) - a.assert.Equal(7, fe.Position().LineNumber) - a.assert.Equal("md", fe.ChromaLexer) + a.c.Assert(fe.Position().LineNumber, qt.Equals, 7) + a.c.Assert(fe.ChromaLexer, qt.Equals, "md") // Make sure that it contains both the content file and template a.assertErrorMessage(`content/myyaml.md:7:10": failed to render shortcode "sc"`, fe.Error()) a.assertErrorMessage(`shortcodes/sc.html:4:22: executing "shortcodes/sc.html" at <.Page.Titles>: can't evaluate`, fe.Error()) @@ -159,9 +159,9 @@ func TestSiteBuildErrors(t *testing.T) { }, assertBuildError: func(a testSiteBuildErrorAsserter, err error) { fe := a.getFileError(err) - a.assert.Equal(7, fe.Position().LineNumber) - a.assert.Equal(10, fe.Position().ColumnNumber) - a.assert.Equal("md", fe.ChromaLexer) + a.c.Assert(fe.Position().LineNumber, qt.Equals, 7) + a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 10) + a.c.Assert(fe.ChromaLexer, qt.Equals, "md") a.assertErrorMessage(`"content/myyaml.md:7:10": failed to extract shortcode: template for shortcode "nono" not found`, fe.Error()) }, }, @@ -183,8 +183,8 @@ func TestSiteBuildErrors(t *testing.T) { }, assertBuildError: func(a testSiteBuildErrorAsserter, err error) { fe := a.getFileError(err) - a.assert.Equal(6, fe.Position().LineNumber) - a.assert.Equal("toml", fe.ErrorContext.ChromaLexer) + a.c.Assert(fe.Position().LineNumber, qt.Equals, 6) + a.c.Assert(fe.ErrorContext.ChromaLexer, qt.Equals, "toml") }, }, @@ -197,8 +197,8 @@ func TestSiteBuildErrors(t *testing.T) { assertBuildError: func(a testSiteBuildErrorAsserter, err error) { fe := a.getFileError(err) - a.assert.Equal(3, fe.Position().LineNumber) - a.assert.Equal("json", fe.ErrorContext.ChromaLexer) + a.c.Assert(fe.Position().LineNumber, qt.Equals, 3) + a.c.Assert(fe.ErrorContext.ChromaLexer, qt.Equals, "json") }, }, @@ -211,14 +211,14 @@ func TestSiteBuildErrors(t *testing.T) { }, assertBuildError: func(a testSiteBuildErrorAsserter, err error) { - a.assert.Error(err) + a.c.Assert(err, qt.Not(qt.IsNil)) // This is fixed in latest Go source if regexp.MustCompile("devel|12").MatchString(runtime.Version()) { fe := a.getFileError(err) - a.assert.Equal(5, fe.Position().LineNumber) - a.assert.Equal(21, fe.Position().ColumnNumber) + a.c.Assert(fe.Position().LineNumber, qt.Equals, 5) + a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 21) } else { - a.assert.Contains(err.Error(), `execute of template failed: panic in Execute`) + a.c.Assert(err.Error(), qt.Contains, `execute of template failed: panic in Execute`) } }, }, @@ -228,10 +228,10 @@ func TestSiteBuildErrors(t *testing.T) { test := test t.Run(test.name, func(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) errorAsserter := testSiteBuildErrorAsserter{ - assert: assert, - name: test.name, + c: c, + name: test.name, } b := newTestSitesBuilder(t).WithSimpleConfigFile() @@ -306,7 +306,7 @@ Some content. if test.assertCreateError != nil { test.assertCreateError(errorAsserter, createErr) } else { - assert.NoError(createErr) + c.Assert(createErr, qt.IsNil) } if createErr == nil { @@ -314,7 +314,7 @@ Some content. if test.assertBuildError != nil { test.assertBuildError(errorAsserter, buildErr) } else { - assert.NoError(buildErr) + c.Assert(buildErr, qt.IsNil) } } }) diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go index 15e4920f0..1a690cdd9 100644 --- a/hugolib/hugo_sites_build_test.go +++ b/hugolib/hugo_sites_build_test.go @@ -8,6 +8,7 @@ import ( "path/filepath" "time" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/resources/page" "github.com/fortytw2/leaktest" @@ -15,7 +16,6 @@ import ( "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/hugofs" "github.com/spf13/afero" - "github.com/stretchr/testify/require" ) func TestMultiSitesMainLangInRoot(t *testing.T) { @@ -26,7 +26,7 @@ func TestMultiSitesMainLangInRoot(t *testing.T) { } func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) { - assert := require.New(t) + c := qt.New(t) siteConfig := map[string]interface{}{ "DefaultContentLanguage": "fr", @@ -49,29 +49,28 @@ func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) { b.Build(BuildCfg{}) sites := b.H.Sites - - require.Len(t, sites, 4) + c.Assert(len(sites), qt.Equals, 4) enSite := sites[0] frSite := sites[1] - assert.Equal("/en", enSite.Info.LanguagePrefix) + c.Assert(enSite.Info.LanguagePrefix, qt.Equals, "/en") if defaultInSubDir { - assert.Equal("/fr", frSite.Info.LanguagePrefix) + c.Assert(frSite.Info.LanguagePrefix, qt.Equals, "/fr") } else { - assert.Equal("", frSite.Info.LanguagePrefix) + c.Assert(frSite.Info.LanguagePrefix, qt.Equals, "") } - assert.Equal("/blog/en/foo", enSite.PathSpec.RelURL("foo", true)) + c.Assert(enSite.PathSpec.RelURL("foo", true), qt.Equals, "/blog/en/foo") doc1en := enSite.RegularPages()[0] doc1fr := frSite.RegularPages()[0] enPerm := doc1en.Permalink() enRelPerm := doc1en.RelPermalink() - assert.Equal("http://example.com/blog/en/sect/doc1-slug/", enPerm) - assert.Equal("/blog/en/sect/doc1-slug/", enRelPerm) + c.Assert(enPerm, qt.Equals, "http://example.com/blog/en/sect/doc1-slug/") + c.Assert(enRelPerm, qt.Equals, "/blog/en/sect/doc1-slug/") frPerm := doc1fr.Permalink() frRelPerm := doc1fr.RelPermalink() @@ -80,15 +79,15 @@ func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) { b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Hello") if defaultInSubDir { - assert.Equal("http://example.com/blog/fr/sect/doc1/", frPerm) - assert.Equal("/blog/fr/sect/doc1/", frRelPerm) + c.Assert(frPerm, qt.Equals, "http://example.com/blog/fr/sect/doc1/") + c.Assert(frRelPerm, qt.Equals, "/blog/fr/sect/doc1/") // should have a redirect on top level. b.AssertFileContent("public/index.html", `<meta http-equiv="refresh" content="0; url=http://example.com/blog/fr" />`) } else { // Main language in root - assert.Equal("http://example.com/blog/sect/doc1/", frPerm) - assert.Equal("/blog/sect/doc1/", frRelPerm) + c.Assert(frPerm, qt.Equals, "http://example.com/blog/sect/doc1/") + c.Assert(frRelPerm, qt.Equals, "/blog/sect/doc1/") // should have redirect back to root b.AssertFileContent("public/fr/index.html", `<meta http-equiv="refresh" content="0; url=http://example.com/blog" />`) @@ -154,7 +153,7 @@ func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) { func TestMultiSitesWithTwoLanguages(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) b := newTestSitesBuilder(t).WithConfigFile("toml", ` defaultContentLanguage = "nn" @@ -179,23 +178,23 @@ p1 = "p1en" b.Build(BuildCfg{SkipRender: true}) sites := b.H.Sites - assert.Len(sites, 2) + c.Assert(len(sites), qt.Equals, 2) nnSite := sites[0] nnHome := nnSite.getPage(page.KindHome) - assert.Len(nnHome.AllTranslations(), 2) - assert.Len(nnHome.Translations(), 1) - assert.True(nnHome.IsTranslated()) + c.Assert(len(nnHome.AllTranslations()), qt.Equals, 2) + c.Assert(len(nnHome.Translations()), qt.Equals, 1) + c.Assert(nnHome.IsTranslated(), qt.Equals, true) enHome := sites[1].getPage(page.KindHome) p1, err := enHome.Param("p1") - assert.NoError(err) - assert.Equal("p1en", p1) + c.Assert(err, qt.IsNil) + c.Assert(p1, qt.Equals, "p1en") p1, err = nnHome.Param("p1") - assert.NoError(err) - assert.Equal("p1nn", p1) + c.Assert(err, qt.IsNil) + c.Assert(p1, qt.Equals, "p1nn") } func TestMultiSitesBuild(t *testing.T) { @@ -217,38 +216,38 @@ func TestMultiSitesBuild(t *testing.T) { } func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { - assert := require.New(t) + c := qt.New(t) b := newMultiSiteTestBuilder(t, configSuffix, configTemplate, nil) b.CreateSites() sites := b.H.Sites - assert.Equal(4, len(sites)) + c.Assert(len(sites), qt.Equals, 4) b.Build(BuildCfg{}) // Check site config for _, s := range sites { - require.True(t, s.Info.defaultContentLanguageInSubdir, s.Info.title) - require.NotNil(t, s.disabledKinds) + c.Assert(s.Info.defaultContentLanguageInSubdir, qt.Equals, true) + c.Assert(s.disabledKinds, qt.Not(qt.IsNil)) } gp1 := b.H.GetContentPage(filepath.FromSlash("content/sect/doc1.en.md")) - require.NotNil(t, gp1) - require.Equal(t, "doc1", gp1.Title()) + c.Assert(gp1, qt.Not(qt.IsNil)) + c.Assert(gp1.Title(), qt.Equals, "doc1") gp2 := b.H.GetContentPage(filepath.FromSlash("content/dummysect/notfound.md")) - require.Nil(t, gp2) + c.Assert(gp2, qt.IsNil) enSite := sites[0] enSiteHome := enSite.getPage(page.KindHome) - require.True(t, enSiteHome.IsTranslated()) + c.Assert(enSiteHome.IsTranslated(), qt.Equals, true) - require.Equal(t, "en", enSite.language.Lang) + c.Assert(enSite.language.Lang, qt.Equals, "en") //dumpPages(enSite.RegularPages()...) - assert.Equal(5, len(enSite.RegularPages())) - assert.Equal(32, len(enSite.AllPages())) + c.Assert(len(enSite.RegularPages()), qt.Equals, 5) + c.Assert(len(enSite.AllPages()), qt.Equals, 32) // Check 404s b.AssertFileContent("public/en/404.html", "404|en|404 Page not found") @@ -264,33 +263,33 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { doc2 := enSite.RegularPages()[1] doc3 := enSite.RegularPages()[2] - require.Equal(t, doc2.Prev(), doc3, "doc3 should follow doc2, in .PrevPage") + c.Assert(doc3, qt.Equals, doc2.Prev()) doc1en := enSite.RegularPages()[0] doc1fr := doc1en.Translations()[0] b.AssertFileContent("public/fr/sect/doc1/index.html", "Permalink: http://example.com/blog/fr/sect/doc1/") - require.Equal(t, doc1en.Translations()[0], doc1fr, "doc1-en should have doc1-fr as translation") - require.Equal(t, doc1fr.Translations()[0], doc1en, "doc1-fr should have doc1-en as translation") - require.Equal(t, "fr", doc1fr.Language().Lang) + c.Assert(doc1fr, qt.Equals, doc1en.Translations()[0]) + c.Assert(doc1en, qt.Equals, doc1fr.Translations()[0]) + c.Assert(doc1fr.Language().Lang, qt.Equals, "fr") doc4 := enSite.AllPages()[4] - require.Len(t, doc4.Translations(), 0, "found translations for doc4") + c.Assert(len(doc4.Translations()), qt.Equals, 0) // Taxonomies and their URLs - require.Len(t, enSite.Taxonomies, 1, "should have 1 taxonomy") + c.Assert(len(enSite.Taxonomies), qt.Equals, 1) tags := enSite.Taxonomies["tags"] - require.Len(t, tags, 2, "should have 2 different tags") - require.Equal(t, tags["tag1"][0].Page, doc1en, "first tag1 page should be doc1") + c.Assert(len(tags), qt.Equals, 2) + c.Assert(doc1en, qt.Equals, tags["tag1"][0].Page) frSite := sites[1] - require.Equal(t, "fr", frSite.language.Lang) - require.Len(t, frSite.RegularPages(), 4, "should have 3 pages") - require.Len(t, frSite.AllPages(), 32, "should have 32 total pages (including translations and nodes)") + c.Assert(frSite.language.Lang, qt.Equals, "fr") + c.Assert(len(frSite.RegularPages()), qt.Equals, 4) + c.Assert(len(frSite.AllPages()), qt.Equals, 32) for _, frenchPage := range frSite.RegularPages() { p := frenchPage - require.Equal(t, "fr", p.Language().Lang) + c.Assert(p.Language().Lang, qt.Equals, "fr") } // See https://github.com/gohugoio/hugo/issues/4285 @@ -302,10 +301,10 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { getPageDoc1EnBase := enSite.getPage(page.KindPage, "sect/doc1") getPageDoc1Fr := frSite.getPage(page.KindPage, filepath.ToSlash(doc1fr.File().Path())) getPageDoc1FrBase := frSite.getPage(page.KindPage, "sect/doc1") - require.Equal(t, doc1en, getPageDoc1En) - require.Equal(t, doc1fr, getPageDoc1Fr) - require.Equal(t, doc1en, getPageDoc1EnBase) - require.Equal(t, doc1fr, getPageDoc1FrBase) + c.Assert(getPageDoc1En, qt.Equals, doc1en) + c.Assert(getPageDoc1Fr, qt.Equals, doc1fr) + c.Assert(getPageDoc1EnBase, qt.Equals, doc1en) + c.Assert(getPageDoc1FrBase, qt.Equals, doc1fr) // Check redirect to main language, French b.AssertFileContent("public/index.html", "0; url=http://example.com/blog/fr") @@ -320,35 +319,35 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { // Check node translations homeEn := enSite.getPage(page.KindHome) - require.NotNil(t, homeEn) - require.Len(t, homeEn.Translations(), 3) - require.Equal(t, "fr", homeEn.Translations()[0].Language().Lang) - require.Equal(t, "nn", homeEn.Translations()[1].Language().Lang) - require.Equal(t, "På nynorsk", homeEn.Translations()[1].Title()) - require.Equal(t, "nb", homeEn.Translations()[2].Language().Lang) - require.Equal(t, "På bokmål", homeEn.Translations()[2].Title(), configSuffix) - require.Equal(t, "Bokmål", homeEn.Translations()[2].Language().LanguageName, configSuffix) + c.Assert(homeEn, qt.Not(qt.IsNil)) + c.Assert(len(homeEn.Translations()), qt.Equals, 3) + c.Assert(homeEn.Translations()[0].Language().Lang, qt.Equals, "fr") + c.Assert(homeEn.Translations()[1].Language().Lang, qt.Equals, "nn") + c.Assert(homeEn.Translations()[1].Title(), qt.Equals, "På nynorsk") + c.Assert(homeEn.Translations()[2].Language().Lang, qt.Equals, "nb") + c.Assert(homeEn.Translations()[2].Title(), qt.Equals, "På bokmål") + c.Assert(homeEn.Translations()[2].Language().LanguageName, qt.Equals, "Bokmål") sectFr := frSite.getPage(page.KindSection, "sect") - require.NotNil(t, sectFr) + c.Assert(sectFr, qt.Not(qt.IsNil)) - require.Equal(t, "fr", sectFr.Language().Lang) - require.Len(t, sectFr.Translations(), 1) - require.Equal(t, "en", sectFr.Translations()[0].Language().Lang) - require.Equal(t, "Sects", sectFr.Translations()[0].Title()) + c.Assert(sectFr.Language().Lang, qt.Equals, "fr") + c.Assert(len(sectFr.Translations()), qt.Equals, 1) + c.Assert(sectFr.Translations()[0].Language().Lang, qt.Equals, "en") + c.Assert(sectFr.Translations()[0].Title(), qt.Equals, "Sects") nnSite := sites[2] - require.Equal(t, "nn", nnSite.language.Lang) + c.Assert(nnSite.language.Lang, qt.Equals, "nn") taxNn := nnSite.getPage(page.KindTaxonomyTerm, "lag") - require.NotNil(t, taxNn) - require.Len(t, taxNn.Translations(), 1) - require.Equal(t, "nb", taxNn.Translations()[0].Language().Lang) + c.Assert(taxNn, qt.Not(qt.IsNil)) + c.Assert(len(taxNn.Translations()), qt.Equals, 1) + c.Assert(taxNn.Translations()[0].Language().Lang, qt.Equals, "nb") taxTermNn := nnSite.getPage(page.KindTaxonomy, "lag", "sogndal") - require.NotNil(t, taxTermNn) - require.Equal(t, taxTermNn, nnSite.getPage(page.KindTaxonomy, "LAG", "SOGNDAL")) - require.Len(t, taxTermNn.Translations(), 1) - require.Equal(t, "nb", taxTermNn.Translations()[0].Language().Lang) + c.Assert(taxTermNn, qt.Not(qt.IsNil)) + c.Assert(nnSite.getPage(page.KindTaxonomy, "LAG", "SOGNDAL"), qt.Equals, taxTermNn) + c.Assert(len(taxTermNn.Translations()), qt.Equals, 1) + c.Assert(taxTermNn.Translations()[0].Language().Lang, qt.Equals, "nb") // Check sitemap(s) b.AssertFileContent("public/sitemap.xml", @@ -360,54 +359,54 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { // Check taxonomies enTags := enSite.Taxonomies["tags"] frTags := frSite.Taxonomies["plaques"] - require.Len(t, enTags, 2, fmt.Sprintf("Tags in en: %v", enTags)) - require.Len(t, frTags, 2, fmt.Sprintf("Tags in fr: %v", frTags)) - require.NotNil(t, enTags["tag1"]) - require.NotNil(t, frTags["FRtag1"]) + c.Assert(len(enTags), qt.Equals, 2, qt.Commentf("Tags in en: %v", enTags)) + c.Assert(len(frTags), qt.Equals, 2, qt.Commentf("Tags in fr: %v", frTags)) + c.Assert(enTags["tag1"], qt.Not(qt.IsNil)) + c.Assert(frTags["FRtag1"], qt.Not(qt.IsNil)) b.AssertFileContent("public/fr/plaques/FRtag1/index.html", "FRtag1|Bonjour|http://example.com/blog/fr/plaques/FRtag1/") // Check Blackfriday config - require.True(t, strings.Contains(content(doc1fr), "«"), content(doc1fr)) - require.False(t, strings.Contains(content(doc1en), "«"), content(doc1en)) - require.True(t, strings.Contains(content(doc1en), "“"), content(doc1en)) + c.Assert(strings.Contains(content(doc1fr), "«"), qt.Equals, true) + c.Assert(strings.Contains(content(doc1en), "«"), qt.Equals, false) + c.Assert(strings.Contains(content(doc1en), "“"), qt.Equals, true) // en and nn have custom site menus - require.Len(t, frSite.Menus(), 0, "fr: "+configSuffix) - require.Len(t, enSite.Menus(), 1, "en: "+configSuffix) - require.Len(t, nnSite.Menus(), 1, "nn: "+configSuffix) + c.Assert(len(frSite.Menus()), qt.Equals, 0) + c.Assert(len(enSite.Menus()), qt.Equals, 1) + c.Assert(len(nnSite.Menus()), qt.Equals, 1) - require.Equal(t, "Home", enSite.Menus()["main"].ByName()[0].Name) - require.Equal(t, "Heim", nnSite.Menus()["main"].ByName()[0].Name) + c.Assert(enSite.Menus()["main"].ByName()[0].Name, qt.Equals, "Home") + c.Assert(nnSite.Menus()["main"].ByName()[0].Name, qt.Equals, "Heim") // Issue #3108 prevPage := enSite.RegularPages()[0].Prev() - require.NotNil(t, prevPage) - require.Equal(t, page.KindPage, prevPage.Kind()) + c.Assert(prevPage, qt.Not(qt.IsNil)) + c.Assert(prevPage.Kind(), qt.Equals, page.KindPage) for { if prevPage == nil { break } - require.Equal(t, page.KindPage, prevPage.Kind()) + c.Assert(prevPage.Kind(), qt.Equals, page.KindPage) prevPage = prevPage.Prev() } // Check bundles b.AssertFileContent("public/fr/bundles/b1/index.html", "RelPermalink: /blog/fr/bundles/b1/|") bundleFr := frSite.getPage(page.KindPage, "bundles/b1/index.md") - require.NotNil(t, bundleFr) - require.Equal(t, 1, len(bundleFr.Resources())) + c.Assert(bundleFr, qt.Not(qt.IsNil)) + c.Assert(len(bundleFr.Resources()), qt.Equals, 1) logoFr := bundleFr.Resources().GetMatch("logo*") - require.NotNil(t, logoFr) + c.Assert(logoFr, qt.Not(qt.IsNil)) b.AssertFileContent("public/fr/bundles/b1/index.html", "Resources: image/png: /blog/fr/bundles/b1/logo.png") b.AssertFileContent("public/fr/bundles/b1/logo.png", "PNG Data") bundleEn := enSite.getPage(page.KindPage, "bundles/b1/index.en.md") - require.NotNil(t, bundleEn) + c.Assert(bundleEn, qt.Not(qt.IsNil)) b.AssertFileContent("public/en/bundles/b1/index.html", "RelPermalink: /blog/en/bundles/b1/|") - require.Equal(t, 1, len(bundleEn.Resources())) + c.Assert(len(bundleEn.Resources()), qt.Equals, 1) logoEn := bundleEn.Resources().GetMatch("logo*") - require.NotNil(t, logoEn) + c.Assert(logoEn, qt.Not(qt.IsNil)) b.AssertFileContent("public/en/bundles/b1/index.html", "Resources: image/png: /blog/en/bundles/b1/logo.png") b.AssertFileContent("public/en/bundles/b1/logo.png", "PNG Data") @@ -420,7 +419,7 @@ func TestMultiSitesRebuild(t *testing.T) { defer leaktest.CheckTimeout(t, 10*time.Second)() } - assert := require.New(t) + c := qt.New(t) b := newMultiSiteTestDefaultBuilder(t).Running().CreateSites().Build(BuildCfg{}) @@ -432,8 +431,8 @@ func TestMultiSitesRebuild(t *testing.T) { enSite := sites[0] frSite := sites[1] - assert.Len(enSite.RegularPages(), 5) - assert.Len(frSite.RegularPages(), 4) + c.Assert(len(enSite.RegularPages()), qt.Equals, 5) + c.Assert(len(frSite.RegularPages()), qt.Equals, 4) // Verify translations b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Hello") @@ -444,8 +443,8 @@ func TestMultiSitesRebuild(t *testing.T) { b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello") homeEn := enSite.getPage(page.KindHome) - require.NotNil(t, homeEn) - assert.Len(homeEn.Translations(), 3) + c.Assert(homeEn, qt.Not(qt.IsNil)) + c.Assert(len(homeEn.Translations()), qt.Equals, 3) contentFs := b.H.Fs.Source @@ -467,7 +466,7 @@ func TestMultiSitesRebuild(t *testing.T) { }, []fsnotify.Event{{Name: filepath.FromSlash("content/sect/doc2.en.md"), Op: fsnotify.Remove}}, func(t *testing.T) { - assert.Len(enSite.RegularPages(), 4, "1 en removed") + c.Assert(len(enSite.RegularPages()), qt.Equals, 4, qt.Commentf("1 en removed")) }, }, @@ -483,15 +482,15 @@ func TestMultiSitesRebuild(t *testing.T) { {Name: filepath.FromSlash("content/new1.fr.md"), Op: fsnotify.Create}, }, func(t *testing.T) { - assert.Len(enSite.RegularPages(), 6) - assert.Len(enSite.AllPages(), 34) - assert.Len(frSite.RegularPages(), 5) - require.Equal(t, "new_fr_1", frSite.RegularPages()[3].Title()) - require.Equal(t, "new_en_2", enSite.RegularPages()[0].Title()) - require.Equal(t, "new_en_1", enSite.RegularPages()[1].Title()) + c.Assert(len(enSite.RegularPages()), qt.Equals, 6) + c.Assert(len(enSite.AllPages()), qt.Equals, 34) + c.Assert(len(frSite.RegularPages()), qt.Equals, 5) + c.Assert(frSite.RegularPages()[3].Title(), qt.Equals, "new_fr_1") + c.Assert(enSite.RegularPages()[0].Title(), qt.Equals, "new_en_2") + c.Assert(enSite.RegularPages()[1].Title(), qt.Equals, "new_en_1") rendered := readDestination(t, fs, "public/en/new1/index.html") - require.True(t, strings.Contains(rendered, "new_en_1"), rendered) + c.Assert(strings.Contains(rendered, "new_en_1"), qt.Equals, true) }, }, { @@ -503,9 +502,9 @@ func TestMultiSitesRebuild(t *testing.T) { }, []fsnotify.Event{{Name: filepath.FromSlash("content/sect/doc1.en.md"), Op: fsnotify.Write}}, func(t *testing.T) { - assert.Len(enSite.RegularPages(), 6) + c.Assert(len(enSite.RegularPages()), qt.Equals, 6) doc1 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html") - require.True(t, strings.Contains(doc1, "CHANGED"), doc1) + c.Assert(strings.Contains(doc1, "CHANGED"), qt.Equals, true) }, }, @@ -521,10 +520,10 @@ func TestMultiSitesRebuild(t *testing.T) { {Name: filepath.FromSlash("content/new1.en.md"), Op: fsnotify.Rename}, }, func(t *testing.T) { - assert.Len(enSite.RegularPages(), 6, "Rename") - require.Equal(t, "new_en_1", enSite.RegularPages()[1].Title()) + c.Assert(len(enSite.RegularPages()), qt.Equals, 6, qt.Commentf("Rename")) + c.Assert(enSite.RegularPages()[1].Title(), qt.Equals, "new_en_1") rendered := readDestination(t, fs, "public/en/new1renamed/index.html") - require.True(t, strings.Contains(rendered, "new_en_1"), rendered) + c.Assert(rendered, qt.Contains, "new_en_1") }}, { // Change a template @@ -536,11 +535,11 @@ func TestMultiSitesRebuild(t *testing.T) { }, []fsnotify.Event{{Name: filepath.FromSlash("layouts/_default/single.html"), Op: fsnotify.Write}}, func(t *testing.T) { - assert.Len(enSite.RegularPages(), 6) - assert.Len(enSite.AllPages(), 34) - assert.Len(frSite.RegularPages(), 5) + c.Assert(len(enSite.RegularPages()), qt.Equals, 6) + c.Assert(len(enSite.AllPages()), qt.Equals, 34) + c.Assert(len(frSite.RegularPages()), qt.Equals, 5) doc1 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html") - require.True(t, strings.Contains(doc1, "Template Changed"), doc1) + c.Assert(strings.Contains(doc1, "Template Changed"), qt.Equals, true) }, }, { @@ -553,18 +552,18 @@ func TestMultiSitesRebuild(t *testing.T) { }, []fsnotify.Event{{Name: filepath.FromSlash("i18n/fr.yaml"), Op: fsnotify.Write}}, func(t *testing.T) { - assert.Len(enSite.RegularPages(), 6) - assert.Len(enSite.AllPages(), 34) - assert.Len(frSite.RegularPages(), 5) + c.Assert(len(enSite.RegularPages()), qt.Equals, 6) + c.Assert(len(enSite.AllPages()), qt.Equals, 34) + c.Assert(len(frSite.RegularPages()), qt.Equals, 5) docEn := readDestination(t, fs, "public/en/sect/doc1-slug/index.html") - require.True(t, strings.Contains(docEn, "Hello"), "No Hello") + c.Assert(strings.Contains(docEn, "Hello"), qt.Equals, true) docFr := readDestination(t, fs, "public/fr/sect/doc1/index.html") - require.True(t, strings.Contains(docFr, "Salut"), "No Salut") + c.Assert(strings.Contains(docFr, "Salut"), qt.Equals, true) homeEn := enSite.getPage(page.KindHome) - require.NotNil(t, homeEn) - assert.Len(homeEn.Translations(), 3) - require.Equal(t, "fr", homeEn.Translations()[0].Language().Lang) + c.Assert(homeEn, qt.Not(qt.IsNil)) + c.Assert(len(homeEn.Translations()), qt.Equals, 3) + c.Assert(homeEn.Translations()[0].Language().Lang, qt.Equals, "fr") }, }, @@ -577,9 +576,9 @@ func TestMultiSitesRebuild(t *testing.T) { {Name: filepath.FromSlash("layouts/shortcodes/shortcode.html"), Op: fsnotify.Write}, }, func(t *testing.T) { - assert.Len(enSite.RegularPages(), 6) - assert.Len(enSite.AllPages(), 34) - assert.Len(frSite.RegularPages(), 5) + c.Assert(len(enSite.RegularPages()), qt.Equals, 6) + c.Assert(len(enSite.AllPages()), qt.Equals, 34) + c.Assert(len(frSite.RegularPages()), qt.Equals, 5) b.AssertFileContent("public/fr/sect/doc1/index.html", "Single", "Modified Shortcode: Salut") b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Modified Shortcode: Hello") }, @@ -781,24 +780,24 @@ categories: ["mycat"] } { t.Run(path, func(t *testing.T) { - assert := require.New(t) + c := qt.New(t) s1, _ := b.H.Sites[0].getPageNew(nil, path) s2, _ := b.H.Sites[1].getPageNew(nil, path) - assert.NotNil(s1) - assert.NotNil(s2) + c.Assert(s1, qt.Not(qt.IsNil)) + c.Assert(s2, qt.Not(qt.IsNil)) - assert.Equal(1, len(s1.Translations())) - assert.Equal(1, len(s2.Translations())) - assert.Equal(s2, s1.Translations()[0]) - assert.Equal(s1, s2.Translations()[0]) + c.Assert(len(s1.Translations()), qt.Equals, 1) + c.Assert(len(s2.Translations()), qt.Equals, 1) + c.Assert(s1.Translations()[0], qt.Equals, s2) + c.Assert(s2.Translations()[0], qt.Equals, s1) m1 := s1.Translations().MergeByLanguage(s2.Translations()) m2 := s2.Translations().MergeByLanguage(s1.Translations()) - assert.Equal(1, len(m1)) - assert.Equal(1, len(m2)) + c.Assert(len(m1), qt.Equals, 1) + c.Assert(len(m2), qt.Equals, 1) }) } diff --git a/hugolib/hugo_sites_multihost_test.go b/hugolib/hugo_sites_multihost_test.go index 999d94559..a15e8cd43 100644 --- a/hugolib/hugo_sites_multihost_test.go +++ b/hugolib/hugo_sites_multihost_test.go @@ -5,13 +5,13 @@ import ( "github.com/gohugoio/hugo/resources/page" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestMultihosts(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) var configTemplate = ` paginate = 1 @@ -58,9 +58,9 @@ languageName = "Nynorsk" s1 := b.H.Sites[0] s1h := s1.getPage(page.KindHome) - assert.True(s1h.IsTranslated()) - assert.Len(s1h.Translations(), 2) - assert.Equal("https://example.com/docs/", s1h.Permalink()) + c.Assert(s1h.IsTranslated(), qt.Equals, true) + c.Assert(len(s1h.Translations()), qt.Equals, 2) + c.Assert(s1h.Permalink(), qt.Equals, "https://example.com/docs/") // For “regular multilingual” we kept the aliases pages with url in front matter // as a literal value that we use as is. @@ -69,8 +69,8 @@ languageName = "Nynorsk" // // check url in front matter: pageWithURLInFrontMatter := s1.getPage(page.KindPage, "sect/doc3.en.md") - assert.NotNil(pageWithURLInFrontMatter) - assert.Equal("/docs/superbob/", pageWithURLInFrontMatter.RelPermalink()) + c.Assert(pageWithURLInFrontMatter, qt.Not(qt.IsNil)) + c.Assert(pageWithURLInFrontMatter.RelPermalink(), qt.Equals, "/docs/superbob/") b.AssertFileContent("public/en/superbob/index.html", "doc3|Hello|en") // check alias: @@ -80,7 +80,7 @@ languageName = "Nynorsk" s2 := b.H.Sites[1] s2h := s2.getPage(page.KindHome) - assert.Equal("https://example.fr/", s2h.Permalink()) + c.Assert(s2h.Permalink(), qt.Equals, "https://example.fr/") b.AssertFileContent("public/fr/index.html", "French Home Page", "String Resource: /docs/text/pipes.txt") b.AssertFileContent("public/fr/text/pipes.txt", "Hugo Pipes") @@ -96,17 +96,17 @@ languageName = "Nynorsk" // Check bundles bundleEn := s1.getPage(page.KindPage, "bundles/b1/index.en.md") - require.NotNil(t, bundleEn) - require.Equal(t, "/docs/bundles/b1/", bundleEn.RelPermalink()) - require.Equal(t, 1, len(bundleEn.Resources())) + c.Assert(bundleEn, qt.Not(qt.IsNil)) + c.Assert(bundleEn.RelPermalink(), qt.Equals, "/docs/bundles/b1/") + c.Assert(len(bundleEn.Resources()), qt.Equals, 1) b.AssertFileContent("public/en/bundles/b1/logo.png", "PNG Data") b.AssertFileContent("public/en/bundles/b1/index.html", " image/png: /docs/bundles/b1/logo.png") bundleFr := s2.getPage(page.KindPage, "bundles/b1/index.md") - require.NotNil(t, bundleFr) - require.Equal(t, "/bundles/b1/", bundleFr.RelPermalink()) - require.Equal(t, 1, len(bundleFr.Resources())) + c.Assert(bundleFr, qt.Not(qt.IsNil)) + c.Assert(bundleFr.RelPermalink(), qt.Equals, "/bundles/b1/") + c.Assert(len(bundleFr.Resources()), qt.Equals, 1) b.AssertFileContent("public/fr/bundles/b1/logo.png", "PNG Data") b.AssertFileContent("public/fr/bundles/b1/index.html", " image/png: /bundles/b1/logo.png") diff --git a/hugolib/hugo_smoke_test.go b/hugolib/hugo_smoke_test.go index a6a951fa7..539e79729 100644 --- a/hugolib/hugo_smoke_test.go +++ b/hugolib/hugo_smoke_test.go @@ -18,13 +18,13 @@ import ( "strings" "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestSmoke(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) const configFile = ` baseURL = "https://example.com" @@ -203,8 +203,8 @@ Some **Markdown** in JSON shortcode. // Check RSS rssHome := b.FileContent("public/index.xml") - assert.Contains(rssHome, `<atom:link href="https://example.com/index.xml" rel="self" type="application/rss+xml" />`) - assert.Equal(3, strings.Count(rssHome, "<item>")) // rssLimit = 3 + c.Assert(rssHome, qt.Contains, `<atom:link href="https://example.com/index.xml" rel="self" type="application/rss+xml" />`) + c.Assert(strings.Count(rssHome, "<item>"), qt.Equals, 3) // rssLimit = 3 // .Render should use template/content from the current output format // even if that output format isn't configured for that page. diff --git a/hugolib/image_test.go b/hugolib/image_test.go index 9d92d7fd4..d6cabebd2 100644 --- a/hugolib/image_test.go +++ b/hugolib/image_test.go @@ -21,18 +21,18 @@ import ( "github.com/gohugoio/hugo/htesting" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/hugofs" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) // We have many tests for the different resize operations etc. in the resource package, // this is an integration test. func TestImageResize(t *testing.T) { - assert := require.New(t) + c := qt.New(t) // Make this a real as possible. workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "image-resize") - assert.NoError(err) + c.Assert(err, qt.IsNil) defer clean() newBuilder := func() *sitesBuilder { @@ -74,22 +74,22 @@ title: "My bundle" imageDir := filepath.Join(workDir, "assets", "images") bundleDir := filepath.Join(workDir, "content", "mybundle") - assert.NoError(os.MkdirAll(imageDir, 0777)) - assert.NoError(os.MkdirAll(bundleDir, 0777)) + c.Assert(os.MkdirAll(imageDir, 0777), qt.IsNil) + c.Assert(os.MkdirAll(bundleDir, 0777), qt.IsNil) src, err := os.Open("testdata/sunset.jpg") - assert.NoError(err) + c.Assert(err, qt.IsNil) out, err := os.Create(filepath.Join(imageDir, "sunset.jpg")) - assert.NoError(err) + c.Assert(err, qt.IsNil) _, err = io.Copy(out, src) - assert.NoError(err) + c.Assert(err, qt.IsNil) out.Close() src.Seek(0, 0) out, err = os.Create(filepath.Join(bundleDir, "sunset.jpg")) - assert.NoError(err) + c.Assert(err, qt.IsNil) _, err = io.Copy(out, src) - assert.NoError(err) + c.Assert(err, qt.IsNil) out.Close() src.Close() diff --git a/hugolib/language_content_dir_test.go b/hugolib/language_content_dir_test.go index b0f443fca..5406422dd 100644 --- a/hugolib/language_content_dir_test.go +++ b/hugolib/language_content_dir_test.go @@ -19,9 +19,11 @@ import ( "path/filepath" "testing" + "github.com/spf13/cast" + "github.com/gohugoio/hugo/resources/page" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) /* @@ -42,7 +44,7 @@ import ( func TestLanguageContentRoot(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) config := ` baseURL = "https://example.org/" @@ -215,9 +217,9 @@ Content. //dumpPages(b.H.Sites[1].RegularPages()...) - assert.NoError(err) + c.Assert(err, qt.IsNil) - assert.Equal(3, len(b.H.Sites)) + c.Assert(len(b.H.Sites), qt.Equals, 3) enSite := b.H.Sites[0] nnSite := b.H.Sites[1] @@ -228,25 +230,26 @@ Content. //dumpPages(nnSite.RegularPages()...) - assert.Equal(12, len(nnSite.RegularPages())) - assert.Equal(13, len(enSite.RegularPages())) + c.Assert(len(nnSite.RegularPages()), qt.Equals, 12) + c.Assert(len(enSite.RegularPages()), qt.Equals, 13) - assert.Equal(10, len(svSite.RegularPages())) + c.Assert(len(svSite.RegularPages()), qt.Equals, 10) svP2, err := svSite.getPageNew(nil, "/sect/page2.md") - assert.NoError(err) + c.Assert(err, qt.IsNil) nnP2, err := nnSite.getPageNew(nil, "/sect/page2.md") - assert.NoError(err) + c.Assert(err, qt.IsNil) enP2, err := enSite.getPageNew(nil, "/sect/page2.md") - assert.NoError(err) - assert.Equal("en", enP2.Language().Lang) - assert.Equal("sv", svP2.Language().Lang) - assert.Equal("nn", nnP2.Language().Lang) + c.Assert(err, qt.IsNil) + c.Assert(enP2.Language().Lang, qt.Equals, "en") + c.Assert(svP2.Language().Lang, qt.Equals, "sv") + c.Assert(nnP2.Language().Lang, qt.Equals, "nn") content, _ := nnP2.Content() - assert.Contains(content, "SVP3-REF: https://example.org/sv/sect/p-sv-3/") - assert.Contains(content, "SVP3-RELREF: /sv/sect/p-sv-3/") + contentStr := cast.ToString(content) + c.Assert(contentStr, qt.Contains, "SVP3-REF: https://example.org/sv/sect/p-sv-3/") + c.Assert(contentStr, qt.Contains, "SVP3-RELREF: /sv/sect/p-sv-3/") // Test RelRef with and without language indicator. nn3RefArgs := map[string]interface{}{ @@ -256,38 +259,34 @@ Content. nnP3RelRef, err := svP2.RelRef( nn3RefArgs, ) - assert.NoError(err) - assert.Equal("/nn/sect/p-nn-3/", nnP3RelRef) + c.Assert(err, qt.IsNil) + c.Assert(nnP3RelRef, qt.Equals, "/nn/sect/p-nn-3/") nnP3Ref, err := svP2.Ref( nn3RefArgs, ) - assert.NoError(err) - assert.Equal("https://example.org/nn/sect/p-nn-3/", nnP3Ref) + c.Assert(err, qt.IsNil) + c.Assert(nnP3Ref, qt.Equals, "https://example.org/nn/sect/p-nn-3/") for i, p := range enSite.RegularPages() { j := i + 1 - msg := fmt.Sprintf("Test %d", j) - assert.Equal("en", p.Language().Lang, msg) - assert.Equal("sect", p.Section()) + c.Assert(p.Language().Lang, qt.Equals, "en") + c.Assert(p.Section(), qt.Equals, "sect") if j < 9 { if j%4 == 0 { - assert.Contains(p.Title(), fmt.Sprintf("p-sv-%d.en", i+1), msg) } else { - assert.Contains(p.Title(), "p-en", msg) + c.Assert(p.Title(), qt.Contains, "p-en") } } } - for i, p := range nnSite.RegularPages() { - msg := fmt.Sprintf("Test %d", i+1) - assert.Equal("nn", p.Language().Lang, msg) - assert.Contains(p.Title(), "nn", msg) + for _, p := range nnSite.RegularPages() { + c.Assert(p.Language().Lang, qt.Equals, "nn") + c.Assert(p.Title(), qt.Contains, "nn") } - for i, p := range svSite.RegularPages() { - msg := fmt.Sprintf("Test %d", i+1) - assert.Equal("sv", p.Language().Lang, msg) - assert.Contains(p.Title(), "sv", msg) + for _, p := range svSite.RegularPages() { + c.Assert(p.Language().Lang, qt.Equals, "sv") + c.Assert(p.Title(), qt.Contains, "sv") } // Check bundles @@ -295,12 +294,12 @@ Content. bundleNn := nnSite.RegularPages()[len(nnSite.RegularPages())-1] bundleSv := svSite.RegularPages()[len(svSite.RegularPages())-1] - assert.Equal("/en/sect/mybundle/", bundleEn.RelPermalink()) - assert.Equal("/sv/sect/mybundle/", bundleSv.RelPermalink()) + c.Assert(bundleEn.RelPermalink(), qt.Equals, "/en/sect/mybundle/") + c.Assert(bundleSv.RelPermalink(), qt.Equals, "/sv/sect/mybundle/") - assert.Equal(4, len(bundleNn.Resources())) - assert.Equal(4, len(bundleSv.Resources())) - assert.Equal(4, len(bundleEn.Resources())) + c.Assert(len(bundleNn.Resources()), qt.Equals, 4) + c.Assert(len(bundleSv.Resources()), qt.Equals, 4) + c.Assert(len(bundleEn.Resources()), qt.Equals, 4) b.AssertFileContent("/my/project/public/en/sect/mybundle/index.html", "image/png: /en/sect/mybundle/logo.png") b.AssertFileContent("/my/project/public/nn/sect/mybundle/index.html", "image/png: /nn/sect/mybundle/logo.png") @@ -314,9 +313,9 @@ Content. b.AssertFileContent("/my/project/public/nn/sect/mybundle/logo.png", "PNG Data") nnSect := nnSite.getPage(page.KindSection, "sect") - assert.NotNil(nnSect) - assert.Equal(12, len(nnSect.Pages())) + c.Assert(nnSect, qt.Not(qt.IsNil)) + c.Assert(len(nnSect.Pages()), qt.Equals, 12) nnHome, _ := nnSite.Info.Home() - assert.Equal("/nn/", nnHome.RelPermalink()) + c.Assert(nnHome.RelPermalink(), qt.Equals, "/nn/") } diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index 0c366cafb..6fa31b4ee 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -18,7 +18,7 @@ import ( "fmt" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) const ( @@ -77,12 +77,12 @@ Menu Main: {{ partial "menu.html" (dict "page" . "menu" "main") }}`, s := h.Sites[0] - require.Len(t, s.Menus(), 2) + b.Assert(len(s.Menus()), qt.Equals, 2) p1 := s.RegularPages()[0].Menus() // There is only one menu in the page, but it is "member of" 2 - require.Len(t, p1, 1) + b.Assert(len(p1), qt.Equals, 1) b.AssertFileContent("public/sect1/p1/index.html", "Single", "Menu Sect: "+ diff --git a/hugolib/page_permalink_test.go b/hugolib/page_permalink_test.go index ffbb50cd5..9081ea898 100644 --- a/hugolib/page_permalink_test.go +++ b/hugolib/page_permalink_test.go @@ -19,7 +19,7 @@ import ( "path/filepath" "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" ) @@ -66,6 +66,7 @@ func TestPermalink(t *testing.T) { test := test t.Run(fmt.Sprintf("%s-%d", test.file, i), func(t *testing.T) { t.Parallel() + c := qt.New(t) cfg, fs := newTestCfg() cfg.Set("uglyURLs", test.uglyURLs) @@ -84,7 +85,7 @@ Content writeSource(t, fs, filepath.Join("content", filepath.FromSlash(test.file)), pageContent) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.Len(t, s.RegularPages(), 1) + c.Assert(len(s.RegularPages()), qt.Equals, 1) p := s.RegularPages()[0] diff --git a/hugolib/page_test.go b/hugolib/page_test.go index bb34ccfb8..6cf03b895 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -34,10 +34,9 @@ import ( "github.com/spf13/afero" "github.com/spf13/viper" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/helpers" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const ( @@ -306,7 +305,6 @@ func checkPageContent(t *testing.T, page page.Page, expected string, msg ...inte a := normalizeContent(expected) b := normalizeContent(content(page)) if a != b { - t.Log(stackTrace()) t.Fatalf("Page content is:\n%q\nExpected:\n%q (%q)", b, a, msg) } } @@ -422,15 +420,15 @@ func testAllMarkdownEnginesForPages(t *testing.T, s := b.H.Sites[0] - require.Len(t, s.RegularPages(), len(pageSources)) + b.Assert(len(s.RegularPages()), qt.Equals, len(pageSources)) assertFunc(t, e.ext, s.RegularPages()) home, err := s.Info.Home() - require.NoError(t, err) - require.NotNil(t, home) - require.Equal(t, homePath, home.File().Path()) - require.Contains(t, content(home), "Home Page Content") + b.Assert(err, qt.IsNil) + b.Assert(home, qt.Not(qt.IsNil)) + b.Assert(home.File().Path(), qt.Equals, homePath) + b.Assert(content(home), qt.Contains, "Home Page Content") } @@ -440,12 +438,13 @@ func testAllMarkdownEnginesForPages(t *testing.T, func TestPageWithDelimiterForMarkdownThatCrossesBorder(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() + c := qt.New(t) writeSource(t, fs, filepath.Join("content", "simple.md"), simplePageWithSummaryDelimiterAndMarkdownThatCrossesBorder) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.Len(t, s.RegularPages(), 1) + c.Assert(len(s.RegularPages()), qt.Equals, 1) p := s.RegularPages()[0] @@ -454,15 +453,14 @@ func TestPageWithDelimiterForMarkdownThatCrossesBorder(t *testing.T) { t.Fatalf("Got summary:\n%q", p.Summary()) } - c := content(p) - if c != "<p>The <a href=\"http://gohugo.io/\">best static site generator</a>.<sup class=\"footnote-ref\" id=\"fnref:1\"><a href=\"#fn:1\">1</a></sup></p>\n\n<div class=\"footnotes\">\n\n<hr />\n\n<ol>\n<li id=\"fn:1\">Many people say so.\n <a class=\"footnote-return\" href=\"#fnref:1\"><sup>[return]</sup></a></li>\n</ol>\n</div>" { - t.Fatalf("Got content:\n%q", c) + cnt := content(p) + if cnt != "<p>The <a href=\"http://gohugo.io/\">best static site generator</a>.<sup class=\"footnote-ref\" id=\"fnref:1\"><a href=\"#fn:1\">1</a></sup></p>\n\n<div class=\"footnotes\">\n\n<hr />\n\n<ol>\n<li id=\"fn:1\">Many people say so.\n <a class=\"footnote-return\" href=\"#fnref:1\"><sup>[return]</sup></a></li>\n</ol>\n</div>" { + t.Fatalf("Got content:\n%q", cnt) } } func TestPageDatesAllKinds(t *testing.T) { t.Parallel() - assert := assert.New(t) pageContent := ` --- @@ -479,11 +477,11 @@ categories: ["cool stuff"] b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) + b.Assert(len(b.H.Sites), qt.Equals, 1) s := b.H.Sites[0] checkDate := func(t time.Time, msg string) { - assert.Equal(2017, t.Year(), msg) + b.Assert(t.Year(), qt.Equals, 2017) } checkDated := func(d resource.Dated, msg string) { @@ -499,7 +497,6 @@ categories: ["cool stuff"] func TestPageDatesSections(t *testing.T) { t.Parallel() - assert := assert.New(t) b := newTestSitesBuilder(t) b.WithSimpleConfigFile().WithContent("no-index/page.md", ` @@ -524,23 +521,24 @@ date: 2018-01-15 b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) + b.Assert(len(b.H.Sites), qt.Equals, 1) s := b.H.Sites[0] - assert.Equal(2017, s.getPage("/").Date().Year()) - assert.Equal(2017, s.getPage("/no-index").Date().Year()) - assert.True(s.getPage("/with-index-no-date").Date().IsZero()) - assert.Equal(2018, s.getPage("/with-index-date").Date().Year()) + b.Assert(s.getPage("/").Date().Year(), qt.Equals, 2017) + b.Assert(s.getPage("/no-index").Date().Year(), qt.Equals, 2017) + b.Assert(s.getPage("/with-index-no-date").Date().IsZero(), qt.Equals, true) + b.Assert(s.getPage("/with-index-date").Date().Year(), qt.Equals, 2018) } func TestCreateNewPage(t *testing.T) { t.Parallel() + c := qt.New(t) assertFunc := func(t *testing.T, ext string, pages page.Pages) { p := pages[0] // issue #2290: Path is relative to the content dir and will continue to be so. - require.Equal(t, filepath.FromSlash(fmt.Sprintf("p0.%s", ext)), p.File().Path()) - assert.False(t, p.IsHome()) + c.Assert(p.File().Path(), qt.Equals, fmt.Sprintf("p0.%s", ext)) + c.Assert(p.IsHome(), qt.Equals, false) checkPageTitle(t, p, "Simple") checkPageContent(t, p, normalizeExpected(ext, "<p>Simple Page</p>\n")) checkPageSummary(t, p, "Simple Page") @@ -602,7 +600,7 @@ func TestPageWithSummaryParameter(t *testing.T) { // Issue #3854 // Also see https://github.com/gohugoio/hugo/issues/3977 func TestPageWithDateFields(t *testing.T) { - assert := require.New(t) + c := qt.New(t) pageWithDate := `--- title: P%d weight: %d @@ -620,9 +618,9 @@ Simple Page With Some Date` t.Parallel() assertFunc := func(t *testing.T, ext string, pages page.Pages) { - assert.True(len(pages) > 0) + c.Assert(len(pages) > 0, qt.Equals, true) for _, p := range pages { - assert.True(hasDate(p)) + c.Assert(hasDate(p), qt.Equals, true) } } @@ -640,6 +638,7 @@ Simple Page With Some Date` func TestPageRawContent(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() + c := qt.New(t) writeSource(t, fs, filepath.Join("content", "raw.md"), `--- title: Raw @@ -650,10 +649,10 @@ title: Raw s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.Len(t, s.RegularPages(), 1) + c.Assert(len(s.RegularPages()), qt.Equals, 1) p := s.RegularPages()[0] - require.Equal(t, p.RawContent(), "**Raw**") + c.Assert("**Raw**", qt.Equals, p.RawContent()) } @@ -687,12 +686,13 @@ func TestPageWithEmbeddedScriptTag(t *testing.T) { func TestPageWithAdditionalExtension(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() + c := qt.New(t) writeSource(t, fs, filepath.Join("content", "simple.md"), simplePageWithAdditionalExtension) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.Len(t, s.RegularPages(), 1) + c.Assert(len(s.RegularPages()), qt.Equals, 1) p := s.RegularPages()[0] @@ -702,12 +702,13 @@ func TestPageWithAdditionalExtension(t *testing.T) { func TestTableOfContents(t *testing.T) { cfg, fs := newTestCfg() + c := qt.New(t) writeSource(t, fs, filepath.Join("content", "tocpage.md"), pageWithToC) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.Len(t, s.RegularPages(), 1) + c.Assert(len(s.RegularPages()), qt.Equals, 1) p := s.RegularPages()[0] @@ -733,9 +734,11 @@ func TestPageWithMoreTag(t *testing.T) { func TestSummaryWithHTMLTagsOnNextLine(t *testing.T) { assertFunc := func(t *testing.T, ext string, pages page.Pages) { + c := qt.New(t) p := pages[0] - require.Contains(t, p.Summary(), "Happy new year everyone!") - require.NotContains(t, p.Summary(), "User interface") + s := string(p.Summary()) + c.Assert(s, qt.Contains, "Happy new year everyone!") + c.Assert(s, qt.Not(qt.Contains), "User interface") } testAllMarkdownEnginesForPages(t, assertFunc, nil, `--- @@ -755,12 +758,13 @@ Here is the last report for commits in the year 2016. It covers hrev50718-hrev50 func TestPageWithDate(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() + c := qt.New(t) writeSource(t, fs, filepath.Join("content", "simple.md"), simplePageRFC3339Date) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.Len(t, s.RegularPages(), 1) + c.Assert(len(s.RegularPages()), qt.Equals, 1) p := s.RegularPages()[0] d, _ := time.Parse(time.RFC3339, "2013-05-17T16:59:30Z") @@ -769,7 +773,7 @@ func TestPageWithDate(t *testing.T) { } func TestPageWithLastmodFromGitInfo(t *testing.T) { - assrt := require.New(t) + c := qt.New(t) // We need to use the OS fs for this. cfg := viper.New() @@ -777,7 +781,7 @@ func TestPageWithLastmodFromGitInfo(t *testing.T) { fs.Destination = &afero.MemMapFs{} wd, err := os.Getwd() - assrt.NoError(err) + c.Assert(err, qt.IsNil) cfg.Set("frontmatter", map[string]interface{}{ "lastmod": []string{":git", "lastmod"}, @@ -807,19 +811,19 @@ func TestPageWithLastmodFromGitInfo(t *testing.T) { b.Build(BuildCfg{SkipRender: true}) h := b.H - assrt.Len(h.Sites, 2) + c.Assert(len(h.Sites), qt.Equals, 2) enSite := h.Sites[0] - assrt.Len(enSite.RegularPages(), 1) + c.Assert(len(enSite.RegularPages()), qt.Equals, 1) // 2018-03-11 is the Git author date for testsite/content/first-post.md - assrt.Equal("2018-03-11", enSite.RegularPages()[0].Lastmod().Format("2006-01-02")) + c.Assert(enSite.RegularPages()[0].Lastmod().Format("2006-01-02"), qt.Equals, "2018-03-11") nnSite := h.Sites[1] - assrt.Len(nnSite.RegularPages(), 1) + c.Assert(len(nnSite.RegularPages()), qt.Equals, 1) // 2018-08-11 is the Git author date for testsite/content_nn/first-post.md - assrt.Equal("2018-08-11", nnSite.RegularPages()[0].Lastmod().Format("2006-01-02")) + c.Assert(nnSite.RegularPages()[0].Lastmod().Format("2006-01-02"), qt.Equals, "2018-08-11") } @@ -828,7 +832,7 @@ func TestPageWithFrontMatterConfig(t *testing.T) { dateHandler := dateHandler t.Run(fmt.Sprintf("dateHandler=%q", dateHandler), func(t *testing.T) { t.Parallel() - assrt := require.New(t) + c := qt.New(t) cfg, fs := newTestCfg() pageTemplate := ` @@ -852,36 +856,36 @@ Content writeSource(t, fs, c2, fmt.Sprintf(pageTemplate, 2, "slug: aslug")) c1fi, err := fs.Source.Stat(c1) - assrt.NoError(err) + c.Assert(err, qt.IsNil) c2fi, err := fs.Source.Stat(c2) - assrt.NoError(err) + c.Assert(err, qt.IsNil) b := newTestSitesBuilderFromDepsCfg(t, deps.DepsCfg{Fs: fs, Cfg: cfg}).WithNothingAdded() b.Build(BuildCfg{SkipRender: true}) s := b.H.Sites[0] - assrt.Len(s.RegularPages(), 2) + c.Assert(len(s.RegularPages()), qt.Equals, 2) noSlug := s.RegularPages()[0] slug := s.RegularPages()[1] - assrt.Equal(28, noSlug.Lastmod().Day()) + c.Assert(noSlug.Lastmod().Day(), qt.Equals, 28) switch strings.ToLower(dateHandler) { case ":filename": - assrt.False(noSlug.Date().IsZero()) - assrt.False(slug.Date().IsZero()) - assrt.Equal(2012, noSlug.Date().Year()) - assrt.Equal(2012, slug.Date().Year()) - assrt.Equal("noslug", noSlug.Slug()) - assrt.Equal("aslug", slug.Slug()) + c.Assert(noSlug.Date().IsZero(), qt.Equals, false) + c.Assert(slug.Date().IsZero(), qt.Equals, false) + c.Assert(noSlug.Date().Year(), qt.Equals, 2012) + c.Assert(slug.Date().Year(), qt.Equals, 2012) + c.Assert(noSlug.Slug(), qt.Equals, "noslug") + c.Assert(slug.Slug(), qt.Equals, "aslug") case ":filemodtime": - assrt.Equal(c1fi.ModTime().Year(), noSlug.Date().Year()) - assrt.Equal(c2fi.ModTime().Year(), slug.Date().Year()) + c.Assert(noSlug.Date().Year(), qt.Equals, c1fi.ModTime().Year()) + c.Assert(slug.Date().Year(), qt.Equals, c2fi.ModTime().Year()) fallthrough default: - assrt.Equal("", noSlug.Slug()) - assrt.Equal("aslug", slug.Slug()) + c.Assert(noSlug.Slug(), qt.Equals, "") + c.Assert(slug.Slug(), qt.Equals, "aslug") } }) @@ -978,6 +982,7 @@ func TestWordCount(t *testing.T) { func TestPagePaths(t *testing.T) { t.Parallel() + c := qt.New(t) siteParmalinksSetting := map[string]string{ "post": ":year/:month/:day/:title/", @@ -1009,14 +1014,14 @@ func TestPagePaths(t *testing.T) { writeSource(t, fs, filepath.Join("content", filepath.FromSlash(test.path)), test.content) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.Len(t, s.RegularPages(), 1) + c.Assert(len(s.RegularPages()), qt.Equals, 1) } } func TestTranslationKey(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) cfg, fs := newTestCfg() writeSource(t, fs, filepath.Join("content", filepath.FromSlash("sect/simple.no.md")), "---\ntitle: \"A1\"\ntranslationKey: \"k1\"\n---\nContent\n") @@ -1024,20 +1029,21 @@ func TestTranslationKey(t *testing.T) { s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.Len(t, s.RegularPages(), 2) + c.Assert(len(s.RegularPages()), qt.Equals, 2) home, _ := s.Info.Home() - assert.NotNil(home) - assert.Equal("home", home.TranslationKey()) - assert.Equal("page/k1", s.RegularPages()[0].TranslationKey()) + c.Assert(home, qt.Not(qt.IsNil)) + c.Assert(home.TranslationKey(), qt.Equals, "home") + c.Assert(s.RegularPages()[0].TranslationKey(), qt.Equals, "page/k1") p2 := s.RegularPages()[1] - assert.Equal("page/sect/simple", p2.TranslationKey()) + c.Assert(p2.TranslationKey(), qt.Equals, "page/sect/simple") } func TestChompBOM(t *testing.T) { t.Parallel() + c := qt.New(t) const utf8BOM = "\xef\xbb\xbf" cfg, fs := newTestCfg() @@ -1046,7 +1052,7 @@ func TestChompBOM(t *testing.T) { s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.Len(t, s.RegularPages(), 1) + c.Assert(len(s.RegularPages()), qt.Equals, 1) p := s.RegularPages()[0] @@ -1340,7 +1346,8 @@ func TestPathIssues(t *testing.T) { t.Run(fmt.Sprintf("disablePathToLower=%t,uglyURLs=%t", disablePathToLower, uglyURLs), func(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() - th := testHelper{cfg, fs, t} + th := newTestHelper(cfg, fs, t) + c := qt.New(t) cfg.Set("permalinks", map[string]string{ "post": ":section/:title", @@ -1376,7 +1383,7 @@ tags: s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) - require.Len(t, s.RegularPages(), 4) + c.Assert(len(s.RegularPages()), qt.Equals, 4) pathFunc := func(s string) string { if uglyURLs { @@ -1409,9 +1416,9 @@ tags: p := s.RegularPages()[0] if uglyURLs { - require.Equal(t, "/post/test0.dot.html", p.RelPermalink()) + c.Assert(p.RelPermalink(), qt.Equals, "/post/test0.dot.html") } else { - require.Equal(t, "/post/test0.dot/", p.RelPermalink()) + c.Assert(p.RelPermalink(), qt.Equals, "/post/test0.dot/") } }) @@ -1423,7 +1430,7 @@ tags: func TestWordCountAndSimilarVsSummary(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) single := []string{"_default/single.html", ` WordCount: {{ .WordCount }} @@ -1502,8 +1509,8 @@ Summary: In Chinese, 好 means good. b.CreateSites().Build(BuildCfg{}) - assert.Equal(1, len(b.H.Sites)) - require.Len(t, b.H.Sites[0].RegularPages(), 6) + c.Assert(len(b.H.Sites), qt.Equals, 1) + c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 6) b.AssertFileContent("public/p1/index.html", "WordCount: 510\nFuzzyWordCount: 600\nReadingTime: 3\nLen Plain: 2550\nLen PlainWords: 510\nTruncated: false\nLen Summary: 2549\nLen Content: 2557") diff --git a/hugolib/page_unwrap_test.go b/hugolib/page_unwrap_test.go index 23747dce8..20888166a 100644 --- a/hugolib/page_unwrap_test.go +++ b/hugolib/page_unwrap_test.go @@ -16,16 +16,16 @@ package hugolib import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/resources/page" - "github.com/stretchr/testify/require" ) func TestUnwrapPage(t *testing.T) { - assert := require.New(t) + c := qt.New(t) p := &pageState{} - assert.Equal(p, mustUnwrap(newPageForShortcode(p))) + c.Assert(mustUnwrap(newPageForShortcode(p)), qt.Equals, p) } func mustUnwrap(v interface{}) page.Page { diff --git a/hugolib/pagebundler_test.go b/hugolib/pagebundler_test.go index 10cd5a27e..a12dd713e 100644 --- a/hugolib/pagebundler_test.go +++ b/hugolib/pagebundler_test.go @@ -38,7 +38,7 @@ import ( "github.com/gohugoio/hugo/deps" "github.com/spf13/viper" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestPageBundlerSiteRegular(t *testing.T) { @@ -63,7 +63,7 @@ func TestPageBundlerSiteRegular(t *testing.T) { if canonify { relURLBase = "" } - assert := require.New(t) + c := qt.New(t) fs, cfg := newTestBundleSources(t) cfg.Set("baseURL", baseURL) cfg.Set("canonifyURLs", canonify) @@ -98,16 +98,16 @@ func TestPageBundlerSiteRegular(t *testing.T) { s := b.H.Sites[0] - assert.Len(s.RegularPages(), 8) + c.Assert(len(s.RegularPages()), qt.Equals, 8) singlePage := s.getPage(page.KindPage, "a/1.md") - assert.Equal("", singlePage.BundleType()) + c.Assert(singlePage.BundleType(), qt.Equals, "") - assert.NotNil(singlePage) - assert.Equal(singlePage, s.getPage("page", "a/1")) - assert.Equal(singlePage, s.getPage("page", "1")) + c.Assert(singlePage, qt.Not(qt.IsNil)) + c.Assert(s.getPage("page", "a/1"), qt.Equals, singlePage) + c.Assert(s.getPage("page", "1"), qt.Equals, singlePage) - assert.Contains(content(singlePage), "TheContent") + c.Assert(content(singlePage), qt.Contains, "TheContent") relFilename := func(basePath, outBase string) (string, string) { rel := basePath @@ -147,53 +147,53 @@ func TestPageBundlerSiteRegular(t *testing.T) { b.AssertFileContent(filepath.FromSlash("/work/public/assets/pic1.png"), "content") leafBundle1 := s.getPage(page.KindPage, "b/my-bundle/index.md") - assert.NotNil(leafBundle1) - assert.Equal("leaf", leafBundle1.BundleType()) - assert.Equal("b", leafBundle1.Section()) + c.Assert(leafBundle1, qt.Not(qt.IsNil)) + c.Assert(leafBundle1.BundleType(), qt.Equals, "leaf") + c.Assert(leafBundle1.Section(), qt.Equals, "b") sectionB := s.getPage(page.KindSection, "b") - assert.NotNil(sectionB) + c.Assert(sectionB, qt.Not(qt.IsNil)) home, _ := s.Info.Home() - assert.Equal("branch", home.BundleType()) + c.Assert(home.BundleType(), qt.Equals, "branch") // This is a root bundle and should live in the "home section" // See https://github.com/gohugoio/hugo/issues/4332 rootBundle := s.getPage(page.KindPage, "root") - assert.NotNil(rootBundle) - assert.True(rootBundle.Parent().IsHome()) + c.Assert(rootBundle, qt.Not(qt.IsNil)) + c.Assert(rootBundle.Parent().IsHome(), qt.Equals, true) if !ugly { b.AssertFileContent(filepath.FromSlash("/work/public/root/index.html"), "Single RelPermalink: "+relURLBase+"/root/") b.AssertFileContent(filepath.FromSlash("/work/public/cpath/root/cindex.html"), "Single RelPermalink: "+relURLBase+"/cpath/root/") } leafBundle2 := s.getPage(page.KindPage, "a/b/index.md") - assert.NotNil(leafBundle2) + c.Assert(leafBundle2, qt.Not(qt.IsNil)) unicodeBundle := s.getPage(page.KindPage, "c/bundle/index.md") - assert.NotNil(unicodeBundle) + c.Assert(unicodeBundle, qt.Not(qt.IsNil)) pageResources := leafBundle1.Resources().ByType(pageResourceType) - assert.Len(pageResources, 2) + c.Assert(len(pageResources), qt.Equals, 2) firstPage := pageResources[0].(page.Page) secondPage := pageResources[1].(page.Page) - assert.Equal(filepath.FromSlash("/work/base/b/my-bundle/1.md"), firstPage.File().Filename(), secondPage.File().Filename()) - assert.Contains(content(firstPage), "TheContent") - assert.Equal(6, len(leafBundle1.Resources())) + c.Assert(firstPage.File().Filename(), qt.Equals, filepath.FromSlash("/work/base/b/my-bundle/1.md")) + c.Assert(content(firstPage), qt.Contains, "TheContent") + c.Assert(len(leafBundle1.Resources()), qt.Equals, 6) // Verify shortcode in bundled page - assert.Contains(content(secondPage), filepath.FromSlash("MyShort in b/my-bundle/2.md")) + c.Assert(content(secondPage), qt.Contains, filepath.FromSlash("MyShort in b/my-bundle/2.md")) // https://github.com/gohugoio/hugo/issues/4582 - assert.Equal(leafBundle1, firstPage.Parent()) - assert.Equal(leafBundle1, secondPage.Parent()) + c.Assert(firstPage.Parent(), qt.Equals, leafBundle1) + c.Assert(secondPage.Parent(), qt.Equals, leafBundle1) - assert.Equal(firstPage, pageResources.GetMatch("1*")) - assert.Equal(secondPage, pageResources.GetMatch("2*")) - assert.Nil(pageResources.GetMatch("doesnotexist*")) + c.Assert(pageResources.GetMatch("1*"), qt.Equals, firstPage) + c.Assert(pageResources.GetMatch("2*"), qt.Equals, secondPage) + c.Assert(pageResources.GetMatch("doesnotexist*"), qt.IsNil) imageResources := leafBundle1.Resources().ByType("image") - assert.Equal(3, len(imageResources)) + c.Assert(len(imageResources), qt.Equals, 3) - assert.NotNil(leafBundle1.OutputFormats().Get("CUSTOMO")) + c.Assert(leafBundle1.OutputFormats().Get("CUSTOMO"), qt.Not(qt.IsNil)) relPermalinker := func(s string) string { return fmt.Sprintf(s, relURLBase) @@ -224,10 +224,10 @@ func TestPageBundlerSiteRegular(t *testing.T) { b.AssertFileContent(filepath.FromSlash("/work/public/2017/pageslug/c/logo.png"), "content") b.AssertFileContent(filepath.FromSlash("/work/public/cpath/2017/pageslug/c/logo.png"), "content") - assert.False(b.CheckExists("/work/public/cpath/cpath/2017/pageslug/c/logo.png")) + c.Assert(b.CheckExists("/work/public/cpath/cpath/2017/pageslug/c/logo.png"), qt.Equals, false) // Custom media type defined in site config. - assert.Len(leafBundle1.Resources().ByType("bepsays"), 1) + c.Assert(len(leafBundle1.Resources().ByType("bepsays")), qt.Equals, 1) if ugly { b.AssertFileContent(filepath.FromSlash("/work/public/2017/pageslug.html"), @@ -279,7 +279,7 @@ func TestPageBundlerSiteMultilingual(t *testing.T) { t.Run(fmt.Sprintf("ugly=%t", ugly), func(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) fs, cfg := newTestBundleSourcesMultilingual(t) cfg.Set("uglyURLs", ugly) @@ -288,17 +288,17 @@ func TestPageBundlerSiteMultilingual(t *testing.T) { sites := b.H - assert.Equal(2, len(sites.Sites)) + c.Assert(len(sites.Sites), qt.Equals, 2) s := sites.Sites[0] - assert.Equal(8, len(s.RegularPages())) - assert.Equal(16, len(s.Pages())) + c.Assert(len(s.RegularPages()), qt.Equals, 8) + c.Assert(len(s.Pages()), qt.Equals, 16) //dumpPages(s.AllPages()...) - assert.Equal(31, len(s.AllPages())) + c.Assert(len(s.AllPages()), qt.Equals, 31) bundleWithSubPath := s.getPage(page.KindPage, "lb/index") - assert.NotNil(bundleWithSubPath) + c.Assert(bundleWithSubPath, qt.Not(qt.IsNil)) // See https://github.com/gohugoio/hugo/issues/4312 // Before that issue: @@ -312,37 +312,36 @@ func TestPageBundlerSiteMultilingual(t *testing.T) { // These may also be translated, so we also need to test that. // "bf", "my-bf-bundle", "index.md + nn bfBundle := s.getPage(page.KindPage, "bf/my-bf-bundle/index") - assert.NotNil(bfBundle) - assert.Equal("en", bfBundle.Language().Lang) - assert.Equal(bfBundle, s.getPage(page.KindPage, "bf/my-bf-bundle/index.md")) - assert.Equal(bfBundle, s.getPage(page.KindPage, "bf/my-bf-bundle")) - assert.Equal(bfBundle, s.getPage(page.KindPage, "my-bf-bundle")) + c.Assert(bfBundle, qt.Not(qt.IsNil)) + c.Assert(bfBundle.Language().Lang, qt.Equals, "en") + c.Assert(s.getPage(page.KindPage, "bf/my-bf-bundle/index.md"), qt.Equals, bfBundle) + c.Assert(s.getPage(page.KindPage, "bf/my-bf-bundle"), qt.Equals, bfBundle) + c.Assert(s.getPage(page.KindPage, "my-bf-bundle"), qt.Equals, bfBundle) nnSite := sites.Sites[1] - assert.Equal(7, len(nnSite.RegularPages())) + c.Assert(len(nnSite.RegularPages()), qt.Equals, 7) bfBundleNN := nnSite.getPage(page.KindPage, "bf/my-bf-bundle/index") - assert.NotNil(bfBundleNN) - assert.Equal("nn", bfBundleNN.Language().Lang) - assert.Equal(bfBundleNN, nnSite.getPage(page.KindPage, "bf/my-bf-bundle/index.nn.md")) - assert.Equal(bfBundleNN, nnSite.getPage(page.KindPage, "bf/my-bf-bundle")) - assert.Equal(bfBundleNN, nnSite.getPage(page.KindPage, "my-bf-bundle")) + c.Assert(bfBundleNN, qt.Not(qt.IsNil)) + c.Assert(bfBundleNN.Language().Lang, qt.Equals, "nn") + c.Assert(nnSite.getPage(page.KindPage, "bf/my-bf-bundle/index.nn.md"), qt.Equals, bfBundleNN) + c.Assert(nnSite.getPage(page.KindPage, "bf/my-bf-bundle"), qt.Equals, bfBundleNN) + c.Assert(nnSite.getPage(page.KindPage, "my-bf-bundle"), qt.Equals, bfBundleNN) // See https://github.com/gohugoio/hugo/issues/4295 // Every resource should have its Name prefixed with its base folder. cBundleResources := bundleWithSubPath.Resources().Match("c/**") - assert.Equal(4, len(cBundleResources)) + c.Assert(len(cBundleResources), qt.Equals, 4) bundlePage := bundleWithSubPath.Resources().GetMatch("c/page*") - assert.NotNil(bundlePage) - assert.IsType(&pageState{}, bundlePage) + c.Assert(bundlePage, qt.Not(qt.IsNil)) bcBundleNN, _ := nnSite.getPageNew(nil, "bc") - assert.NotNil(bcBundleNN) + c.Assert(bcBundleNN, qt.Not(qt.IsNil)) bcBundleEN, _ := s.getPageNew(nil, "bc") - assert.Equal("nn", bcBundleNN.Language().Lang) - assert.Equal("en", bcBundleEN.Language().Lang) - assert.Equal(3, len(bcBundleNN.Resources())) - assert.Equal(3, len(bcBundleEN.Resources())) + c.Assert(bcBundleNN.Language().Lang, qt.Equals, "nn") + c.Assert(bcBundleEN.Language().Lang, qt.Equals, "en") + c.Assert(len(bcBundleNN.Resources()), qt.Equals, 3) + c.Assert(len(bcBundleEN.Resources()), qt.Equals, 3) b.AssertFileContent("public/en/bc/data1.json", "data1") b.AssertFileContent("public/en/bc/data2.json", "data2") b.AssertFileContent("public/en/bc/logo-bc.png", "logo") @@ -357,22 +356,22 @@ func TestPageBundlerSiteMultilingual(t *testing.T) { func TestMultilingualDisableDefaultLanguage(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) _, cfg := newTestBundleSourcesMultilingual(t) cfg.Set("disableLanguages", []string{"en"}) err := loadDefaultSettingsFor(cfg) - assert.NoError(err) + c.Assert(err, qt.IsNil) err = loadLanguageSettings(cfg, nil) - assert.Error(err) - assert.Contains(err.Error(), "cannot disable default language") + c.Assert(err, qt.Not(qt.IsNil)) + c.Assert(err.Error(), qt.Contains, "cannot disable default language") } func TestMultilingualDisableLanguage(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) fs, cfg := newTestBundleSourcesMultilingual(t) cfg.Set("disableLanguages", []string{"nn"}) @@ -380,19 +379,19 @@ func TestMultilingualDisableLanguage(t *testing.T) { b.Build(BuildCfg{}) sites := b.H - assert.Equal(1, len(sites.Sites)) + c.Assert(len(sites.Sites), qt.Equals, 1) s := sites.Sites[0] - assert.Equal(8, len(s.RegularPages())) - assert.Equal(16, len(s.Pages())) + c.Assert(len(s.RegularPages()), qt.Equals, 8) + c.Assert(len(s.Pages()), qt.Equals, 16) // No nn pages - assert.Equal(16, len(s.AllPages())) + c.Assert(len(s.AllPages()), qt.Equals, 16) for _, p := range s.rawAllPages { - assert.True(p.Language().Lang != "nn") + c.Assert(p.Language().Lang != "nn", qt.Equals, true) } for _, p := range s.AllPages() { - assert.True(p.Language().Lang != "nn") + c.Assert(p.Language().Lang != "nn", qt.Equals, true) } } @@ -405,42 +404,42 @@ func TestPageBundlerSiteWitSymbolicLinksInContent(t *testing.T) { os.Chdir(wd) }() - assert := require.New(t) + c := qt.New(t) // We need to use the OS fs for this. cfg := viper.New() fs := hugofs.NewFrom(hugofs.Os, cfg) workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugosym") - assert.NoError(err) + c.Assert(err, qt.IsNil) contentDirName := "content" contentDir := filepath.Join(workDir, contentDirName) - assert.NoError(os.MkdirAll(filepath.Join(contentDir, "a"), 0777)) + c.Assert(os.MkdirAll(filepath.Join(contentDir, "a"), 0777), qt.IsNil) for i := 1; i <= 3; i++ { - assert.NoError(os.MkdirAll(filepath.Join(workDir, fmt.Sprintf("symcontent%d", i)), 0777)) + c.Assert(os.MkdirAll(filepath.Join(workDir, fmt.Sprintf("symcontent%d", i)), 0777), qt.IsNil) } - assert.NoError(os.MkdirAll(filepath.Join(workDir, "symcontent2", "a1"), 0777)) + c.Assert(os.MkdirAll(filepath.Join(workDir, "symcontent2", "a1"), 0777), qt.IsNil) // Symlinked sections inside content. os.Chdir(contentDir) for i := 1; i <= 3; i++ { - assert.NoError(os.Symlink(filepath.FromSlash(fmt.Sprintf(("../symcontent%d"), i)), fmt.Sprintf("symbolic%d", i))) + c.Assert(os.Symlink(filepath.FromSlash(fmt.Sprintf(("../symcontent%d"), i)), fmt.Sprintf("symbolic%d", i)), qt.IsNil) } - assert.NoError(os.Chdir(filepath.Join(contentDir, "a"))) + c.Assert(os.Chdir(filepath.Join(contentDir, "a")), qt.IsNil) // Create a symlink to one single content file - assert.NoError(os.Symlink(filepath.FromSlash("../../symcontent2/a1/page.md"), "page_s.md")) + c.Assert(os.Symlink(filepath.FromSlash("../../symcontent2/a1/page.md"), "page_s.md"), qt.IsNil) - assert.NoError(os.Chdir(filepath.FromSlash("../../symcontent3"))) + c.Assert(os.Chdir(filepath.FromSlash("../../symcontent3")), qt.IsNil) // Create a circular symlink. Will print some warnings. - assert.NoError(os.Symlink(filepath.Join("..", contentDirName), filepath.FromSlash("circus"))) + c.Assert(os.Symlink(filepath.Join("..", contentDirName), filepath.FromSlash("circus")), qt.IsNil) - assert.NoError(os.Chdir(workDir)) + c.Assert(os.Chdir(workDir), qt.IsNil) defer clean() @@ -491,11 +490,11 @@ TheContent. b.Build(BuildCfg{}) s := b.H.Sites[0] - assert.Equal(7, len(s.RegularPages())) + c.Assert(len(s.RegularPages()), qt.Equals, 7) a1Bundle := s.getPage(page.KindPage, "symbolic2/a1/index.md") - assert.NotNil(a1Bundle) - assert.Equal(2, len(a1Bundle.Resources())) - assert.Equal(1, len(a1Bundle.Resources().ByType(pageResourceType))) + c.Assert(a1Bundle, qt.Not(qt.IsNil)) + c.Assert(len(a1Bundle.Resources()), qt.Equals, 2) + c.Assert(len(a1Bundle.Resources().ByType(pageResourceType)), qt.Equals, 1) b.AssertFileContent(filepath.FromSlash(workDir+"/public/a/page/index.html"), "TheContent") b.AssertFileContent(filepath.FromSlash(workDir+"/public/symbolic1/s1/index.html"), "TheContent") @@ -507,7 +506,7 @@ func TestPageBundlerHeadless(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() - assert := require.New(t) + c := qt.New(t) workDir := "/work" cfg.Set("workingDir", workDir) @@ -549,30 +548,29 @@ HEADLESS {{< myShort >}} s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) - assert.Equal(1, len(s.RegularPages())) - assert.Equal(1, len(s.headlessPages)) + c.Assert(len(s.RegularPages()), qt.Equals, 1) + c.Assert(len(s.headlessPages), qt.Equals, 1) regular := s.getPage(page.KindPage, "a/index") - assert.Equal("/s1/", regular.RelPermalink()) + c.Assert(regular.RelPermalink(), qt.Equals, "/s1/") headless := s.getPage(page.KindPage, "b/index") - assert.NotNil(headless) - assert.Equal("Headless Bundle in Topless Bar", headless.Title()) - assert.Equal("", headless.RelPermalink()) - assert.Equal("", headless.Permalink()) - assert.Contains(content(headless), "HEADLESS SHORTCODE") + c.Assert(headless, qt.Not(qt.IsNil)) + c.Assert(headless.Title(), qt.Equals, "Headless Bundle in Topless Bar") + c.Assert(headless.RelPermalink(), qt.Equals, "") + c.Assert(headless.Permalink(), qt.Equals, "") + c.Assert(content(headless), qt.Contains, "HEADLESS SHORTCODE") headlessResources := headless.Resources() - assert.Equal(3, len(headlessResources)) - assert.Equal(2, len(headlessResources.Match("l*"))) + c.Assert(len(headlessResources), qt.Equals, 3) + c.Assert(len(headlessResources.Match("l*")), qt.Equals, 2) pageResource := headlessResources.GetMatch("p*") - assert.NotNil(pageResource) - assert.IsType(&pageState{}, pageResource) + c.Assert(pageResource, qt.Not(qt.IsNil)) p := pageResource.(page.Page) - assert.Contains(content(p), "SHORTCODE") - assert.Equal("p1.md", p.Name()) + c.Assert(content(p), qt.Contains, "SHORTCODE") + c.Assert(p.Name(), qt.Equals, "p1.md") - th := testHelper{s.Cfg, s.Fs, t} + th := newTestHelper(s.Cfg, s.Fs, t) th.assertFileContent(filepath.FromSlash(workDir+"/public/s1/index.html"), "TheContent") th.assertFileContent(filepath.FromSlash(workDir+"/public/s1/l1.png"), "PNG") @@ -584,7 +582,7 @@ HEADLESS {{< myShort >}} } func TestMultiSiteBundles(t *testing.T) { - assert := require.New(t) + c := qt.New(t) b := newTestSitesBuilder(t) b.WithConfigFile("toml", ` @@ -656,12 +654,12 @@ Single content. b.AssertFileContent("public/mybundle/data.yaml", "data en") b.AssertFileContent("public/mybundle/forms.yaml", "forms en") - assert.False(b.CheckExists("public/nn/nn/mybundle/data.yaml")) - assert.False(b.CheckExists("public/en/mybundle/data.yaml")) + c.Assert(b.CheckExists("public/nn/nn/mybundle/data.yaml"), qt.Equals, false) + c.Assert(b.CheckExists("public/en/mybundle/data.yaml"), qt.Equals, false) homeEn := b.H.Sites[0].home - assert.NotNil(homeEn) - assert.Equal(2018, homeEn.Date().Year()) + c.Assert(homeEn, qt.Not(qt.IsNil)) + c.Assert(homeEn.Date().Year(), qt.Equals, 2018) b.AssertFileContent("public/section-not-bundle/index.html", "Section Page", "Content: <p>Section content.</p>") b.AssertFileContent("public/section-not-bundle/single/index.html", "Section Single", "|<p>Single content.</p>") @@ -670,7 +668,7 @@ Single content. func newTestBundleSources(t *testing.T) (*hugofs.Fs, *viper.Viper) { cfg, fs := newTestCfgBasic() - assert := require.New(t) + c := qt.New(t) workDir := "/work" cfg.Set("workingDir", workDir) @@ -814,22 +812,22 @@ Content for 은행. // Write a real image into one of the bundle above. src, err := os.Open("testdata/sunset.jpg") - assert.NoError(err) + c.Assert(err, qt.IsNil) // We need 2 to test https://github.com/gohugoio/hugo/issues/4202 out, err := fs.Source.Create(filepath.Join(workDir, "base", "b", "my-bundle", "sunset1.jpg")) - assert.NoError(err) + c.Assert(err, qt.IsNil) out2, err := fs.Source.Create(filepath.Join(workDir, "base", "b", "my-bundle", "sunset2.jpg")) - assert.NoError(err) + c.Assert(err, qt.IsNil) _, err = io.Copy(out, src) - assert.NoError(err) + c.Assert(err, qt.IsNil) out.Close() src.Seek(0, 0) _, err = io.Copy(out2, src) out2.Close() src.Close() - assert.NoError(err) + c.Assert(err, qt.IsNil) return fs, cfg @@ -959,7 +957,7 @@ date: 2017-01-15 // https://github.com/gohugoio/hugo/issues/4870 func TestBundleSlug(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) const pageTemplate = `--- title: Title @@ -980,8 +978,8 @@ slug: %s "|/about/services1/this-is-the-slug/|/", "|/about/services2/this-is-another-slug/|") - assert.True(b.CheckExists("public/about/services1/this-is-the-slug/index.html")) - assert.True(b.CheckExists("public/about/services2/this-is-another-slug/index.html")) + c.Assert(b.CheckExists("public/about/services1/this-is-the-slug/index.html"), qt.Equals, true) + c.Assert(b.CheckExists("public/about/services2/this-is-another-slug/index.html"), qt.Equals, true) } @@ -1087,8 +1085,8 @@ slug: leaf b.AssertFileContent("public/en/enonly/myen/index.html", "Single: en: Page") b.AssertFileContent("public/en/enonly/myendata.json", "mydata") - assert := require.New(t) - assert.False(b.CheckExists("public/sv/enonly/myen/index.html")) + c := qt.New(t) + c.Assert(b.CheckExists("public/sv/enonly/myen/index.html"), qt.Equals, false) // Both leaf and branch bundle in same dir // We log a warning about it, but we keep both. diff --git a/hugolib/pagecollections_test.go b/hugolib/pagecollections_test.go index a5a347f83..0f7520e1b 100644 --- a/hugolib/pagecollections_test.go +++ b/hugolib/pagecollections_test.go @@ -21,10 +21,10 @@ import ( "testing" "time" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/deps" - "github.com/stretchr/testify/require" ) const pageCollectionsPageTemplate = `--- @@ -72,6 +72,7 @@ func BenchmarkGetPage(b *testing.B) { func BenchmarkGetPageRegular(b *testing.B) { var ( + c = qt.New(b) cfg, fs = newTestCfg() r = rand.New(rand.NewSource(time.Now().UnixNano())) ) @@ -94,7 +95,7 @@ func BenchmarkGetPageRegular(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { page, _ := s.getPageNew(nil, pagePaths[i]) - require.NotNil(b, page) + c.Assert(page, qt.Not(qt.IsNil)) } } @@ -105,27 +106,28 @@ type testCase struct { expectedTitle string } -func (t *testCase) check(p page.Page, err error, errorMsg string, assert *require.Assertions) { +func (t *testCase) check(p page.Page, err error, errorMsg string, c *qt.C) { + errorComment := qt.Commentf(errorMsg) switch t.kind { case "Ambiguous": - assert.Error(err) - assert.Nil(p, errorMsg) + c.Assert(err, qt.Not(qt.IsNil)) + c.Assert(p, qt.IsNil, errorComment) case "NoPage": - assert.NoError(err) - assert.Nil(p, errorMsg) + c.Assert(err, qt.IsNil) + c.Assert(p, qt.IsNil, errorComment) default: - assert.NoError(err, errorMsg) - assert.NotNil(p, errorMsg) - assert.Equal(t.kind, p.Kind(), errorMsg) - assert.Equal(t.expectedTitle, p.Title(), errorMsg) + c.Assert(err, qt.IsNil, errorComment) + c.Assert(p, qt.Not(qt.IsNil), errorComment) + c.Assert(p.Kind(), qt.Equals, t.kind, errorComment) + c.Assert(p.Title(), qt.Equals, t.expectedTitle, errorComment) } } func TestGetPage(t *testing.T) { var ( - assert = require.New(t) cfg, fs = newTestCfg() + c = qt.New(t) ) for i := 0; i < 10; i++ { @@ -156,8 +158,8 @@ func TestGetPage(t *testing.T) { s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) sec3, err := s.getPageNew(nil, "/sect3") - assert.NoError(err, "error getting Page for /sec3") - assert.NotNil(sec3, "failed to get Page for /sec3") + c.Assert(err, qt.IsNil) + c.Assert(sec3, qt.Not(qt.IsNil)) tests := []testCase{ // legacy content root relative paths @@ -227,7 +229,7 @@ func TestGetPage(t *testing.T) { if test.context == nil { args := append([]string{test.kind}, test.path...) page, err := s.Info.GetPage(args...) - test.check(page, err, errorMsg, assert) + test.check(page, err, errorMsg, c) } // test new internal Site.getPageNew @@ -238,7 +240,7 @@ func TestGetPage(t *testing.T) { ref = path.Join(test.path...) } page2, err := s.getPageNew(test.context, ref) - test.check(page2, err, errorMsg, assert) + test.check(page2, err, errorMsg, c) } } diff --git a/hugolib/pages_capture_test.go b/hugolib/pages_capture_test.go index 38391f85c..b5b2bf31c 100644 --- a/hugolib/pages_capture_test.go +++ b/hugolib/pages_capture_test.go @@ -26,9 +26,9 @@ import ( "github.com/gohugoio/hugo/common/loggers" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/hugofs" "github.com/spf13/afero" - "github.com/stretchr/testify/require" ) func TestPagesCapture(t *testing.T) { @@ -36,10 +36,10 @@ func TestPagesCapture(t *testing.T) { cfg, hfs := newTestCfg() fs := hfs.Source - assert := require.New(t) + c := qt.New(t) var writeFile = func(filename string) { - assert.NoError(afero.WriteFile(fs, filepath.FromSlash(filename), []byte(fmt.Sprintf("content-%s", filename)), 0755)) + c.Assert(afero.WriteFile(fs, filepath.FromSlash(filename), []byte(fmt.Sprintf("content-%s", filename)), 0755), qt.IsNil) } writeFile("_index.md") @@ -53,22 +53,22 @@ func TestPagesCapture(t *testing.T) { writeFile("pages/page.png") ps, err := helpers.NewPathSpec(hugofs.NewFrom(fs, cfg), cfg, loggers.NewErrorLogger()) - assert.NoError(err) + c.Assert(err, qt.IsNil) sourceSpec := source.NewSourceSpec(ps, fs) t.Run("Collect", func(t *testing.T) { - assert := require.New(t) + c := qt.New(t) proc := &testPagesCollectorProcessor{} - c := newPagesCollector(sourceSpec, loggers.NewErrorLogger(), nil, proc) - assert.NoError(c.Collect()) - assert.Equal(4, len(proc.items)) + coll := newPagesCollector(sourceSpec, loggers.NewErrorLogger(), nil, proc) + c.Assert(coll.Collect(), qt.IsNil) + c.Assert(len(proc.items), qt.Equals, 4) }) t.Run("error in Wait", func(t *testing.T) { - assert := require.New(t) - c := newPagesCollector(sourceSpec, loggers.NewErrorLogger(), nil, + c := qt.New(t) + coll := newPagesCollector(sourceSpec, loggers.NewErrorLogger(), nil, &testPagesCollectorProcessor{waitErr: errors.New("failed")}) - assert.Error(c.Collect()) + c.Assert(coll.Collect(), qt.Not(qt.IsNil)) }) } diff --git a/hugolib/pages_language_merge_test.go b/hugolib/pages_language_merge_test.go index bae2ddd81..7d7181214 100644 --- a/hugolib/pages_language_merge_test.go +++ b/hugolib/pages_language_merge_test.go @@ -17,15 +17,15 @@ import ( "fmt" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/resources/resource" - "github.com/stretchr/testify/require" ) // TODO(bep) move and rewrite in resource/page. func TestMergeLanguages(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) b := newTestSiteForLanguageMerge(t, 30) b.CreateSites() @@ -38,53 +38,53 @@ func TestMergeLanguages(t *testing.T) { frSite := h.Sites[1] nnSite := h.Sites[2] - assert.Equal(31, len(enSite.RegularPages())) - assert.Equal(6, len(frSite.RegularPages())) - assert.Equal(12, len(nnSite.RegularPages())) + c.Assert(len(enSite.RegularPages()), qt.Equals, 31) + c.Assert(len(frSite.RegularPages()), qt.Equals, 6) + c.Assert(len(nnSite.RegularPages()), qt.Equals, 12) for i := 0; i < 2; i++ { mergedNN := nnSite.RegularPages().MergeByLanguage(enSite.RegularPages()) - assert.Equal(31, len(mergedNN)) + c.Assert(len(mergedNN), qt.Equals, 31) for i := 1; i <= 31; i++ { expectedLang := "en" if i == 2 || i%3 == 0 || i == 31 { expectedLang = "nn" } p := mergedNN[i-1] - assert.Equal(expectedLang, p.Language().Lang, fmt.Sprintf("Test %d", i)) + c.Assert(p.Language().Lang, qt.Equals, expectedLang) } } mergedFR := frSite.RegularPages().MergeByLanguage(enSite.RegularPages()) - assert.Equal(31, len(mergedFR)) + c.Assert(len(mergedFR), qt.Equals, 31) for i := 1; i <= 31; i++ { expectedLang := "en" if i%5 == 0 { expectedLang = "fr" } p := mergedFR[i-1] - assert.Equal(expectedLang, p.Language().Lang, fmt.Sprintf("Test %d", i)) + c.Assert(p.Language().Lang, qt.Equals, expectedLang) } firstNN := nnSite.RegularPages()[0] - assert.Equal(4, len(firstNN.Sites())) - assert.Equal("en", firstNN.Sites().First().Language().Lang) + c.Assert(len(firstNN.Sites()), qt.Equals, 4) + c.Assert(firstNN.Sites().First().Language().Lang, qt.Equals, "en") nnBundle := nnSite.getPage("page", "bundle") enBundle := enSite.getPage("page", "bundle") - assert.Equal(6, len(enBundle.Resources())) - assert.Equal(2, len(nnBundle.Resources())) + c.Assert(len(enBundle.Resources()), qt.Equals, 6) + c.Assert(len(nnBundle.Resources()), qt.Equals, 2) var ri interface{} = nnBundle.Resources() // This looks less ugly in the templates ... mergedNNResources := ri.(resource.ResourcesLanguageMerger).MergeByLanguage(enBundle.Resources()) - assert.Equal(6, len(mergedNNResources)) + c.Assert(len(mergedNNResources), qt.Equals, 6) unchanged, err := nnSite.RegularPages().MergeByLanguageInterface(nil) - assert.NoError(err) - assert.Equal(nnSite.RegularPages(), unchanged) + c.Assert(err, qt.IsNil) + c.Assert(unchanged, deepEqualsPages, nnSite.RegularPages()) } diff --git a/hugolib/paths/baseURL_test.go b/hugolib/paths/baseURL_test.go index 382a18314..77095bb7d 100644 --- a/hugolib/paths/baseURL_test.go +++ b/hugolib/paths/baseURL_test.go @@ -16,51 +16,52 @@ package paths import ( "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestBaseURL(t *testing.T) { + c := qt.New(t) b, err := newBaseURLFromString("http://example.com") - require.NoError(t, err) - require.Equal(t, "http://example.com", b.String()) + c.Assert(err, qt.IsNil) + c.Assert(b.String(), qt.Equals, "http://example.com") p, err := b.WithProtocol("webcal://") - require.NoError(t, err) - require.Equal(t, "webcal://example.com", p) + c.Assert(err, qt.IsNil) + c.Assert(p, qt.Equals, "webcal://example.com") p, err = b.WithProtocol("webcal") - require.NoError(t, err) - require.Equal(t, "webcal://example.com", p) + c.Assert(err, qt.IsNil) + c.Assert(p, qt.Equals, "webcal://example.com") _, err = b.WithProtocol("mailto:") - require.Error(t, err) + c.Assert(err, qt.Not(qt.IsNil)) b, err = newBaseURLFromString("mailto:[email protected]") - require.NoError(t, err) - require.Equal(t, "mailto:[email protected]", b.String()) + c.Assert(err, qt.IsNil) + c.Assert(b.String(), qt.Equals, "mailto:[email protected]") // These are pretty constructed p, err = b.WithProtocol("webcal") - require.NoError(t, err) - require.Equal(t, "webcal:[email protected]", p) + c.Assert(err, qt.IsNil) + c.Assert(p, qt.Equals, "webcal:[email protected]") p, err = b.WithProtocol("webcal://") - require.NoError(t, err) - require.Equal(t, "webcal://[email protected]", p) + c.Assert(err, qt.IsNil) + c.Assert(p, qt.Equals, "webcal://[email protected]") // Test with "non-URLs". Some people will try to use these as a way to get // relative URLs working etc. b, err = newBaseURLFromString("/") - require.NoError(t, err) - require.Equal(t, "/", b.String()) + c.Assert(err, qt.IsNil) + c.Assert(b.String(), qt.Equals, "/") b, err = newBaseURLFromString("") - require.NoError(t, err) - require.Equal(t, "", b.String()) + c.Assert(err, qt.IsNil) + c.Assert(b.String(), qt.Equals, "") // BaseURL with sub path b, err = newBaseURLFromString("http://example.com/sub") - require.NoError(t, err) - require.Equal(t, "http://example.com/sub", b.String()) - require.Equal(t, "http://example.com", b.HostURL()) + c.Assert(err, qt.IsNil) + c.Assert(b.String(), qt.Equals, "http://example.com/sub") + c.Assert(b.HostURL(), qt.Equals, "http://example.com") } diff --git a/hugolib/paths/paths_test.go b/hugolib/paths/paths_test.go index 95a8be782..59dbf0e00 100644 --- a/hugolib/paths/paths_test.go +++ b/hugolib/paths/paths_test.go @@ -18,13 +18,13 @@ import ( "github.com/gohugoio/hugo/langs" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/hugofs" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) func TestNewPaths(t *testing.T) { - assert := require.New(t) + c := qt.New(t) v := viper.New() fs := hugofs.NewMem(v) @@ -43,9 +43,9 @@ func TestNewPaths(t *testing.T) { langs.LoadLanguageSettings(v, nil) p, err := New(fs, v) - assert.NoError(err) + c.Assert(err, qt.IsNil) - assert.Equal(true, p.defaultContentLanguageInSubdir) - assert.Equal("no", p.DefaultContentLanguage) - assert.Equal(true, p.multilingual) + c.Assert(p.defaultContentLanguageInSubdir, qt.Equals, true) + c.Assert(p.DefaultContentLanguage, qt.Equals, "no") + c.Assert(p.multilingual, qt.Equals, true) } diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go index ea95a3f09..75f5595e1 100644 --- a/hugolib/resource_chain_test.go +++ b/hugolib/resource_chain_test.go @@ -22,7 +22,7 @@ import ( "github.com/spf13/viper" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/hugofs" @@ -34,9 +34,9 @@ func TestSCSSWithIncludePaths(t *testing.T) { if !scss.Supports() { t.Skip("Skip SCSS") } - assert := require.New(t) + c := qt.New(t) workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-scss-include") - assert.NoError(err) + c.Assert(err, qt.IsNil) defer clean() v := viper.New() @@ -49,13 +49,13 @@ func TestSCSSWithIncludePaths(t *testing.T) { fooDir := filepath.Join(workDir, "node_modules", "foo") scssDir := filepath.Join(workDir, "assets", "scss") - assert.NoError(os.MkdirAll(fooDir, 0777)) - assert.NoError(os.MkdirAll(filepath.Join(workDir, "content", "sect"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(workDir, "data"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(workDir, "i18n"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(workDir, "layouts", "shortcodes"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(workDir, "layouts", "_default"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(scssDir), 0777)) + c.Assert(os.MkdirAll(fooDir, 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(workDir, "content", "sect"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(workDir, "data"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(workDir, "i18n"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(workDir, "layouts", "shortcodes"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(workDir, "layouts", "_default"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(scssDir), 0777), qt.IsNil) b.WithSourceFile(filepath.Join(fooDir, "_moo.scss"), ` $moolor: #fff; @@ -85,9 +85,9 @@ func TestSCSSWithThemeOverrides(t *testing.T) { if !scss.Supports() { t.Skip("Skip SCSS") } - assert := require.New(t) + c := qt.New(t) workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-scss-include") - assert.NoError(err) + c.Assert(err, qt.IsNil) defer clean() theme := "mytheme" @@ -105,14 +105,14 @@ func TestSCSSWithThemeOverrides(t *testing.T) { fooDir := filepath.Join(workDir, "node_modules", "foo") scssDir := filepath.Join(workDir, "assets", "scss") scssThemeDir := filepath.Join(themeDirs, "assets", "scss") - assert.NoError(os.MkdirAll(fooDir, 0777)) - assert.NoError(os.MkdirAll(filepath.Join(workDir, "content", "sect"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(workDir, "data"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(workDir, "i18n"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(workDir, "layouts", "shortcodes"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(workDir, "layouts", "_default"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(scssDir, "components"), 0777)) - assert.NoError(os.MkdirAll(filepath.Join(scssThemeDir, "components"), 0777)) + c.Assert(os.MkdirAll(fooDir, 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(workDir, "content", "sect"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(workDir, "data"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(workDir, "i18n"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(workDir, "layouts", "shortcodes"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(workDir, "layouts", "_default"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(scssDir, "components"), 0777), qt.IsNil) + c.Assert(os.MkdirAll(filepath.Join(scssThemeDir, "components"), 0777), qt.IsNil) b.WithSourceFile(filepath.Join(scssThemeDir, "components", "_imports.scss"), ` @import "moo"; @@ -170,7 +170,7 @@ T1: {{ $r.Content }} func TestResourceChain(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) tests := []struct { name string @@ -203,7 +203,7 @@ T6: {{ $bundle1.Permalink }} b.AssertFileContent("public/index.html", `T5 RelPermalink: /sass/styles3.css|`) b.AssertFileContent("public/index.html", `T6: http://example.com/styles/bundle1.css`) - assert.False(b.CheckExists("public/styles/templ.min.css")) + c.Assert(b.CheckExists("public/styles/templ.min.css"), qt.Equals, false) b.AssertFileContent("public/styles/bundle1.css", `.home{color:blue}body{color:#333}`) }}, @@ -353,10 +353,9 @@ Publish 2: {{ $cssPublish2.Permalink }} "Publish 1: body{color:blue} /external1.min.css", "Publish 2: http://example.com/external2.min.css", ) - assert.True(b.CheckExists("public/external2.min.css"), "Referenced content should be copied to /public") - assert.True(b.CheckExists("public/external1.min.css"), "Referenced content should be copied to /public") - - assert.False(b.CheckExists("public/inline.min.css"), "Inline content should not be copied to /public") + c.Assert(b.CheckExists("public/external2.min.css"), qt.Equals, true) + c.Assert(b.CheckExists("public/external1.min.css"), qt.Equals, true) + c.Assert(b.CheckExists("public/inline.min.css"), qt.Equals, false) }}, {"unmarshal", func() bool { return true }, func(b *sitesBuilder) { @@ -489,7 +488,7 @@ $color: #333; func TestMultiSiteResource(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) b := newMultiSiteTestDefaultBuilder(t) @@ -497,8 +496,8 @@ func TestMultiSiteResource(t *testing.T) { // This build is multilingual, but not multihost. There should be only one pipes.txt b.AssertFileContent("public/fr/index.html", "French Home Page", "String Resource: /blog/text/pipes.txt") - assert.False(b.CheckExists("public/fr/text/pipes.txt")) - assert.False(b.CheckExists("public/en/text/pipes.txt")) + c.Assert(b.CheckExists("public/fr/text/pipes.txt"), qt.Equals, false) + c.Assert(b.CheckExists("public/en/text/pipes.txt"), qt.Equals, false) b.AssertFileContent("public/en/index.html", "Default Home Page", "String Resource: /blog/text/pipes.txt") b.AssertFileContent("public/text/pipes.txt", "Hugo Pipes") diff --git a/hugolib/rss_test.go b/hugolib/rss_test.go index 38f0f1eff..634843e3d 100644 --- a/hugolib/rss_test.go +++ b/hugolib/rss_test.go @@ -25,7 +25,7 @@ func TestRSSOutput(t *testing.T) { t.Parallel() var ( cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} + th = newTestHelper(cfg, fs, t) ) rssLimit := len(weightedSources) - 1 diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 24ef77503..13cbd1fd8 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -16,7 +16,6 @@ package hugolib import ( "fmt" "path/filepath" - "regexp" "reflect" @@ -31,7 +30,7 @@ import ( "github.com/gohugoio/hugo/tpl" "github.com/spf13/cast" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func CheckShortCodeMatch(t *testing.T, input, expected string, withTemplate func(templ tpl.TemplateHandler) error) { @@ -41,6 +40,7 @@ func CheckShortCodeMatch(t *testing.T, input, expected string, withTemplate func func CheckShortCodeMatchAndError(t *testing.T, input, expected string, withTemplate func(templ tpl.TemplateHandler) error, expectError bool) { cfg, fs := newTestCfg() + c := qt.New(t) // Need some front matter, see https://github.com/gohugoio/hugo/issues/2337 contentFile := `--- @@ -62,9 +62,9 @@ title: "Title" } h := b.H - require.Len(t, h.Sites, 1) + c.Assert(len(h.Sites), qt.Equals, 1) - require.Len(t, h.Sites[0].RegularPages(), 1) + c.Assert(len(h.Sites[0].RegularPages()), qt.Equals, 1) output := strings.TrimSpace(content(h.Sites[0].RegularPages()[0])) output = strings.TrimPrefix(output, "<p>") @@ -358,8 +358,8 @@ title: "Shortcodes Galore!" /*errCheck := func(s string) func(name string, assert *require.Assertions, shortcode *shortcode, err error) { return func(name string, assert *require.Assertions, shortcode *shortcode, err error) { - assert.Error(err, name) - assert.Equal(s, err.Error(), name) + c.Assert(err, name, qt.Not(qt.IsNil)) + c.Assert(err.Error(), name, qt.Equals, s) } }*/ @@ -374,18 +374,18 @@ title: "Shortcodes Galore!" s.name, s.isInline, s.isClosing, s.inner, s.params, s.ordinal, s.doMarkup, s.info.Config.Version, s.pos)) } - regexpCheck := func(re string) func(assert *require.Assertions, shortcode *shortcode, err error) { - return func(assert *require.Assertions, shortcode *shortcode, err error) { - assert.NoError(err) - got := str(shortcode) - assert.Regexp(regexp.MustCompile(re), got, got) + regexpCheck := func(re string) func(c *qt.C, shortcode *shortcode, err error) { + return func(c *qt.C, shortcode *shortcode, err error) { + c.Assert(err, qt.IsNil) + c.Assert(str(shortcode), qt.Matches, ".*"+re+".*") + } } for _, test := range []struct { name string input string - check func(assert *require.Assertions, shortcode *shortcode, err error) + check func(c *qt.C, shortcode *shortcode, err error) }{ {"one shortcode, no markup", "{{< tag >}}", regexpCheck("tag.*closing:false.*markup:false")}, {"one shortcode, markup", "{{% tag %}}", regexpCheck("tag.*closing:false.*markup:true;version:2")}, @@ -411,7 +411,7 @@ title: "Shortcodes Galore!" t.Run(test.name, func(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) counter := 0 placeholderFunc := func() string { @@ -420,13 +420,13 @@ title: "Shortcodes Galore!" } p, err := pageparser.ParseMain(strings.NewReader(test.input), pageparser.Config{}) - assert.NoError(err) + c.Assert(err, qt.IsNil) handler := newShortcodeHandler(nil, s, placeholderFunc) iter := p.Iterator() short, err := handler.extractShortcode(0, 0, iter) - test.check(assert, short, err) + test.check(c, short, err) }) } @@ -582,7 +582,7 @@ title: "Foo" t.Skip("Skip Rst test case as no rst2html present.") } - th := testHelper{s.Cfg, s.Fs, t} + th := newTestHelper(s.Cfg, s.Fs, t) expected := cast.ToStringSlice(test.expected) th.assertFileContent(filepath.FromSlash(test.outFile), expected...) @@ -655,12 +655,12 @@ CSV: {{< myShort >}} b.Build(BuildCfg{}) h := b.H - require.Len(t, h.Sites, 1) + b.Assert(len(h.Sites), qt.Equals, 1) s := h.Sites[0] home := s.getPage(page.KindHome) - require.NotNil(t, home) - require.Len(t, home.OutputFormats(), 3) + b.Assert(home, qt.Not(qt.IsNil)) + b.Assert(len(home.OutputFormats()), qt.Equals, 3) b.AssertFileContent("public/index.html", "Home HTML", @@ -827,7 +827,6 @@ func TestReplaceShortcodeTokens(t *testing.T) { func TestShortcodeGetContent(t *testing.T) { t.Parallel() - assert := require.New(t) contentShortcode := ` {{- $t := .Get 0 -}} @@ -878,7 +877,7 @@ C-%s` builder.WithContent(content...).WithTemplates(templates...).CreateSites().Build(BuildCfg{}) s := builder.H.Sites[0] - assert.Equal(3, len(s.RegularPages())) + builder.Assert(len(s.RegularPages()), qt.Equals, 3) builder.AssertFileContent("public/en/section1/index.html", "List Content: <p>Logo:P1:|P2:logo.png/PNG logo|:P1: P1:|P2:docs1p1/<p>C-s1p1</p>\n|", @@ -958,7 +957,7 @@ SHORTCODE: {{< c >}} func TestShortcodePreserveOrder(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) contentTemplate := `--- title: doc%d @@ -1004,7 +1003,7 @@ weight: %d builder.WithContent(content...).WithTemplatesAdded(shortcodes...).CreateSites().Build(BuildCfg{}) s := builder.H.Sites[0] - assert.Equal(3, len(s.RegularPages())) + c.Assert(len(s.RegularPages()), qt.Equals, 3) builder.AssertFileContent("public/en/p1/index.html", `v1: 0 sgo: |v2: 1 sgo: 0|v3: 2 sgo: 1|v4: 3 sgo: 2|v5: 4 sgo: 3`) builder.AssertFileContent("public/en/p1/index.html", `outer ordinal: 5 inner: @@ -1016,7 +1015,7 @@ ordinal: 4 scratch ordinal: 5 scratch get ordinal: 4`) func TestShortcodeVariables(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) builder := newTestSitesBuilder(t).WithSimpleConfigFile() @@ -1041,7 +1040,7 @@ String: {{ . | safeHTML }} `).CreateSites().Build(BuildCfg{}) s := builder.H.Sites[0] - assert.Equal(1, len(s.RegularPages())) + c.Assert(len(s.RegularPages()), qt.Equals, 1) builder.AssertFileContent("public/page/index.html", filepath.FromSlash("File: content/page.md"), @@ -1134,7 +1133,7 @@ CONTENT:{{ .Content }} // https://github.com/gohugoio/hugo/issues/5863 func TestShortcodeNamespaced(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) builder := newTestSitesBuilder(t).WithSimpleConfigFile() @@ -1152,7 +1151,7 @@ title: "Hugo Rocks!" "layouts/shortcodes/test/hello.html", `test/hello`).CreateSites().Build(BuildCfg{}) s := builder.H.Sites[0] - assert.Equal(1, len(s.RegularPages())) + c.Assert(len(s.RegularPages()), qt.Equals, 1) builder.AssertFileContent("public/page/index.html", "hello: hello", diff --git a/hugolib/site_benchmark_new_test.go b/hugolib/site_benchmark_new_test.go index 9de2ce5d6..935592346 100644 --- a/hugolib/site_benchmark_new_test.go +++ b/hugolib/site_benchmark_new_test.go @@ -20,6 +20,8 @@ import ( "strconv" "strings" "testing" + + qt "github.com/frankban/quicktest" ) type siteBenchmarkTestcase struct { @@ -182,9 +184,9 @@ contentDir="content/sv" }, func(s *sitesBuilder) { s.CheckExists("public/blog/mybundle/index.html") - s.Assertions.Equal(4, len(s.H.Sites)) - s.Assertions.Equal(len(s.H.Sites[0].RegularPages()), len(s.H.Sites[1].RegularPages())) - s.Assertions.Equal(30, len(s.H.Sites[0].RegularPages())) + s.Assert(len(s.H.Sites), qt.Equals, 4) + s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, len(s.H.Sites[1].RegularPages())) + s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, 30) }, }, diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go index 90e023225..f0fa02d7e 100644 --- a/hugolib/site_output_test.go +++ b/hugolib/site_output_test.go @@ -17,12 +17,11 @@ import ( "strings" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/resources/page" "github.com/spf13/afero" - "github.com/stretchr/testify/require" - "fmt" "github.com/gohugoio/hugo/helpers" @@ -142,15 +141,15 @@ Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.P b.Build(BuildCfg{}) s := b.H.Sites[0] - require.Equal(t, "en", s.language.Lang) + b.Assert(s.language.Lang, qt.Equals, "en") home := s.getPage(page.KindHome) - require.NotNil(t, home) + b.Assert(home, qt.Not(qt.IsNil)) lenOut := len(outputs) - require.Len(t, home.OutputFormats(), lenOut) + b.Assert(len(home.OutputFormats()), qt.Equals, lenOut) // There is currently always a JSON output to make it simpler ... altFormats := lenOut - 1 @@ -179,9 +178,8 @@ Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.P "OtherShort: <h1>Hi!</h1>", "Len Pages: home 10", ) - assert := require.New(t) b.AssertFileContent("public/page/2/index.html", "Page Number: 2") - assert.False(b.CheckExists("public/page/2/index.json")) + b.Assert(b.CheckExists("public/page/2/index.json"), qt.Equals, false) b.AssertFileContent("public/nn/index.html", "List HTML|JSON Nynorsk Heim|", @@ -204,19 +202,19 @@ Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.P of := home.OutputFormats() json := of.Get("JSON") - require.NotNil(t, json) - require.Equal(t, "/blog/index.json", json.RelPermalink()) - require.Equal(t, "http://example.com/blog/index.json", json.Permalink()) + b.Assert(json, qt.Not(qt.IsNil)) + b.Assert(json.RelPermalink(), qt.Equals, "/blog/index.json") + b.Assert(json.Permalink(), qt.Equals, "http://example.com/blog/index.json") if helpers.InStringArray(outputs, "cal") { cal := of.Get("calendar") - require.NotNil(t, cal) - require.Equal(t, "/blog/index.ics", cal.RelPermalink()) - require.Equal(t, "webcal://example.com/blog/index.ics", cal.Permalink()) + b.Assert(cal, qt.Not(qt.IsNil)) + b.Assert(cal.RelPermalink(), qt.Equals, "/blog/index.ics") + b.Assert(cal.Permalink(), qt.Equals, "webcal://example.com/blog/index.ics") } - require.True(t, home.HasShortcode("myShort")) - require.False(t, home.HasShortcode("doesNotExist")) + b.Assert(home.HasShortcode("myShort"), qt.Equals, true) + b.Assert(home.HasShortcode("doesNotExist"), qt.Equals, false) } @@ -237,6 +235,8 @@ baseName = "feed" ` + c := qt.New(t) + mf := afero.NewMemMapFs() writeToFs(t, mf, "content/foo.html", `foo`) @@ -244,14 +244,14 @@ baseName = "feed" err := h.Build(BuildCfg{}) - require.NoError(t, err) + c.Assert(err, qt.IsNil) th.assertFileContent("public/feed.xml", "Recent content on") s := h.Sites[0] //Issue #3450 - require.Equal(t, "http://example.com/blog/feed.xml", s.Info.RSSLink) + c.Assert(s.Info.RSSLink, qt.Equals, "http://example.com/blog/feed.xml") } @@ -294,6 +294,8 @@ baseName = "customdelimbase" ` + c := qt.New(t) + mf := afero.NewMemMapFs() writeToFs(t, mf, "content/foo.html", `foo`) writeToFs(t, mf, "layouts/_default/list.dotless", `a dotless`) @@ -305,7 +307,7 @@ baseName = "customdelimbase" err := h.Build(BuildCfg{}) - require.NoError(t, err) + c.Assert(err, qt.IsNil) th.assertFileContent("public/_redirects", "a dotless") th.assertFileContent("public/defaultdelimbase.defd", "default delimim") @@ -315,21 +317,21 @@ baseName = "customdelimbase" s := h.Sites[0] home := s.getPage(page.KindHome) - require.NotNil(t, home) + c.Assert(home, qt.Not(qt.IsNil)) outputs := home.OutputFormats() - require.Equal(t, "/blog/_redirects", outputs.Get("DOTLESS").RelPermalink()) - require.Equal(t, "/blog/defaultdelimbase.defd", outputs.Get("DEF").RelPermalink()) - require.Equal(t, "/blog/nosuffixbase", outputs.Get("NOS").RelPermalink()) - require.Equal(t, "/blog/customdelimbase_del", outputs.Get("CUS").RelPermalink()) + c.Assert(outputs.Get("DOTLESS").RelPermalink(), qt.Equals, "/blog/_redirects") + c.Assert(outputs.Get("DEF").RelPermalink(), qt.Equals, "/blog/defaultdelimbase.defd") + c.Assert(outputs.Get("NOS").RelPermalink(), qt.Equals, "/blog/nosuffixbase") + c.Assert(outputs.Get("CUS").RelPermalink(), qt.Equals, "/blog/customdelimbase_del") } func TestCreateSiteOutputFormats(t *testing.T) { t.Run("Basic", func(t *testing.T) { - assert := require.New(t) + c := qt.New(t) outputsConfig := map[string]interface{}{ page.KindHome: []string{"HTML", "JSON"}, @@ -340,28 +342,28 @@ func TestCreateSiteOutputFormats(t *testing.T) { cfg.Set("outputs", outputsConfig) outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg) - assert.NoError(err) - assert.Equal(output.Formats{output.JSONFormat}, outputs[page.KindSection]) - assert.Equal(output.Formats{output.HTMLFormat, output.JSONFormat}, outputs[page.KindHome]) + c.Assert(err, qt.IsNil) + c.Assert(outputs[page.KindSection], deepEqualsOutputFormats, output.Formats{output.JSONFormat}) + c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.JSONFormat}) // Defaults - assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[page.KindTaxonomy]) - assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[page.KindTaxonomyTerm]) - assert.Equal(output.Formats{output.HTMLFormat}, outputs[page.KindPage]) + c.Assert(outputs[page.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat}) + c.Assert(outputs[page.KindTaxonomyTerm], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat}) + c.Assert(outputs[page.KindPage], deepEqualsOutputFormats, output.Formats{output.HTMLFormat}) // These aren't (currently) in use when rendering in Hugo, // but the pages needs to be assigned an output format, // so these should also be correct/sensible. - assert.Equal(output.Formats{output.RSSFormat}, outputs[kindRSS]) - assert.Equal(output.Formats{output.SitemapFormat}, outputs[kindSitemap]) - assert.Equal(output.Formats{output.RobotsTxtFormat}, outputs[kindRobotsTXT]) - assert.Equal(output.Formats{output.HTMLFormat}, outputs[kind404]) + c.Assert(outputs[kindRSS], deepEqualsOutputFormats, output.Formats{output.RSSFormat}) + c.Assert(outputs[kindSitemap], deepEqualsOutputFormats, output.Formats{output.SitemapFormat}) + c.Assert(outputs[kindRobotsTXT], deepEqualsOutputFormats, output.Formats{output.RobotsTxtFormat}) + c.Assert(outputs[kind404], deepEqualsOutputFormats, output.Formats{output.HTMLFormat}) }) // Issue #4528 t.Run("Mixed case", func(t *testing.T) { - assert := require.New(t) + c := qt.New(t) cfg := viper.New() outputsConfig := map[string]interface{}{ @@ -370,15 +372,15 @@ func TestCreateSiteOutputFormats(t *testing.T) { cfg.Set("outputs", outputsConfig) outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg) - assert.NoError(err) - assert.Equal(output.Formats{output.JSONFormat}, outputs[page.KindTaxonomyTerm]) + c.Assert(err, qt.IsNil) + c.Assert(outputs[page.KindTaxonomyTerm], deepEqualsOutputFormats, output.Formats{output.JSONFormat}) }) } func TestCreateSiteOutputFormatsInvalidConfig(t *testing.T) { - assert := require.New(t) + c := qt.New(t) outputsConfig := map[string]interface{}{ page.KindHome: []string{"FOO", "JSON"}, @@ -388,11 +390,11 @@ func TestCreateSiteOutputFormatsInvalidConfig(t *testing.T) { cfg.Set("outputs", outputsConfig) _, err := createSiteOutputFormats(output.DefaultFormats, cfg) - assert.Error(err) + c.Assert(err, qt.Not(qt.IsNil)) } func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) { - assert := require.New(t) + c := qt.New(t) outputsConfig := map[string]interface{}{ page.KindHome: []string{}, @@ -402,12 +404,12 @@ func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) { cfg.Set("outputs", outputsConfig) outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg) - assert.NoError(err) - assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[page.KindHome]) + c.Assert(err, qt.IsNil) + c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat}) } func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) { - assert := require.New(t) + c := qt.New(t) outputsConfig := map[string]interface{}{ page.KindHome: []string{}, @@ -422,8 +424,8 @@ func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) { ) outputs, err := createSiteOutputFormats(output.Formats{customRSS, customHTML}, cfg) - assert.NoError(err) - assert.Equal(output.Formats{customHTML, customRSS}, outputs[page.KindHome]) + c.Assert(err, qt.IsNil) + c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{customHTML, customRSS}) } // https://github.com/gohugoio/hugo/issues/5849 diff --git a/hugolib/site_sections_test.go b/hugolib/site_sections_test.go index 2e7ffdf0b..3cd2a06bb 100644 --- a/hugolib/site_sections_test.go +++ b/hugolib/site_sections_test.go @@ -19,17 +19,17 @@ import ( "strings" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/resources/page" - "github.com/stretchr/testify/require" ) func TestNestedSections(t *testing.T) { var ( - assert = require.New(t) + c = qt.New(t) cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} + th = newTestHelper(cfg, fs, t) ) cfg.Set("permalinks", map[string]string{ @@ -117,179 +117,179 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) - require.Len(t, s.RegularPages(), 21) + c.Assert(len(s.RegularPages()), qt.Equals, 21) tests := []struct { sections string - verify func(assert *require.Assertions, p page.Page) + verify func(c *qt.C, p page.Page) }{ - {"elsewhere", func(assert *require.Assertions, p page.Page) { - assert.Len(p.Pages(), 1) + {"elsewhere", func(c *qt.C, p page.Page) { + c.Assert(len(p.Pages()), qt.Equals, 1) for _, p := range p.Pages() { - assert.Equal("elsewhere", p.SectionsPath()) + c.Assert(p.SectionsPath(), qt.Equals, "elsewhere") } }}, - {"post", func(assert *require.Assertions, p page.Page) { - assert.Len(p.Pages(), 2) + {"post", func(c *qt.C, p page.Page) { + c.Assert(len(p.Pages()), qt.Equals, 2) for _, p := range p.Pages() { - assert.Equal("post", p.Section()) + c.Assert(p.Section(), qt.Equals, "post") } }}, - {"empty1", func(assert *require.Assertions, p page.Page) { + {"empty1", func(c *qt.C, p page.Page) { // > b,c - assert.Nil(getPage(p, "/empty1/b")) // No _index.md page. - assert.NotNil(getPage(p, "/empty1/b/c")) + c.Assert(getPage(p, "/empty1/b"), qt.IsNil) // No _index.md page. + c.Assert(getPage(p, "/empty1/b/c"), qt.Not(qt.IsNil)) }}, - {"empty2", func(assert *require.Assertions, p page.Page) { + {"empty2", func(c *qt.C, p page.Page) { // > b,c,d where b and d have _index.md files. b := getPage(p, "/empty2/b") - assert.NotNil(b) - assert.Equal("T40_-1", b.Title()) + c.Assert(b, qt.Not(qt.IsNil)) + c.Assert(b.Title(), qt.Equals, "T40_-1") - c := getPage(p, "/empty2/b/c") - assert.Nil(c) // No _index.md + cp := getPage(p, "/empty2/b/c") + c.Assert(cp, qt.IsNil) // No _index.md d := getPage(p, "/empty2/b/c/d") - assert.NotNil(d) - assert.Equal("T41_-1", d.Title()) + c.Assert(d, qt.Not(qt.IsNil)) + c.Assert(d.Title(), qt.Equals, "T41_-1") - assert.False(c.Eq(d)) - assert.True(c.Eq(c)) - assert.False(c.Eq("asdf")) + c.Assert(cp.Eq(d), qt.Equals, false) + c.Assert(cp.Eq(cp), qt.Equals, true) + c.Assert(cp.Eq("asdf"), qt.Equals, false) }}, - {"empty3", func(assert *require.Assertions, p page.Page) { + {"empty3", func(c *qt.C, p page.Page) { // b,c,d with regular page in b b := getPage(p, "/empty3/b") - assert.Nil(b) // No _index.md + c.Assert(b, qt.IsNil) // No _index.md e3 := getPage(p, "/empty3/b/empty3") - assert.NotNil(e3) - assert.Equal("empty3.md", e3.File().LogicalName()) + c.Assert(e3, qt.Not(qt.IsNil)) + c.Assert(e3.File().LogicalName(), qt.Equals, "empty3.md") }}, - {"empty3", func(assert *require.Assertions, p page.Page) { + {"empty3", func(c *qt.C, p page.Page) { xxx := getPage(p, "/empty3/nil") - assert.Nil(xxx) + c.Assert(xxx, qt.IsNil) }}, - {"top", func(assert *require.Assertions, p page.Page) { - assert.Equal("Tops", p.Title()) - assert.Len(p.Pages(), 2) - assert.Equal("mypage2.md", p.Pages()[0].File().LogicalName()) - assert.Equal("mypage3.md", p.Pages()[1].File().LogicalName()) + {"top", func(c *qt.C, p page.Page) { + c.Assert(p.Title(), qt.Equals, "Tops") + c.Assert(len(p.Pages()), qt.Equals, 2) + c.Assert(p.Pages()[0].File().LogicalName(), qt.Equals, "mypage2.md") + c.Assert(p.Pages()[1].File().LogicalName(), qt.Equals, "mypage3.md") home := p.Parent() - assert.True(home.IsHome()) - assert.Len(p.Sections(), 0) - assert.Equal(home, home.CurrentSection()) + c.Assert(home.IsHome(), qt.Equals, true) + c.Assert(len(p.Sections()), qt.Equals, 0) + c.Assert(home.CurrentSection(), qt.Equals, home) active, err := home.InSection(home) - assert.NoError(err) - assert.True(active) - assert.Equal(p, p.FirstSection()) + c.Assert(err, qt.IsNil) + c.Assert(active, qt.Equals, true) + c.Assert(p.FirstSection(), qt.Equals, p) }}, - {"l1", func(assert *require.Assertions, p page.Page) { - assert.Equal("L1s", p.Title()) - assert.Len(p.Pages(), 4) // 2 pages + 2 sections - assert.True(p.Parent().IsHome()) - assert.Len(p.Sections(), 2) + {"l1", func(c *qt.C, p page.Page) { + c.Assert(p.Title(), qt.Equals, "L1s") + c.Assert(len(p.Pages()), qt.Equals, 4) // 2 pages + 2 sections + c.Assert(p.Parent().IsHome(), qt.Equals, true) + c.Assert(len(p.Sections()), qt.Equals, 2) }}, - {"l1,l2", func(assert *require.Assertions, p page.Page) { - assert.Equal("T2_-1", p.Title()) - assert.Len(p.Pages(), 4) // 3 pages + 1 section - assert.Equal(p, p.Pages()[0].Parent()) - assert.Equal("L1s", p.Parent().Title()) - assert.Equal("/l1/l2/", p.RelPermalink()) - assert.Len(p.Sections(), 1) + {"l1,l2", func(c *qt.C, p page.Page) { + c.Assert(p.Title(), qt.Equals, "T2_-1") + c.Assert(len(p.Pages()), qt.Equals, 4) // 3 pages + 1 section + c.Assert(p.Pages()[0].Parent(), qt.Equals, p) + c.Assert(p.Parent().Title(), qt.Equals, "L1s") + c.Assert(p.RelPermalink(), qt.Equals, "/l1/l2/") + c.Assert(len(p.Sections()), qt.Equals, 1) for _, child := range p.Pages() { if child.IsSection() { - assert.Equal(child, child.CurrentSection()) + c.Assert(child.CurrentSection(), qt.Equals, child) continue } - assert.Equal(p, child.CurrentSection()) + c.Assert(child.CurrentSection(), qt.Equals, p) active, err := child.InSection(p) - assert.NoError(err) + c.Assert(err, qt.IsNil) - assert.True(active) + c.Assert(active, qt.Equals, true) active, err = p.InSection(child) - assert.NoError(err) - assert.True(active) + c.Assert(err, qt.IsNil) + c.Assert(active, qt.Equals, true) active, err = p.InSection(getPage(p, "/")) - assert.NoError(err) - assert.False(active) + c.Assert(err, qt.IsNil) + c.Assert(active, qt.Equals, false) isAncestor, err := p.IsAncestor(child) - assert.NoError(err) - assert.True(isAncestor) + c.Assert(err, qt.IsNil) + c.Assert(isAncestor, qt.Equals, true) isAncestor, err = child.IsAncestor(p) - assert.NoError(err) - assert.False(isAncestor) + c.Assert(err, qt.IsNil) + c.Assert(isAncestor, qt.Equals, false) isDescendant, err := p.IsDescendant(child) - assert.NoError(err) - assert.False(isDescendant) + c.Assert(err, qt.IsNil) + c.Assert(isDescendant, qt.Equals, false) isDescendant, err = child.IsDescendant(p) - assert.NoError(err) - assert.True(isDescendant) + c.Assert(err, qt.IsNil) + c.Assert(isDescendant, qt.Equals, true) } - assert.True(p.Eq(p.CurrentSection())) + c.Assert(p.Eq(p.CurrentSection()), qt.Equals, true) }}, - {"l1,l2_2", func(assert *require.Assertions, p page.Page) { - assert.Equal("T22_-1", p.Title()) - assert.Len(p.Pages(), 2) - assert.Equal(filepath.FromSlash("l1/l2_2/page_2_2_1.md"), p.Pages()[0].File().Path()) - assert.Equal("L1s", p.Parent().Title()) - assert.Len(p.Sections(), 0) + {"l1,l2_2", func(c *qt.C, p page.Page) { + c.Assert(p.Title(), qt.Equals, "T22_-1") + c.Assert(len(p.Pages()), qt.Equals, 2) + c.Assert(p.Pages()[0].File().Path(), qt.Equals, filepath.FromSlash("l1/l2_2/page_2_2_1.md")) + c.Assert(p.Parent().Title(), qt.Equals, "L1s") + c.Assert(len(p.Sections()), qt.Equals, 0) }}, - {"l1,l2,l3", func(assert *require.Assertions, p page.Page) { + {"l1,l2,l3", func(c *qt.C, p page.Page) { nilp, _ := p.GetPage("this/does/not/exist") - assert.Equal("T3_-1", p.Title()) - assert.Len(p.Pages(), 2) - assert.Equal("T2_-1", p.Parent().Title()) - assert.Len(p.Sections(), 0) + c.Assert(p.Title(), qt.Equals, "T3_-1") + c.Assert(len(p.Pages()), qt.Equals, 2) + c.Assert(p.Parent().Title(), qt.Equals, "T2_-1") + c.Assert(len(p.Sections()), qt.Equals, 0) l1 := getPage(p, "/l1") isDescendant, err := l1.IsDescendant(p) - assert.NoError(err) - assert.False(isDescendant) + c.Assert(err, qt.IsNil) + c.Assert(isDescendant, qt.Equals, false) isDescendant, err = l1.IsDescendant(nil) - assert.NoError(err) - assert.False(isDescendant) + c.Assert(err, qt.IsNil) + c.Assert(isDescendant, qt.Equals, false) isDescendant, err = nilp.IsDescendant(p) - assert.NoError(err) - assert.False(isDescendant) + c.Assert(err, qt.IsNil) + c.Assert(isDescendant, qt.Equals, false) isDescendant, err = p.IsDescendant(l1) - assert.NoError(err) - assert.True(isDescendant) + c.Assert(err, qt.IsNil) + c.Assert(isDescendant, qt.Equals, true) isAncestor, err := l1.IsAncestor(p) - assert.NoError(err) - assert.True(isAncestor) + c.Assert(err, qt.IsNil) + c.Assert(isAncestor, qt.Equals, true) isAncestor, err = p.IsAncestor(l1) - assert.NoError(err) - assert.False(isAncestor) - assert.Equal(l1, p.FirstSection()) + c.Assert(err, qt.IsNil) + c.Assert(isAncestor, qt.Equals, false) + c.Assert(p.FirstSection(), qt.Equals, l1) isAncestor, err = p.IsAncestor(nil) - assert.NoError(err) - assert.False(isAncestor) + c.Assert(err, qt.IsNil) + c.Assert(isAncestor, qt.Equals, false) isAncestor, err = nilp.IsAncestor(l1) - assert.NoError(err) - assert.False(isAncestor) + c.Assert(err, qt.IsNil) + c.Assert(isAncestor, qt.Equals, false) }}, - {"perm a,link", func(assert *require.Assertions, p page.Page) { - assert.Equal("T9_-1", p.Title()) - assert.Equal("/perm-a/link/", p.RelPermalink()) - assert.Len(p.Pages(), 4) + {"perm a,link", func(c *qt.C, p page.Page) { + c.Assert(p.Title(), qt.Equals, "T9_-1") + c.Assert(p.RelPermalink(), qt.Equals, "/perm-a/link/") + c.Assert(len(p.Pages()), qt.Equals, 4) first := p.Pages()[0] - assert.Equal("/perm-a/link/t1_1/", first.RelPermalink()) + c.Assert(first.RelPermalink(), qt.Equals, "/perm-a/link/t1_1/") th.assertFileContent("public/perm-a/link/t1_1/index.html", "Single|T1_1") last := p.Pages()[3] - assert.Equal("/perm-a/link/t1_5/", last.RelPermalink()) + c.Assert(last.RelPermalink(), qt.Equals, "/perm-a/link/t1_5/") }}, } @@ -300,27 +300,27 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} test := test t.Run(fmt.Sprintf("sections %s", test.sections), func(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) sections := strings.Split(test.sections, ",") p := s.getPage(page.KindSection, sections...) - assert.NotNil(p, fmt.Sprint(sections)) + c.Assert(p, qt.Not(qt.IsNil)) if p.Pages() != nil { - assert.Equal(p.Pages(), p.Data().(page.Data).Pages()) + c.Assert(p.Data().(page.Data).Pages(), deepEqualsPages, p.Pages()) } - assert.NotNil(p.Parent(), fmt.Sprintf("Parent nil: %q", test.sections)) - test.verify(assert, p) + c.Assert(p.Parent(), qt.Not(qt.IsNil)) + test.verify(c, p) }) } - assert.NotNil(home) + c.Assert(home, qt.Not(qt.IsNil)) - assert.Len(home.Sections(), 9) - assert.Equal(home.Sections(), s.Info.Sections()) + c.Assert(len(home.Sections()), qt.Equals, 9) + c.Assert(s.Info.Sections(), deepEqualsPages, home.Sections()) rootPage := s.getPage(page.KindPage, "mypage.md") - assert.NotNil(rootPage) - assert.True(rootPage.Parent().IsHome()) + c.Assert(rootPage, qt.Not(qt.IsNil)) + c.Assert(rootPage.Parent().IsHome(), qt.Equals, true) // Add a odd test for this as this looks a little bit off, but I'm not in the mood // to think too hard a out this right now. It works, but people will have to spell @@ -329,8 +329,8 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} // getPage. // TODO(bep) sectionWithSpace := s.getPage(page.KindSection, "Spaces in Section") - require.NotNil(t, sectionWithSpace) - require.Equal(t, "/spaces-in-section/", sectionWithSpace.RelPermalink()) + c.Assert(sectionWithSpace, qt.Not(qt.IsNil)) + c.Assert(sectionWithSpace.RelPermalink(), qt.Equals, "/spaces-in-section/") th.assertFileContent("public/l1/l2/page/2/index.html", "L1/l2-IsActive: true", "PAG|T2_3|true") diff --git a/hugolib/site_stats_test.go b/hugolib/site_stats_test.go index bbefc9577..9c7bb240d 100644 --- a/hugolib/site_stats_test.go +++ b/hugolib/site_stats_test.go @@ -21,13 +21,13 @@ import ( "github.com/gohugoio/hugo/helpers" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestSiteStats(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) siteConfig := ` baseURL = "http://example.com/blog" @@ -93,6 +93,6 @@ aliases: [/Ali%d] helpers.ProcessingStatsTable(&buff, stats...) - assert.Contains(buff.String(), "Pages | 19 | 6") + c.Assert(buff.String(), qt.Contains, "Pages | 19 | 6") } diff --git a/hugolib/site_test.go b/hugolib/site_test.go index bbf101fc4..74424cd3d 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -24,10 +24,9 @@ import ( "github.com/gohugoio/hugo/helpers" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/resources/page" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const ( @@ -145,6 +144,7 @@ func TestLastChange(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() + c := qt.New(t) writeSource(t, fs, filepath.Join("content", "sect/doc1.md"), "---\ntitle: doc1\nweight: 1\ndate: 2014-05-29\n---\n# doc1\n*some content*") writeSource(t, fs, filepath.Join("content", "sect/doc2.md"), "---\ntitle: doc2\nweight: 2\ndate: 2015-05-29\n---\n# doc2\n*some content*") @@ -154,8 +154,8 @@ func TestLastChange(t *testing.T) { s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.False(t, s.Info.LastChange().IsZero(), "Site.LastChange is zero") - require.Equal(t, 2017, s.Info.LastChange().Year(), "Site.LastChange should be set to the page with latest Lastmod (year 2017)") + c.Assert(s.Info.LastChange().IsZero(), qt.Equals, false) + c.Assert(s.Info.LastChange().Year(), qt.Equals, 2017) } // Issue #_index @@ -163,12 +163,13 @@ func TestPageWithUnderScoreIndexInFilename(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() + c := qt.New(t) writeSource(t, fs, filepath.Join("content", "sect/my_index_file.md"), "---\ntitle: doc1\nweight: 1\ndate: 2014-05-29\n---\n# doc1\n*some content*") s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - require.Len(t, s.RegularPages(), 1) + c.Assert(len(s.RegularPages()), qt.Equals, 1) } @@ -184,6 +185,8 @@ func TestCrossrefs(t *testing.T) { func doTestCrossrefs(t *testing.T, relative, uglyURLs bool) { + c := qt.New(t) + baseURL := "http://foo/bar" var refShortcode string @@ -253,9 +256,9 @@ THE END.`, refShortcode), WithTemplate: createWithTemplateFromNameValues("_default/single.html", "{{.Content}}")}, BuildCfg{}) - require.Len(t, s.RegularPages(), 4) + c.Assert(len(s.RegularPages()), qt.Equals, 4) - th := testHelper{s.Cfg, s.Fs, t} + th := newTestHelper(s.Cfg, s.Fs, t) tests := []struct { doc string @@ -286,6 +289,7 @@ func TestShouldAlwaysHaveUglyURLs(t *testing.T) { func doTestShouldAlwaysHaveUglyURLs(t *testing.T, uglyURLs bool) { cfg, fs := newTestCfg() + c := qt.New(t) cfg.Set("verbose", true) cfg.Set("baseURL", "http://auth/bub") @@ -333,7 +337,7 @@ func doTestShouldAlwaysHaveUglyURLs(t *testing.T, uglyURLs bool) { } for _, p := range s.RegularPages() { - assert.False(t, p.IsHome()) + c.Assert(p.IsHome(), qt.Equals, false) } for _, test := range tests { @@ -355,7 +359,7 @@ func TestShouldNotWriteZeroLengthFilesToDestination(t *testing.T) { writeSource(t, fs, filepath.Join("layouts", "_default/list.html"), "") s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) - th := testHelper{s.Cfg, s.Fs, t} + th := newTestHelper(s.Cfg, s.Fs, t) th.assertFileNotExist(filepath.Join("public", "index.html")) } @@ -378,6 +382,7 @@ func TestSectionNaming(t *testing.T) { } func doTestSectionNaming(t *testing.T, canonify, uglify, pluralize bool) { + c := qt.New(t) var expectedPathSuffix string @@ -412,10 +417,10 @@ func doTestSectionNaming(t *testing.T, canonify, uglify, pluralize bool) { s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) mainSections, err := s.Info.Param("mainSections") - require.NoError(t, err) - require.Equal(t, []string{"sect"}, mainSections) + c.Assert(err, qt.IsNil) + c.Assert(mainSections, qt.DeepEquals, []string{"sect"}) - th := testHelper{s.Cfg, s.Fs, t} + th := newTestHelper(s.Cfg, s.Fs, t) tests := []struct { doc string pluralAware bool @@ -527,7 +532,7 @@ func TestAbsURLify(t *testing.T) { writeSource(t, fs, filepath.Join("layouts", "blue/single.html"), templateWithURLAbs) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) - th := testHelper{s.Cfg, s.Fs, t} + th := newTestHelper(s.Cfg, s.Fs, t) tests := []struct { file, expected string diff --git a/hugolib/site_url_test.go b/hugolib/site_url_test.go index 9827f994b..c51285eb4 100644 --- a/hugolib/site_url_test.go +++ b/hugolib/site_url_test.go @@ -22,8 +22,8 @@ import ( "html/template" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" - "github.com/stretchr/testify/require" ) const slugDoc1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\naliases:\n - /sd1/foo/\n - /sd2\n - /sd3/\n - /sd4.html\n---\nslug doc 1 content\n" @@ -43,6 +43,8 @@ var urlFakeSource = [][2]string{ // Issue #1105 func TestShouldNotAddTrailingSlashToBaseURL(t *testing.T) { t.Parallel() + c := qt.New(t) + for i, this := range []struct { in string expected string @@ -56,8 +58,8 @@ func TestShouldNotAddTrailingSlashToBaseURL(t *testing.T) { cfg.Set("baseURL", this.in) d := deps.DepsCfg{Cfg: cfg, Fs: fs} s, err := NewSiteForCfg(d) - require.NoError(t, err) - require.NoError(t, s.initializeSiteInfo()) + c.Assert(err, qt.IsNil) + c.Assert(s.initializeSiteInfo(), qt.IsNil) if s.Info.BaseURL() != template.URL(this.expected) { t.Errorf("[%d] got %s expected %s", i, s.Info.BaseURL(), this.expected) @@ -94,7 +96,7 @@ func TestPageCount(t *testing.T) { func TestUglyURLsPerSection(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) const dt = `--- title: Do not go gentle into that good night @@ -117,23 +119,23 @@ Do not go gentle into that good night. s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) - assert.Len(s.RegularPages(), 2) + c.Assert(len(s.RegularPages()), qt.Equals, 2) notUgly := s.getPage(page.KindPage, "sect1/p1.md") - assert.NotNil(notUgly) - assert.Equal("sect1", notUgly.Section()) - assert.Equal("/sect1/p1/", notUgly.RelPermalink()) + c.Assert(notUgly, qt.Not(qt.IsNil)) + c.Assert(notUgly.Section(), qt.Equals, "sect1") + c.Assert(notUgly.RelPermalink(), qt.Equals, "/sect1/p1/") ugly := s.getPage(page.KindPage, "sect2/p2.md") - assert.NotNil(ugly) - assert.Equal("sect2", ugly.Section()) - assert.Equal("/sect2/p2.html", ugly.RelPermalink()) + c.Assert(ugly, qt.Not(qt.IsNil)) + c.Assert(ugly.Section(), qt.Equals, "sect2") + c.Assert(ugly.RelPermalink(), qt.Equals, "/sect2/p2.html") } func TestSectionWithURLInFrontMatter(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) const st = `--- title: Do not go gentle into that good night @@ -157,7 +159,7 @@ Do not go gentle into that good night. ` cfg, fs := newTestCfg() - th := testHelper{cfg, fs, t} + th := newTestHelper(cfg, fs, t) cfg.Set("paginate", 1) @@ -175,11 +177,11 @@ Do not go gentle into that good night. s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) - assert.Len(s.RegularPages(), 10) + c.Assert(len(s.RegularPages()), qt.Equals, 10) sect1 := s.getPage(page.KindSection, "sect1") - assert.NotNil(sect1) - assert.Equal("/ss1/", sect1.RelPermalink()) + c.Assert(sect1, qt.Not(qt.IsNil)) + c.Assert(sect1.RelPermalink(), qt.Equals, "/ss1/") th.assertFileContent(filepath.Join("public", "ss1", "index.html"), "P1|URL: /ss1/|Next: /ss1/page/2/") th.assertFileContent(filepath.Join("public", "ss1", "page", "2", "index.html"), "P2|URL: /ss1/page/2/|Next: /ss1/page/3/") diff --git a/hugolib/sitemap_test.go b/hugolib/sitemap_test.go index 5aba6f09d..4dfb61ecd 100644 --- a/hugolib/sitemap_test.go +++ b/hugolib/sitemap_test.go @@ -18,10 +18,10 @@ import ( "reflect" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl" - "github.com/stretchr/testify/require" ) const sitemapTemplate = `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> @@ -44,6 +44,7 @@ func TestSitemapOutput(t *testing.T) { func doTestSitemapOutput(t *testing.T, internal bool) { + c := qt.New(t) cfg, fs := newTestCfg() cfg.Set("baseURL", "http://auth/bub/") @@ -63,7 +64,7 @@ func doTestSitemapOutput(t *testing.T, internal bool) { writeSourcesToSource(t, "content", fs, weightedSources...) s := buildSingleSite(t, depsCfg, BuildCfg{}) - th := testHelper{s.Cfg, s.Fs, t} + th := newTestHelper(s.Cfg, s.Fs, t) outputSitemap := "public/sitemap.xml" th.assertFileContent(outputSitemap, @@ -79,8 +80,8 @@ func doTestSitemapOutput(t *testing.T, internal bool) { "<loc>http://auth/bub/categories/hugo/</loc>", ) - content := readDestination(th.T, th.Fs, outputSitemap) - require.NotContains(t, content, "404") + content := readDestination(th, th.Fs, outputSitemap) + c.Assert(content, qt.Not(qt.Contains), "404") } diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go index 21748d0bf..ccad3a207 100644 --- a/hugolib/taxonomy_test.go +++ b/hugolib/taxonomy_test.go @@ -23,7 +23,7 @@ import ( "strings" "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" ) @@ -167,37 +167,37 @@ permalinkeds: for taxonomy, count := range taxonomyTermPageCounts { term := s.getPage(page.KindTaxonomyTerm, taxonomy) - require.NotNil(t, term) - require.Len(t, term.Pages(), count, taxonomy) + b.Assert(term, qt.Not(qt.IsNil)) + b.Assert(len(term.Pages()), qt.Equals, count, qt.Commentf(taxonomy)) for _, p := range term.Pages() { - require.Equal(t, page.KindTaxonomy, p.Kind()) + b.Assert(p.Kind(), qt.Equals, page.KindTaxonomy) } } cat1 := s.getPage(page.KindTaxonomy, "categories", "cat1") - require.NotNil(t, cat1) + b.Assert(cat1, qt.Not(qt.IsNil)) if uglyURLs { - require.Equal(t, "/blog/categories/cat1.html", cat1.RelPermalink()) + b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1.html") } else { - require.Equal(t, "/blog/categories/cat1/", cat1.RelPermalink()) + b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1/") } pl1 := s.getPage(page.KindTaxonomy, "permalinkeds", "pl1") permalinkeds := s.getPage(page.KindTaxonomyTerm, "permalinkeds") - require.NotNil(t, pl1) - require.NotNil(t, permalinkeds) + b.Assert(pl1, qt.Not(qt.IsNil)) + b.Assert(permalinkeds, qt.Not(qt.IsNil)) if uglyURLs { - require.Equal(t, "/blog/perma/pl1.html", pl1.RelPermalink()) - require.Equal(t, "/blog/permalinkeds.html", permalinkeds.RelPermalink()) + b.Assert(pl1.RelPermalink(), qt.Equals, "/blog/perma/pl1.html") + b.Assert(permalinkeds.RelPermalink(), qt.Equals, "/blog/permalinkeds.html") } else { - require.Equal(t, "/blog/perma/pl1/", pl1.RelPermalink()) - require.Equal(t, "/blog/permalinkeds/", permalinkeds.RelPermalink()) + b.Assert(pl1.RelPermalink(), qt.Equals, "/blog/perma/pl1/") + b.Assert(permalinkeds.RelPermalink(), qt.Equals, "/blog/permalinkeds/") } helloWorld := s.getPage(page.KindTaxonomy, "others", "hello-hugo-world") - require.NotNil(t, helloWorld) - require.Equal(t, "Hello Hugo world", helloWorld.Title()) + b.Assert(helloWorld, qt.Not(qt.IsNil)) + b.Assert(helloWorld.Title(), qt.Equals, "Hello Hugo world") // Issue #2977 b.AssertFileContent(pathFunc("public/empties/index.html"), "Taxonomy Term Page", "Empties") @@ -209,8 +209,6 @@ permalinkeds: func TestTaxonomiesPathSeparation(t *testing.T) { t.Parallel() - assert := require.New(t) - config := ` baseURL = "https://example.com" [taxonomies] @@ -263,8 +261,8 @@ title: "This is S3s" ta := s.findPagesByKind(page.KindTaxonomy) te := s.findPagesByKind(page.KindTaxonomyTerm) - assert.Equal(4, len(te)) - assert.Equal(7, len(ta)) + b.Assert(len(te), qt.Equals, 4) + b.Assert(len(ta), qt.Equals, 7) b.AssertFileContent("public/news/categories/a/index.html", "Taxonomy List Page 1|a|Hello|https://example.com/news/categories/a/|") b.AssertFileContent("public/news/categories/b/index.html", "Taxonomy List Page 1|This is B|Hello|https://example.com/news/categories/b/|") diff --git a/hugolib/template_engines_test.go b/hugolib/template_engines_test.go index ec229a299..ebfb0b428 100644 --- a/hugolib/template_engines_test.go +++ b/hugolib/template_engines_test.go @@ -97,7 +97,7 @@ Shortcode: {{< myShort >}} writeSource(t, fs, filepath.Join("layouts", "shortcodes", fmt.Sprintf("myShort.%s", suffix)), shortcodeTempl) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) - th := testHelper{s.Cfg, s.Fs, t} + th := newTestHelper(s.Cfg, s.Fs, t) th.assertFileContent(filepath.Join("public", "p", "index.html"), "Page Title: My Title", diff --git a/hugolib/template_test.go b/hugolib/template_test.go index 6ed9643c7..de93f1c80 100644 --- a/hugolib/template_test.go +++ b/hugolib/template_test.go @@ -196,7 +196,7 @@ func TestTemplateLookupOrder(t *testing.T) { t.Run(this.name, func(t *testing.T) { // TODO(bep) there are some function vars need to pull down here to enable => t.Parallel() cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} + th = newTestHelper(cfg, fs, t) for i := 1; i <= 3; i++ { writeSource(t, fs, filepath.Join("content", fmt.Sprintf("sect%d", i), fmt.Sprintf("page%d.md", i)), `--- diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 25ebbf125..e7d3b99fb 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -8,7 +8,10 @@ import ( "testing" "unicode/utf8" + "github.com/gohugoio/hugo/output" + "github.com/gohugoio/hugo/parser/metadecoders" + "github.com/google/go-cmp/cmp" "github.com/gohugoio/hugo/parser" "github.com/pkg/errors" @@ -36,10 +39,16 @@ import ( "github.com/gohugoio/hugo/resources/resource" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/hugofs" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" +) + +var ( + deepEqualsPages = qt.CmpEquals(cmp.Comparer(func(p1, p2 *pageState) bool { return p1 == p2 })) + deepEqualsOutputFormats = qt.CmpEquals(cmp.Comparer(func(o1, o2 output.Format) bool { + return o1.Name == o2.Name && o1.MediaType.Type() == o2.MediaType.Type() + })) ) type sitesBuilder struct { @@ -50,7 +59,7 @@ type sitesBuilder struct { T testing.TB depsCfg deps.DepsCfg - *require.Assertions + *qt.C logger *loggers.Logger @@ -101,11 +110,11 @@ func newTestSitesBuilder(t testing.TB) *sitesBuilder { Separator: " ", } - return &sitesBuilder{T: t, Assertions: require.New(t), Fs: fs, configFormat: "toml", dumper: litterOptions} + return &sitesBuilder{T: t, C: qt.New(t), Fs: fs, configFormat: "toml", dumper: litterOptions} } func newTestSitesBuilderFromDepsCfg(t testing.TB, d deps.DepsCfg) *sitesBuilder { - assert := require.New(t) + c := qt.New(t) litterOptions := litter.Options{ HidePrivateFields: true, @@ -113,7 +122,7 @@ func newTestSitesBuilderFromDepsCfg(t testing.TB, d deps.DepsCfg) *sitesBuilder Separator: " ", } - b := &sitesBuilder{T: t, Assertions: assert, depsCfg: d, Fs: d.Fs, dumper: litterOptions} + b := &sitesBuilder{T: t, C: c, depsCfg: d, Fs: d.Fs, dumper: litterOptions} workingDir := d.Cfg.GetString("workingDir") b.WithWorkingDir(workingDir) @@ -177,7 +186,7 @@ func (s *sitesBuilder) WithViper(v *viper.Viper) *sitesBuilder { // Write to a config file to make sure the tests follow the same code path. var buff bytes.Buffer m := v.AllSettings() - s.Assertions.NoError(parser.InterfaceToConfig(m, metadecoders.TOML, &buff)) + s.Assert(parser.InterfaceToConfig(m, metadecoders.TOML, &buff), qt.IsNil) return s.WithConfigFile("toml", buff.String()) } @@ -323,13 +332,13 @@ lag = "lag" func (s *sitesBuilder) WithSunset(in string) { // Write a real image into one of the bundle above. src, err := os.Open(filepath.FromSlash("testdata/sunset.jpg")) - s.NoError(err) + s.Assert(err, qt.IsNil) out, err := s.Fs.Source.Create(filepath.FromSlash(in)) - s.NoError(err) + s.Assert(err, qt.IsNil) _, err = io.Copy(out, src) - s.NoError(err) + s.Assert(err, qt.IsNil) out.Close() src.Close() @@ -630,10 +639,6 @@ func (s *sitesBuilder) Fatalf(format string, args ...interface{}) { s.T.Fatalf(format, args...) } -func stackTrace() string { - return strings.Join(assert.CallerInfo(), "\n\r\t\t\t") -} - func (s *sitesBuilder) AssertFileContentFn(filename string, f func(s string) bool) { s.T.Helper() content := s.FileContent(filename) @@ -698,36 +703,44 @@ func (s *sitesBuilder) CheckExists(filename string) bool { return destinationExists(s.Fs, filepath.Clean(filename)) } +func newTestHelper(cfg config.Provider, fs *hugofs.Fs, t testing.TB) testHelper { + return testHelper{ + Cfg: cfg, + Fs: fs, + C: qt.New(t), + } +} + type testHelper struct { Cfg config.Provider Fs *hugofs.Fs - T testing.TB + *qt.C } func (th testHelper) assertFileContent(filename string, matches ...string) { - th.T.Helper() + th.Helper() filename = th.replaceDefaultContentLanguageValue(filename) - content := readDestination(th.T, th.Fs, filename) + content := readDestination(th, th.Fs, filename) for _, match := range matches { match = th.replaceDefaultContentLanguageValue(match) - require.True(th.T, strings.Contains(content, match), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1))) + th.Assert(strings.Contains(content, match), qt.Equals, true) } } func (th testHelper) assertFileContentRegexp(filename string, matches ...string) { filename = th.replaceDefaultContentLanguageValue(filename) - content := readDestination(th.T, th.Fs, filename) + content := readDestination(th, th.Fs, filename) for _, match := range matches { match = th.replaceDefaultContentLanguageValue(match) r := regexp.MustCompile(match) - require.True(th.T, r.MatchString(content), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1))) + th.Assert(r.MatchString(content), qt.Equals, true) } } func (th testHelper) assertFileNotExist(filename string) { exists, err := helpers.Exists(filename, th.Fs.Destination) - require.NoError(th.T, err) - require.False(th.T, exists) + th.Assert(err, qt.IsNil) + th.Assert(exists, qt.Equals, false) } func (th testHelper) replaceDefaultContentLanguageValue(value string) string { @@ -786,14 +799,16 @@ func newTestSitesFromConfig(t testing.TB, afs afero.Fs, tomlConfig string, layou t.Fatalf("Layouts must be provided in pairs") } + c := qt.New(t) + writeToFs(t, afs, filepath.Join("content", ".gitkeep"), "") writeToFs(t, afs, "config.toml", tomlConfig) cfg, err := LoadConfigDefault(afs) - require.NoError(t, err) + c.Assert(err, qt.IsNil) fs := hugofs.NewFrom(afs, cfg) - th := testHelper{cfg, fs, t} + th := newTestHelper(cfg, fs, t) for i := 0; i < len(layoutPathContentPairs); i += 2 { writeSource(t, fs, layoutPathContentPairs[i], layoutPathContentPairs[i+1]) @@ -801,7 +816,7 @@ func newTestSitesFromConfig(t testing.TB, afs afero.Fs, tomlConfig string, layou h, err := NewHugoSites(deps.DepsCfg{Fs: fs, Cfg: cfg}) - require.NoError(t, err) + c.Assert(err, qt.IsNil) return th, h } @@ -821,6 +836,7 @@ func createWithTemplateFromNameValues(additionalTemplates ...string) func(templ // TODO(bep) replace these with the builder func buildSingleSite(t testing.TB, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site { + t.Helper() return buildSingleSiteExpected(t, false, false, depsCfg, buildCfg) } @@ -831,23 +847,23 @@ func buildSingleSiteExpected(t testing.TB, expectSiteInitEror, expectBuildError err := b.CreateSitesE() if expectSiteInitEror { - require.Error(t, err) + b.Assert(err, qt.Not(qt.IsNil)) return nil } else { - require.NoError(t, err) + b.Assert(err, qt.IsNil) } h := b.H - require.Len(t, h.Sites, 1) + b.Assert(len(h.Sites), qt.Equals, 1) if expectBuildError { - require.Error(t, h.Build(buildCfg)) + b.Assert(h.Build(buildCfg), qt.Not(qt.IsNil)) return nil } - require.NoError(t, h.Build(buildCfg)) + b.Assert(h.Build(buildCfg), qt.IsNil) return h.Sites[0] } |