diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-10 21:05:17 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-12 13:26:32 +0200 |
commit | 9e571827055dedb46b78c5db3d17d6913f14870b (patch) | |
tree | f5f0108afe0c9385ff6dc27664943d9f719f57ad /hugolib/hugo_sites_build_errors_test.go | |
parent | 6027ee11082d0b9d72de1d4d1980a702be294ad2 (diff) |
tests: Convert from testify to quicktest
Diffstat (limited to 'hugolib/hugo_sites_build_errors_test.go')
-rw-r--r-- | hugolib/hugo_sites_build_errors_test.go | 68 |
1 files changed, 34 insertions, 34 deletions
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) } } }) |