diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-10 22:05:17 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-12 14:26:32 +0300 |
commit | 9e571827055dedb46b78c5db3d17d6913f14870b (patch) | |
tree | f5f0108afe0c9385ff6dc27664943d9f719f57ad /tpl | |
parent | 6027ee11082d0b9d72de1d4d1980a702be294ad2 (diff) |
tests: Convert from testify to quicktest
Diffstat (limited to 'tpl')
57 files changed, 876 insertions, 842 deletions
diff --git a/tpl/cast/cast_test.go b/tpl/cast/cast_test.go index fc20934f8..c6219728b 100644 --- a/tpl/cast/cast_test.go +++ b/tpl/cast/cast_test.go @@ -14,16 +14,15 @@ package cast import ( - "fmt" "html/template" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestToInt(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() @@ -40,23 +39,23 @@ func TestToInt(t *testing.T) { {"a", false}, {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.v) + errMsg := qt.Commentf("[%d] %v", i, test.v) result, err := ns.ToInt(test.v) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestToString(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New() for i, test := range []struct { @@ -68,23 +67,23 @@ func TestToString(t *testing.T) { {"a", "a"}, {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.v) + errMsg := qt.Commentf("[%d] %v", i, test.v) result, err := ns.ToString(test.v) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestToFloat(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New() for i, test := range []struct { @@ -105,16 +104,16 @@ func TestToFloat(t *testing.T) { {2, 2.0}, {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.v) + errMsg := qt.Commentf("[%d] %v", i, test.v) result, err := ns.ToFloat(test.v) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } diff --git a/tpl/cast/init_test.go b/tpl/cast/init_test.go index 47cbd3d0b..73d9d5adc 100644 --- a/tpl/cast/init_test.go +++ b/tpl/cast/init_test.go @@ -16,12 +16,15 @@ package cast import ( "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +36,7 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) + } diff --git a/tpl/collections/append_test.go b/tpl/collections/append_test.go index f886aca22..a254601b4 100644 --- a/tpl/collections/append_test.go +++ b/tpl/collections/append_test.go @@ -14,17 +14,17 @@ package collections import ( - "fmt" "reflect" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" - "github.com/stretchr/testify/require" ) // Also see tests in common/collection. func TestAppend(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -45,18 +45,18 @@ func TestAppend(t *testing.T) { false}, } { - errMsg := fmt.Sprintf("[%d]", i) + errMsg := qt.Commentf("[%d]", i) args := append(test.addend, test.start) result, err := ns.Append(args...) if b, ok := test.expected.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) + c.Assert(err, qt.IsNil, errMsg) if !reflect.DeepEqual(test.expected, result) { t.Fatalf("%s got\n%T: %v\nexpected\n%T: %v", errMsg, result, result, test.expected, test.expected) diff --git a/tpl/collections/apply_test.go b/tpl/collections/apply_test.go index edec3da18..96dd8896b 100644 --- a/tpl/collections/apply_test.go +++ b/tpl/collections/apply_test.go @@ -18,9 +18,9 @@ import ( "fmt" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl" - "github.com/stretchr/testify/require" ) type templateFinder int @@ -41,24 +41,25 @@ func (templateFinder) GetFuncs() map[string]interface{} { func TestApply(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{Tmpl: new(templateFinder)}) strings := []interface{}{"a\n", "b\n"} result, err := ns.Apply(strings, "print", "a", "b", "c") - require.NoError(t, err) - require.Equal(t, []interface{}{"abc", "abc"}, result, "testing variadic") + c.Assert(err, qt.IsNil) + c.Assert(result, qt.DeepEquals, []interface{}{"abc", "abc"}) _, err = ns.Apply(strings, "apply", ".") - require.Error(t, err) + c.Assert(err, qt.Not(qt.IsNil)) var nilErr *error _, err = ns.Apply(nilErr, "chomp", ".") - require.Error(t, err) + c.Assert(err, qt.Not(qt.IsNil)) _, err = ns.Apply(strings, "dobedobedo", ".") - require.Error(t, err) + c.Assert(err, qt.Not(qt.IsNil)) _, err = ns.Apply(strings, "foo.Chomp", "c\n") if err == nil { diff --git a/tpl/collections/collections_test.go b/tpl/collections/collections_test.go index 662536a24..8ea973f0b 100644 --- a/tpl/collections/collections_test.go +++ b/tpl/collections/collections_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/deps" @@ -29,14 +30,13 @@ import ( "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/langs" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) type tstNoStringer struct{} func TestAfter(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -58,17 +58,17 @@ func TestAfter(t *testing.T) { {1, t, false}, {1, (*string)(nil), false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.After(test.index, test.seq) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - require.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) } } @@ -92,7 +92,7 @@ func (g *tstGrouper2) Group(key interface{}, items interface{}) (interface{}, er func TestGroup(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New(&deps.Deps{}) for i, test := range []struct { @@ -111,22 +111,23 @@ func TestGroup(t *testing.T) { {"a", nil, false}, {nil, []*tstGrouper{{}, {}}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.Group(test.key, test.items) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - require.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestDelimit(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -161,7 +162,7 @@ func TestDelimit(t *testing.T) { {map[int]string{3: "10", 2: "20", 1: "30", 4: "40", 5: "50"}, "--", "--and--", "30--20--10--40--and--50"}, {map[float64]string{3.5: "10", 2.5: "20", 1.5: "30", 4.5: "40", 5.5: "50"}, "--", "--and--", "30--20--10--40--and--50"}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) var result template.HTML var err error @@ -172,13 +173,14 @@ func TestDelimit(t *testing.T) { result, err = ns.Delimit(test.seq, test.delimiter, test.last) } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestDictionary(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -192,22 +194,23 @@ func TestDictionary(t *testing.T) { {[]interface{}{5, "b"}, false}, {[]interface{}{"a", "b", "c"}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.values) + errMsg := qt.Commentf("[%d] %v", i, test.values) result, err := ns.Dictionary(test.values...) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) } } func TestEchoParam(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -229,16 +232,17 @@ func TestEchoParam(t *testing.T) { {map[string]interface{}{"foo": nil}, "foo", ""}, {(*[]string)(nil), "bar", ""}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result := ns.EchoParam(test.a, test.key) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestFirst(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -260,23 +264,23 @@ func TestFirst(t *testing.T) { {1, t, false}, {1, (*string)(nil), false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.First(test.limit, test.seq) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) } } func TestIn(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) ns := New(&deps.Deps{}) @@ -311,16 +315,16 @@ func TestIn(t *testing.T) { {pagesVals{p3v, p2v, p3v, p2v}, p4v, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.In(test.l1, test.l2) - assert.NoError(err) - assert.Equal(test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect, errMsg) } // Slices are not comparable _, err := ns.In([]string{"a", "b"}, []string{"a", "b"}) - assert.Error(err) + c.Assert(err, qt.Not(qt.IsNil)) } type testPage struct { @@ -348,6 +352,7 @@ var ( func TestIntersect(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -420,16 +425,16 @@ func TestIntersect(t *testing.T) { {[]int{1, 1}, [][]int{{1, 2}, {1, 2}, {1, 3}}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.Intersect(test.l1, test.l2) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - assert.NoError(t, err, errMsg) + c.Assert(err, qt.IsNil, errMsg) if !reflect.DeepEqual(result, test.expect) { t.Fatalf("[%d] Got\n%v expected\n%v", i, result, test.expect) } @@ -438,7 +443,7 @@ func TestIntersect(t *testing.T) { func TestIsSet(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := newTestNs() for i, test := range []struct { @@ -460,20 +465,21 @@ func TestIsSet(t *testing.T) { {nil, "nil", false, false}, {[]interface{}{1, 2, 3, 5}, TstX{}, false, true}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.IsSet(test.a, test.key) if test.isErr { continue } - assert.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestLast(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -495,23 +501,23 @@ func TestLast(t *testing.T) { {1, t, false}, {1, (*string)(nil), false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.Last(test.limit, test.seq) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) } } func TestQuerify(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New(&deps.Deps{}) for i, test := range []struct { @@ -524,23 +530,23 @@ func TestQuerify(t *testing.T) { {[]interface{}{5, "b"}, false}, {[]interface{}{"a", "b", "c"}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.params) + errMsg := qt.Commentf("[%d] %v", i, test.params) result, err := ns.Querify(test.params...) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestSeq(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New(&deps.Deps{}) for i, test := range []struct { @@ -568,23 +574,23 @@ func TestSeq(t *testing.T) { {[]interface{}{tstNoStringer{}}, false}, {nil, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.Seq(test.args...) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) } } func TestShuffle(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New(&deps.Deps{}) for i, test := range []struct { @@ -604,27 +610,27 @@ func TestShuffle(t *testing.T) { {t, false}, {(*string)(nil), false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.Shuffle(test.seq) if !test.success { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) + c.Assert(err, qt.IsNil, errMsg) resultv := reflect.ValueOf(result) seqv := reflect.ValueOf(test.seq) - assert.Equal(t, resultv.Len(), seqv.Len(), errMsg) + c.Assert(seqv.Len(), qt.Equals, resultv.Len(), errMsg) } } func TestShuffleRandomising(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New(&deps.Deps{}) // Note that this test can fail with false negative result if the shuffle @@ -641,21 +647,21 @@ func TestShuffleRandomising(t *testing.T) { result, err := ns.Shuffle(test.seq) resultv := reflect.ValueOf(result) - require.NoError(t, err) + c.Assert(err, qt.IsNil) allSame := true for i, v := range test.seq { allSame = allSame && (resultv.Index(i).Interface() == v) } - assert.False(t, allSame, "Expected sequence to be shuffled but was in the same order") + c.Assert(allSame, qt.Equals, false) } } // Also see tests in commons/collection. func TestSlice(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New(&deps.Deps{}) for i, test := range []struct { @@ -668,18 +674,18 @@ func TestSlice(t *testing.T) { {[]interface{}{5, "b"}, []interface{}{5, "b"}}, {[]interface{}{tstNoStringer{}}, []tstNoStringer{{}}}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.args) + errMsg := qt.Commentf("[%d] %v", i, test.args) result := ns.Slice(test.args...) - assert.Equal(t, test.expected, result, errMsg) + c.Assert(result, qt.DeepEquals, test.expected, errMsg) } - assert.Len(t, ns.Slice(), 0) } func TestUnion(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -752,15 +758,15 @@ func TestUnion(t *testing.T) { {[][]int{{1, 1}, {1, 2}}, [][]int{{2, 1}, {2, 2}}, false, true}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.Union(test.l1, test.l2) if test.isErr { - assert.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - assert.NoError(t, err, errMsg) + c.Assert(err, qt.IsNil, errMsg) if !reflect.DeepEqual(result, test.expect) { t.Fatalf("[%d] Got\n%v expected\n%v", i, result, test.expect) } @@ -769,7 +775,7 @@ func TestUnion(t *testing.T) { func TestUniq(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New(&deps.Deps{}) for i, test := range []struct { l interface{} @@ -798,16 +804,16 @@ func TestUniq(t *testing.T) { {1, 1, true}, {"foo", "fo", true}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.Uniq(test.l) if test.isErr { - assert.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - assert.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) } } diff --git a/tpl/collections/complement_test.go b/tpl/collections/complement_test.go index 07611bd5b..abe572b6e 100644 --- a/tpl/collections/complement_test.go +++ b/tpl/collections/complement_test.go @@ -14,13 +14,12 @@ package collections import ( - "fmt" "reflect" "testing" "github.com/gohugoio/hugo/deps" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) type StructWithSlice struct { @@ -33,7 +32,7 @@ type StructWithSlicePointers []*StructWithSlice func TestComplement(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) ns := New(&deps.Deps{}) @@ -69,18 +68,18 @@ func TestComplement(t *testing.T) { {[]interface{}{[][]string{{"c", "d"}}}, []interface{}{[]string{"c", "d"}, []string{"a", "b"}}, false}, } { - errMsg := fmt.Sprintf("[%d]", i) + errMsg := qt.Commentf("[%d]", i) args := append(test.t, test.s) result, err := ns.Complement(args...) if b, ok := test.expected.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) + c.Assert(err, qt.IsNil, errMsg) if !reflect.DeepEqual(test.expected, result) { t.Fatalf("%s got\n%T: %v\nexpected\n%T: %v", errMsg, result, result, test.expected, test.expected) @@ -88,8 +87,8 @@ func TestComplement(t *testing.T) { } _, err := ns.Complement() - assert.Error(err) + c.Assert(err, qt.Not(qt.IsNil)) _, err = ns.Complement([]string{"a", "b"}) - assert.Error(err) + c.Assert(err, qt.Not(qt.IsNil)) } diff --git a/tpl/collections/index_test.go b/tpl/collections/index_test.go index bd752d666..fdc66a0ae 100644 --- a/tpl/collections/index_test.go +++ b/tpl/collections/index_test.go @@ -14,17 +14,15 @@ package collections import ( - "fmt" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestIndex(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New(&deps.Deps{}) for i, test := range []struct { @@ -45,16 +43,16 @@ func TestIndex(t *testing.T) { {[]int{0, 1}, []interface{}{nil}, nil, true}, {tstNoStringer{}, []interface{}{0}, nil, true}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.Index(test.item, test.indices...) if test.isErr { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) } } diff --git a/tpl/collections/init_test.go b/tpl/collections/init_test.go index 0739f0412..3a3b2070f 100644 --- a/tpl/collections/init_test.go +++ b/tpl/collections/init_test.go @@ -16,12 +16,15 @@ package collections import ( "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +36,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/collections/merge_test.go b/tpl/collections/merge_test.go index ca55107ac..a08e0021b 100644 --- a/tpl/collections/merge_test.go +++ b/tpl/collections/merge_test.go @@ -25,8 +25,8 @@ import ( "github.com/gohugoio/hugo/parser/metadecoders" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" - "github.com/stretchr/testify/require" ) func TestMerge(t *testing.T) { @@ -69,27 +69,27 @@ func TestMerge(t *testing.T) { t.Run(test.name, func(t *testing.T) { t.Parallel() - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) - assert := require.New(t) + c := qt.New(t) srcStr, dstStr := fmt.Sprint(test.src), fmt.Sprint(test.dst) result, err := ns.Merge(test.src, test.dst) if test.isErr { - assert.Error(err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) return } - assert.NoError(err, errMsg) - assert.Equal(test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) // map sort in fmt was fixed in go 1.12. if !strings.HasPrefix(runtime.Version(), "go1.11") { // Verify that the original maps are preserved. - assert.Equal(srcStr, fmt.Sprint(test.src)) - assert.Equal(dstStr, fmt.Sprint(test.dst)) + c.Assert(fmt.Sprint(test.src), qt.Equals, srcStr) + c.Assert(fmt.Sprint(test.dst), qt.Equals, dstStr) } }) @@ -97,7 +97,7 @@ func TestMerge(t *testing.T) { } func TestMergeDataFormats(t *testing.T) { - assert := require.New(t) + c := qt.New(t) ns := New(&deps.Deps{}) toml1 := ` @@ -119,33 +119,38 @@ V22 = "v22_2" ` meta1, err := metadecoders.Default.UnmarshalToMap([]byte(toml1), metadecoders.TOML) - assert.NoError(err) + c.Assert(err, qt.IsNil) meta2, err := metadecoders.Default.UnmarshalToMap([]byte(toml2), metadecoders.TOML) - assert.NoError(err) + c.Assert(err, qt.IsNil) for _, format := range []metadecoders.Format{metadecoders.JSON, metadecoders.YAML, metadecoders.TOML} { var dataStr1, dataStr2 bytes.Buffer err = parser.InterfaceToConfig(meta1, format, &dataStr1) - assert.NoError(err) + c.Assert(err, qt.IsNil) err = parser.InterfaceToConfig(meta2, format, &dataStr2) - assert.NoError(err) + c.Assert(err, qt.IsNil) dst, err := metadecoders.Default.UnmarshalToMap(dataStr1.Bytes(), format) - assert.NoError(err) + c.Assert(err, qt.IsNil) src, err := metadecoders.Default.UnmarshalToMap(dataStr2.Bytes(), format) - assert.NoError(err) + c.Assert(err, qt.IsNil) merged, err := ns.Merge(src, dst) - assert.NoError(err) - - assert.Equal(map[string]interface{}{"V1": "v1_1", "V2": "v2_2", "V2s": map[string]interface{}{"V21": "v21_1", "V22": "v22_2"}}, merged) + c.Assert(err, qt.IsNil) + + c.Assert( + merged, + qt.DeepEquals, + map[string]interface{}{ + "V1": "v1_1", "V2": "v2_2", + "V2s": map[string]interface{}{"V21": "v21_1", "V22": "v22_2"}}) } } func TestCaseInsensitiveMapLookup(t *testing.T) { - assert := require.New(t) + c := qt.New(t) m1 := reflect.ValueOf(map[string]interface{}{ "a": 1, @@ -160,14 +165,14 @@ func TestCaseInsensitiveMapLookup(t *testing.T) { var found bool a, found := caseInsensitiveLookup(m1, reflect.ValueOf("A")) - assert.True(found) - assert.Equal(1, a.Interface()) + c.Assert(found, qt.Equals, true) + c.Assert(a.Interface(), qt.Equals, 1) b, found := caseInsensitiveLookup(m1, reflect.ValueOf("b")) - assert.True(found) - assert.Equal(2, b.Interface()) + c.Assert(found, qt.Equals, true) + c.Assert(b.Interface(), qt.Equals, 2) two, found := caseInsensitiveLookup(m2, reflect.ValueOf(2)) - assert.True(found) - assert.Equal(2, two.Interface()) + c.Assert(found, qt.Equals, true) + c.Assert(two.Interface(), qt.Equals, 2) } diff --git a/tpl/collections/symdiff_test.go b/tpl/collections/symdiff_test.go index b62fdb73b..ac40fda55 100644 --- a/tpl/collections/symdiff_test.go +++ b/tpl/collections/symdiff_test.go @@ -14,19 +14,18 @@ package collections import ( - "fmt" "reflect" "testing" "github.com/gohugoio/hugo/deps" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestSymDiff(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) ns := New(&deps.Deps{}) @@ -56,16 +55,16 @@ func TestSymDiff(t *testing.T) { {[]int{1, 2, 3}, []string{"3", "4"}, false}, } { - errMsg := fmt.Sprintf("[%d]", i) + errMsg := qt.Commentf("[%d]", i) result, err := ns.SymDiff(test.s2, test.s1) if b, ok := test.expected.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) + c.Assert(err, qt.IsNil, errMsg) if !reflect.DeepEqual(test.expected, result) { t.Fatalf("%s got\n%T: %v\nexpected\n%T: %v", errMsg, result, result, test.expected, test.expected) @@ -73,8 +72,8 @@ func TestSymDiff(t *testing.T) { } _, err := ns.Complement() - assert.Error(err) + c.Assert(err, qt.Not(qt.IsNil)) _, err = ns.Complement([]string{"a", "b"}) - assert.Error(err) + c.Assert(err, qt.Not(qt.IsNil)) } diff --git a/tpl/compare/compare_test.go b/tpl/compare/compare_test.go index a7b1e54a6..2331206b3 100644 --- a/tpl/compare/compare_test.go +++ b/tpl/compare/compare_test.go @@ -14,17 +14,17 @@ package compare import ( - "fmt" "path" "reflect" "runtime" "testing" "time" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/hugo" "github.com/spf13/cast" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) type T struct { @@ -80,6 +80,7 @@ func tstIsLt(tp tstCompareType) bool { return tp == tstLt || tp == tstLe } func TestDefaultFunc(t *testing.T) { t.Parallel() + c := qt.New(t) then := time.Now() now := time.Now() @@ -127,12 +128,15 @@ func TestDefaultFunc(t *testing.T) { {then, now, now}, {then, time.Time{}, then}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + + eq := qt.CmpEquals(hqt.DeepAllowUnexported(test.dflt)) + + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.Default(test.dflt, test.given) - require.NoError(t, err, errMsg) - assert.Equal(t, result, test.expect, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, eq, test.expect, errMsg) } } @@ -234,11 +238,11 @@ func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b inte } func TestCase(t *testing.T) { - assert := require.New(t) + c := qt.New(t) n := New(true) - assert.True(n.Lt("az", "Za")) - assert.True(n.Gt("ab", "Ab")) + c.Assert(n.Lt("az", "Za"), qt.Equals, true) + c.Assert(n.Gt("ab", "Ab"), qt.Equals, true) } func TestTimeUnix(t *testing.T) { @@ -265,10 +269,10 @@ func TestTimeUnix(t *testing.T) { } func TestConditional(t *testing.T) { - assert := require.New(t) + c := qt.New(t) n := New(false) a, b := "a", "b" - assert.Equal(a, n.Conditional(true, a, b)) - assert.Equal(b, n.Conditional(false, a, b)) + c.Assert(n.Conditional(true, a, b), qt.Equals, a) + c.Assert(n.Conditional(false, a, b), qt.Equals, b) } diff --git a/tpl/compare/init_test.go b/tpl/compare/init_test.go index 65e59b1aa..29a525f93 100644 --- a/tpl/compare/init_test.go +++ b/tpl/compare/init_test.go @@ -16,12 +16,14 @@ package compare import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +35,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/compare/truth_test.go b/tpl/compare/truth_test.go index 7a9d03442..4c83e8b0a 100644 --- a/tpl/compare/truth_test.go +++ b/tpl/compare/truth_test.go @@ -18,8 +18,8 @@ import ( "testing" "time" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/hreflect" - "github.com/stretchr/testify/require" ) func TestTruth(t *testing.T) { @@ -46,15 +46,15 @@ func TestTruth(t *testing.T) { }) t.Run("Not", func(t *testing.T) { - assert := require.New(t) - assert.True(n.Not(falsev)) - assert.False(n.Not(truthv)) + c := qt.New(t) + c.Assert(n.Not(falsev), qt.Equals, true) + c.Assert(n.Not(truthv), qt.Equals, false) }) t.Run("getIf", func(t *testing.T) { - assert := require.New(t) + c := qt.New(t) assertTruth(t, n.getIf(reflect.ValueOf(nil)), false) s := reflect.ValueOf("Hugo") - assert.Equal(s, n.getIf(s)) + c.Assert(n.getIf(s), qt.Equals, s) }) } diff --git a/tpl/crypto/crypto_test.go b/tpl/crypto/crypto_test.go index 1bd919c31..209ef9f0a 100644 --- a/tpl/crypto/crypto_test.go +++ b/tpl/crypto/crypto_test.go @@ -14,15 +14,14 @@ package crypto import ( - "fmt" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestMD5(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() @@ -34,23 +33,23 @@ func TestMD5(t *testing.T) { {"Lorem ipsum dolor", "06ce65ac476fc656bea3fca5d02cfd81"}, {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.in) + errMsg := qt.Commentf("[%d] %v", i, test.in) result, err := ns.MD5(test.in) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestSHA1(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New() for i, test := range []struct { @@ -61,23 +60,23 @@ func TestSHA1(t *testing.T) { {"Lorem ipsum dolor", "45f75b844be4d17b3394c6701768daf39419c99b"}, {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.in) + errMsg := qt.Commentf("[%d] %v", i, test.in) result, err := ns.SHA1(test.in) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestSHA256(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New() for i, test := range []struct { @@ -88,16 +87,16 @@ func TestSHA256(t *testing.T) { {"Lorem ipsum dolor", "9b3e1beb7053e0f900a674dd1c99aca3355e1275e1b03d3cb1bc977f5154e196"}, {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.in) + errMsg := qt.Commentf("[%d] %v", i, test.in) result, err := ns.SHA256(test.in) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } diff --git a/tpl/crypto/init_test.go b/tpl/crypto/init_test.go index 852a90a40..120e1e4e7 100644 --- a/tpl/crypto/init_test.go +++ b/tpl/crypto/init_test.go @@ -16,12 +16,14 @@ package crypto import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +35,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/data/data_test.go b/tpl/data/data_test.go index 9e7c0d0a6..04575707c 100644 --- a/tpl/data/data_test.go +++ b/tpl/data/data_test.go @@ -14,19 +14,18 @@ package data import ( - "fmt" "net/http" "net/http/httptest" "path/filepath" "strings" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestGetCSV(t *testing.T) { t.Parallel() + c := qt.New(t) for i, test := range []struct { sep string @@ -74,7 +73,7 @@ func TestGetCSV(t *testing.T) { false, }, } { - msg := fmt.Sprintf("Test %d", i) + msg := qt.Commentf("Test %d", i) ns := newTestNs() @@ -100,7 +99,7 @@ func TestGetCSV(t *testing.T) { // Setup local test file for schema-less URLs if !strings.Contains(test.url, ":") && !strings.HasPrefix(test.url, "fail/") { f, err := ns.deps.Fs.Source.Create(filepath.Join(ns.deps.Cfg.GetString("workingDir"), test.url)) - require.NoError(t, err, msg) + c.Assert(err, qt.IsNil, msg) f.WriteString(test.content) f.Close() } @@ -109,22 +108,23 @@ func TestGetCSV(t *testing.T) { got, err := ns.GetCSV(test.sep, test.url) if _, ok := test.expect.(bool); ok { - require.Equal(t, 1, int(ns.deps.Log.ErrorCounter.Count())) - //require.Error(t, err, msg) - require.Nil(t, got) + c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 1) + //c.Assert(err, msg, qt.Not(qt.IsNil)) + c.Assert(got, qt.IsNil) continue } - require.NoError(t, err, msg) - require.Equal(t, 0, int(ns.deps.Log.ErrorCounter.Count())) - require.NotNil(t, got, msg) + c.Assert(err, qt.IsNil, msg) + c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 0) + c.Assert(got, qt.Not(qt.IsNil), msg) + c.Assert(got, qt.DeepEquals, test.expect, msg) - assert.EqualValues(t, test.expect, got, msg) } } func TestGetJSON(t *testing.T) { t.Parallel() + c := qt.New(t) for i, test := range []struct { url string @@ -159,7 +159,7 @@ func TestGetJSON(t *testing.T) { }, } { - msg := fmt.Sprintf("Test %d", i) + msg := qt.Commentf("Test %d", i) ns := newTestNs() // Setup HTTP test server @@ -184,7 +184,7 @@ func TestGetJSON(t *testing.T) { // Setup local test file for schema-less URLs if !strings.Contains(test.url, ":") && !strings.HasPrefix(test.url, "fail/") { f, err := ns.deps.Fs.Source.Create(filepath.Join(ns.deps.Cfg.GetString("workingDir"), test.url)) - require.NoError(t, err, msg) + c.Assert(err, qt.IsNil, msg) f.WriteString(test.content) f.Close() } @@ -193,20 +193,20 @@ func TestGetJSON(t *testing.T) { got, _ := ns.GetJSON(test.url) if _, ok := test.expect.(bool); ok { - require.Equal(t, 1, int(ns.deps.Log.ErrorCounter.Count())) - //require.Error(t, err, msg) + c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 1) + //c.Assert(err, msg, qt.Not(qt.IsNil)) continue } - require.Equal(t, 0, int(ns.deps.Log.ErrorCounter.Count()), msg) - require.NotNil(t, got, msg) - - assert.EqualValues(t, test.expect, got, msg) + c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 0, msg) + c.Assert(got, qt.Not(qt.IsNil), msg) + c.Assert(got, qt.DeepEquals, test.expect) } } func TestParseCSV(t *testing.T) { t.Parallel() + c := qt.New(t) for i, test := range []struct { csv []byte @@ -221,21 +221,21 @@ func TestParseCSV(t *testing.T) { {[]byte("a|b|c\nd|e|f|g"), "|", "abcdefg", true}, {[]byte("z|y|c\nd|e|f"), "|", "zycdef", false}, } { - msg := fmt.Sprintf("Test %d: %v", i, test) + msg := qt.Commentf("Test %d: %v", i, test) csv, err := parseCSV(test.csv, test.sep) if test.err { - assert.Error(t, err, msg) + c.Assert(err, qt.Not(qt.IsNil), msg) continue } - require.NoError(t, err, msg) + c.Assert(err, qt.IsNil, msg) act := "" for _, v := range csv { act = act + strings.Join(v, "") } - assert.Equal(t, test.exp, act, msg) + c.Assert(act, qt.Equals, test.exp, msg) } } diff --git a/tpl/data/init_test.go b/tpl/data/init_test.go index 94c8408ea..fedce8e5c 100644 --- a/tpl/data/init_test.go +++ b/tpl/data/init_test.go @@ -16,13 +16,15 @@ package data import ( "testing" + qt "github.com/frankban/quicktest" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/langs" "github.com/gohugoio/hugo/tpl/internal" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -38,6 +40,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/data/resources_test.go b/tpl/data/resources_test.go index e9850c226..aec5a2e8c 100644 --- a/tpl/data/resources_test.go +++ b/tpl/data/resources_test.go @@ -15,7 +15,6 @@ package data import ( "bytes" - "fmt" "net/http" "net/http/httptest" "net/url" @@ -27,6 +26,7 @@ import ( "github.com/gohugoio/hugo/helpers" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/cache/filecache" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/config" @@ -35,8 +35,6 @@ import ( "github.com/gohugoio/hugo/langs" "github.com/spf13/afero" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestScpGetLocal(t *testing.T) { @@ -88,6 +86,7 @@ func getTestServer(handler func(w http.ResponseWriter, r *http.Request)) (*httpt func TestScpGetRemote(t *testing.T) { t.Parallel() + c := qt.New(t) fs := new(afero.MemMapFs) cache := filecache.NewCache(fs, 100, "") @@ -102,10 +101,10 @@ func TestScpGetRemote(t *testing.T) { } for _, test := range tests { - msg := fmt.Sprintf("%v", test) + msg := qt.Commentf("%v", test) req, err := http.NewRequest("GET", test.path, nil) - require.NoError(t, err, msg) + c.Assert(err, qt.IsNil, msg) srv, cl := getTestServer(func(w http.ResponseWriter, r *http.Request) { w.Write(test.content) @@ -115,23 +114,24 @@ func TestScpGetRemote(t *testing.T) { ns := newTestNs() ns.client = cl - var c []byte + var cb []byte f := func(b []byte) (bool, error) { - c = b + cb = b return false, nil } err = ns.getRemote(cache, f, req) - require.NoError(t, err, msg) - assert.Equal(t, string(test.content), string(c)) + c.Assert(err, qt.IsNil, msg) + c.Assert(string(cb), qt.Equals, string(test.content)) - assert.Equal(t, string(test.content), string(c)) + c.Assert(string(cb), qt.Equals, string(test.content)) } } func TestScpGetRemoteParallel(t *testing.T) { t.Parallel() + c := qt.New(t) content := []byte(`T€st Content 123`) srv, cl := getTestServer(func(w http.ResponseWriter, r *http.Request) { @@ -142,7 +142,7 @@ func TestScpGetRemoteParallel(t *testing.T) { url := "http://Foo.Bar/foo_Bar-Foo" req, err := http.NewRequest("GET", url, nil) - require.NoError(t, err) + c.Assert(err, qt.IsNil) for _, ignoreCache := range []bool{false} { cfg := viper.New() @@ -159,16 +159,16 @@ func TestScpGetRemoteParallel(t *testing.T) { go func(gor int) { defer wg.Done() for j := 0; j < 10; j++ { - var c []byte + var cb []byte f := func(b []byte) (bool, error) { - c = b + cb = b return false, nil } err := ns.getRemote(ns.cacheGetJSON, f, req) - assert.NoError(t, err) - if string(content) != string(c) { - t.Errorf("expected\n%q\ngot\n%q", content, c) + c.Assert(err, qt.IsNil) + if string(content) != string(cb) { + t.Errorf("expected\n%q\ngot\n%q", content, cb) } time.Sleep(23 * time.Millisecond) diff --git a/tpl/encoding/encoding_test.go b/tpl/encoding/encoding_test.go index 8242561b6..2c1804dad 100644 --- a/tpl/encoding/encoding_test.go +++ b/tpl/encoding/encoding_test.go @@ -14,23 +14,22 @@ package encoding import ( - "fmt" "html/template" "math" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) type tstNoStringer struct{} func TestBase64Decode(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { v interface{} expect interface{} }{ @@ -38,26 +37,26 @@ func TestBase64Decode(t *testing.T) { // errors {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.v) result, err := ns.Base64Decode(test.v) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestBase64Encode(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { v interface{} expect interface{} }{ @@ -65,26 +64,25 @@ func TestBase64Encode(t *testing.T) { // errors {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.v) result, err := ns.Base64Encode(test.v) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestJsonify(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { v interface{} expect interface{} }{ @@ -94,16 +92,15 @@ func TestJsonify(t *testing.T) { // errors {math.NaN(), false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.v) result, err := ns.Jsonify(test.v) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } diff --git a/tpl/encoding/init_test.go b/tpl/encoding/init_test.go index 6bbee99fa..5fd71eb32 100644 --- a/tpl/encoding/init_test.go +++ b/tpl/encoding/init_test.go @@ -16,12 +16,14 @@ package encoding import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +35,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/fmt/init_test.go b/tpl/fmt/init_test.go index b693ffa2b..edc1dbb5e 100644 --- a/tpl/fmt/init_test.go +++ b/tpl/fmt/init_test.go @@ -16,13 +16,16 @@ package fmt import ( "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -34,6 +37,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/hugo/init_test.go b/tpl/hugo/init_test.go index f4e31f622..c94a883fd 100644 --- a/tpl/hugo/init_test.go +++ b/tpl/hugo/init_test.go @@ -16,14 +16,17 @@ package hugo import ( "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/tpl/internal" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace v := viper.New() @@ -38,6 +41,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, s.Hugo(), ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, s.Hugo()) } diff --git a/tpl/images/images_test.go b/tpl/images/images_test.go index f2b4a426a..b1b1e1cfd 100644 --- a/tpl/images/images_test.go +++ b/tpl/images/images_test.go @@ -15,20 +15,18 @@ package images import ( "bytes" - "fmt" "image" "image/color" "image/png" "path/filepath" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/hugofs" "github.com/spf13/afero" "github.com/spf13/cast" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) type tstNoStringer struct{} @@ -82,32 +80,32 @@ var configTests = []struct { func TestNSConfig(t *testing.T) { t.Parallel() + c := qt.New(t) v := viper.New() v.Set("workingDir", "/a/b") ns := New(&deps.Deps{Fs: hugofs.NewMem(v)}) - for i, test := range configTests { - errMsg := fmt.Sprintf("[%d] %s", i, test.path) + for _, test := range configTests { // check for expected errors early to avoid writing files if b, ok := test.expect.(bool); ok && !b { _, err := ns.Config(test.path) - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } // cast path to string for afero.WriteFile sp, err := cast.ToStringE(test.path) - require.NoError(t, err, errMsg) + c.Assert(err, qt.IsNil) afero.WriteFile(ns.deps.Fs.Source, filepath.Join(v.GetString("workingDir"), sp), test.input, 0755) result, err := ns.Config(test.path) - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) - assert.NotEqual(t, 0, len(ns.cache), errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) + c.Assert(len(ns.cache), qt.Not(qt.Equals), 0) } } diff --git a/tpl/images/init_test.go b/tpl/images/init_test.go index 8a867f9d3..d6dc26fe7 100644 --- a/tpl/images/init_test.go +++ b/tpl/images/init_test.go @@ -16,12 +16,14 @@ package images import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +35,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/inflect/inflect_test.go b/tpl/inflect/inflect_test.go index a94a20218..609d4a470 100644 --- a/tpl/inflect/inflect_test.go +++ b/tpl/inflect/inflect_test.go @@ -1,19 +1,18 @@ package inflect import ( - "fmt" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestInflect(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { fn func(i interface{}) (string, error) in interface{} expect interface{} @@ -34,16 +33,15 @@ func TestInflect(t *testing.T) { {ns.Singularize, "", ""}, {ns.Singularize, t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := test.fn(test.in) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } diff --git a/tpl/inflect/init_test.go b/tpl/inflect/init_test.go index cbcd312c7..322813b5f 100644 --- a/tpl/inflect/init_test.go +++ b/tpl/inflect/init_test.go @@ -16,12 +16,15 @@ package inflect import ( "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +36,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/internal/templatefuncRegistry_test.go b/tpl/internal/templatefuncRegistry_test.go index ec7fbeb1a..8609bf34a 100644 --- a/tpl/internal/templatefuncRegistry_test.go +++ b/tpl/internal/templatefuncRegistry_test.go @@ -17,7 +17,7 @@ import ( "runtime" "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) type Test struct { @@ -28,11 +28,12 @@ func (t *Test) MyTestMethod() string { } func TestMethodToName(t *testing.T) { + c := qt.New(t) test := &Test{} if runtime.Compiler == "gccgo" { - require.Contains(t, methodToName(test.MyTestMethod), "thunk") + c.Assert(methodToName(test.MyTestMethod), qt.Contains, "thunk") } else { - require.Equal(t, "MyTestMethod", methodToName(test.MyTestMethod)) + c.Assert(methodToName(test.MyTestMethod), qt.Equals, "MyTestMethod") } } diff --git a/tpl/lang/init_test.go b/tpl/lang/init_test.go index fc4893ad0..82def5523 100644 --- a/tpl/lang/init_test.go +++ b/tpl/lang/init_test.go @@ -16,12 +16,15 @@ package lang import ( "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +36,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/lang/lang_test.go b/tpl/lang/lang_test.go index aee567502..e62faf2ac 100644 --- a/tpl/lang/lang_test.go +++ b/tpl/lang/lang_test.go @@ -1,16 +1,15 @@ package lang import ( - "fmt" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestNumFormat(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -41,23 +40,21 @@ func TestNumFormat(t *testing.T) { {6, -12345.6789, "-|٫| ", "|", "-12 345٫678900"}, } - for i, c := range cases { - errMsg := fmt.Sprintf("[%d] %v", i, c) - + for _, cas := range cases { var s string var err error - if len(c.runes) == 0 { - s, err = ns.NumFmt(c.prec, c.n) + if len(cas.runes) == 0 { + s, err = ns.NumFmt(cas.prec, cas.n) } else { - if c.delim == "" { - s, err = ns.NumFmt(c.prec, c.n, c.runes) + if cas.delim == "" { + s, err = ns.NumFmt(cas.prec, cas.n, cas.runes) } else { - s, err = ns.NumFmt(c.prec, c.n, c.runes, c.delim) + s, err = ns.NumFmt(cas.prec, cas.n, cas.runes, cas.delim) } } - require.NoError(t, err, errMsg) - assert.Equal(t, c.want, s, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(s, qt.Equals, cas.want) } } diff --git a/tpl/math/init_test.go b/tpl/math/init_test.go index f1882c1a2..6c0ce0a93 100644 --- a/tpl/math/init_test.go +++ b/tpl/math/init_test.go @@ -16,12 +16,14 @@ package math import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +35,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/math/math_test.go b/tpl/math/math_test.go index f2e6236af..0beec8204 100644 --- a/tpl/math/math_test.go +++ b/tpl/math/math_test.go @@ -14,20 +14,19 @@ package math import ( - "fmt" "math" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestBasicNSArithmetic(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { fn func(a, b interface{}) (interface{}, error) a interface{} b interface{} @@ -42,26 +41,25 @@ func TestBasicNSArithmetic(t *testing.T) { {ns.Div, 4, 2, int64(2)}, {ns.Div, 1.0, "foo", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := test.fn(test.a, test.b) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestCeil(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { x interface{} expect interface{} }{ @@ -75,26 +73,26 @@ func TestCeil(t *testing.T) { {-1.5, -1.0}, {"abc", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Ceil(test.x) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestFloor(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { x interface{} expect interface{} }{ @@ -108,26 +106,26 @@ func TestFloor(t *testing.T) { {-1.5, -2.0}, {"abc", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Floor(test.x) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestLog(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { a interface{} expect interface{} }{ @@ -138,12 +136,11 @@ func TestLog(t *testing.T) { {3.1, float64(1.1314)}, {"abc", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Log(test.a) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } @@ -153,17 +150,18 @@ func TestLog(t *testing.T) { result = float64(int(result*10000)) / 10000 } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestMod(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { a interface{} b interface{} expect interface{} @@ -184,26 +182,26 @@ func TestMod(t *testing.T) { {"aaa", "0", false}, {"3", "aaa", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Mod(test.a, test.b) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestModBool(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { a interface{} b interface{} expect interface{} @@ -230,26 +228,26 @@ func TestModBool(t *testing.T) { {"aaa", "0", nil}, {"3", "aaa", nil}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.ModBool(test.a, test.b) if test.expect == nil { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestRound(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { x interface{} expect interface{} }{ @@ -263,16 +261,15 @@ func TestRound(t *testing.T) { {-1.5, -2.0}, {"abc", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Round(test.x) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } diff --git a/tpl/os/init_test.go b/tpl/os/init_test.go index 08d816cdf..6a91c743a 100644 --- a/tpl/os/init_test.go +++ b/tpl/os/init_test.go @@ -16,12 +16,14 @@ package os import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +35,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/os/os_test.go b/tpl/os/os_test.go index 46dafd842..3adb6f8c2 100644 --- a/tpl/os/os_test.go +++ b/tpl/os/os_test.go @@ -14,20 +14,19 @@ package os import ( - "fmt" "path/filepath" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/hugofs" "github.com/spf13/afero" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestReadFile(t *testing.T) { t.Parallel() + c := qt.New(t) workingDir := "/home/hugo" @@ -40,7 +39,7 @@ func TestReadFile(t *testing.T) { afero.WriteFile(ns.deps.Fs.Source, filepath.Join(workingDir, "/f/f1.txt"), []byte("f1-content"), 0755) afero.WriteFile(ns.deps.Fs.Source, filepath.Join("/home", "f2.txt"), []byte("f2-content"), 0755) - for i, test := range []struct { + for _, test := range []struct { filename string expect interface{} }{ @@ -50,22 +49,22 @@ func TestReadFile(t *testing.T) { {"", false}, {"b", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.ReadFile(test.filename) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestFileExists(t *testing.T) { t.Parallel() + c := qt.New(t) workingDir := "/home/hugo" @@ -77,7 +76,7 @@ func TestFileExists(t *testing.T) { afero.WriteFile(ns.deps.Fs.Source, filepath.Join(workingDir, "/f/f1.txt"), []byte("f1-content"), 0755) afero.WriteFile(ns.deps.Fs.Source, filepath.Join("/home", "f2.txt"), []byte("f2-content"), 0755) - for i, test := range []struct { + for _, test := range []struct { filename string expect interface{} }{ @@ -87,22 +86,21 @@ func TestFileExists(t *testing.T) { {"b", false}, {"", nil}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.FileExists(test.filename) if test.expect == nil { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestStat(t *testing.T) { t.Parallel() - + c := qt.New(t) workingDir := "/home/hugo" v := viper.New() @@ -112,7 +110,7 @@ func TestStat(t *testing.T) { afero.WriteFile(ns.deps.Fs.Source, filepath.Join(workingDir, "/f/f1.txt"), []byte("f1-content"), 0755) - for i, test := range []struct { + for _, test := range []struct { filename string expect interface{} }{ @@ -121,15 +119,14 @@ func TestStat(t *testing.T) { {"b", nil}, {"", nil}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Stat(test.filename) if test.expect == nil { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result.Size(), errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result.Size(), qt.Equals, test.expect) } } diff --git a/tpl/partials/init_test.go b/tpl/partials/init_test.go index 0513f1572..6fd0b3e6d 100644 --- a/tpl/partials/init_test.go +++ b/tpl/partials/init_test.go @@ -16,13 +16,15 @@ package partials import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -37,6 +39,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/path/init_test.go b/tpl/path/init_test.go index b0aeab358..20744b239 100644 --- a/tpl/path/init_test.go +++ b/tpl/path/init_test.go @@ -16,12 +16,15 @@ package path import ( "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +36,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/path/path_test.go b/tpl/path/path_test.go index b9a29a285..ce453b9a1 100644 --- a/tpl/path/path_test.go +++ b/tpl/path/path_test.go @@ -14,14 +14,12 @@ package path import ( - "fmt" "path/filepath" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var ns = New(&deps.Deps{Cfg: viper.New()}) @@ -30,8 +28,9 @@ type tstNoStringer struct{} func TestBase(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { path interface{} expect interface{} }{ @@ -44,24 +43,24 @@ func TestBase(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Base(test.path) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestDir(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { path interface{} expect interface{} }{ @@ -74,24 +73,24 @@ func TestDir(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Dir(test.path) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestExt(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { path interface{} expect interface{} }{ @@ -102,24 +101,24 @@ func TestExt(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Ext(test.path) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestJoin(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { elements interface{} expect interface{} }{ @@ -136,24 +135,24 @@ func TestJoin(t *testing.T) { {tstNoStringer{}, false}, {[]interface{}{"", tstNoStringer{}}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Join(test.elements) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestSplit(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { path interface{} expect interface{} }{ @@ -164,16 +163,15 @@ func TestSplit(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Split(test.path) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } diff --git a/tpl/reflect/init_test.go b/tpl/reflect/init_test.go index 4357200ab..c0247b045 100644 --- a/tpl/reflect/init_test.go +++ b/tpl/reflect/init_test.go @@ -16,13 +16,15 @@ package reflect import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -34,6 +36,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/reflect/reflect_test.go b/tpl/reflect/reflect_test.go index 9b2ad97a6..745360ee7 100644 --- a/tpl/reflect/reflect_test.go +++ b/tpl/reflect/reflect_test.go @@ -14,10 +14,9 @@ package reflect import ( - "fmt" "testing" - "github.com/stretchr/testify/assert" + qt "github.com/frankban/quicktest" ) var ns = New() @@ -25,7 +24,8 @@ var ns = New() type tstNoStringer struct{} func TestIsMap(t *testing.T) { - for i, test := range []struct { + c := qt.New(t) + for _, test := range []struct { v interface{} expect interface{} }{ @@ -33,14 +33,14 @@ func TestIsMap(t *testing.T) { {"foo", false}, {nil, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result := ns.IsMap(test.v) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(result, qt.Equals, test.expect) } } func TestIsSlice(t *testing.T) { - for i, test := range []struct { + c := qt.New(t) + for _, test := range []struct { v interface{} expect interface{} }{ @@ -48,8 +48,7 @@ func TestIsSlice(t *testing.T) { {"foo", false}, {nil, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result := ns.IsSlice(test.v) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(result, qt.Equals, test.expect) } } diff --git a/tpl/safe/init_test.go b/tpl/safe/init_test.go index 99305b53b..2ed7b1872 100644 --- a/tpl/safe/init_test.go +++ b/tpl/safe/init_test.go @@ -16,12 +16,15 @@ package safe import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) + var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +36,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/safe/safe_test.go b/tpl/safe/safe_test.go index 346b448c9..e91605762 100644 --- a/tpl/safe/safe_test.go +++ b/tpl/safe/safe_test.go @@ -14,22 +14,21 @@ package safe import ( - "fmt" "html/template" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) type tstNoStringer struct{} func TestCSS(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { a interface{} expect interface{} }{ @@ -37,26 +36,26 @@ func TestCSS(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.CSS(test.a) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestHTML(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { a interface{} expect interface{} }{ @@ -64,26 +63,26 @@ func TestHTML(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.HTML(test.a) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestHTMLAttr(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { a interface{} expect interface{} }{ @@ -91,26 +90,25 @@ func TestHTMLAttr(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) - result, err := ns.HTMLAttr(test.a) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestJS(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { a interface{} expect interface{} }{ @@ -118,26 +116,26 @@ func TestJS(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.JS(test.a) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestJSStr(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { a interface{} expect interface{} }{ @@ -145,26 +143,26 @@ func TestJSStr(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.JSStr(test.a) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestURL(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { a interface{} expect interface{} }{ @@ -172,26 +170,26 @@ func TestURL(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.URL(test.a) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestSanitizeURL(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() - for i, test := range []struct { + for _, test := range []struct { a interface{} expect interface{} }{ @@ -199,16 +197,15 @@ func TestSanitizeURL(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.SanitizeURL(test.a) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } diff --git a/tpl/site/init_test.go b/tpl/site/init_test.go index 5ef885677..f4a7935ad 100644 --- a/tpl/site/init_test.go +++ b/tpl/site/init_test.go @@ -16,15 +16,17 @@ package site import ( "testing" - "github.com/spf13/viper" - + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" + "github.com/spf13/viper" ) func TestInit(t *testing.T) { + c := qt.New(t) + var found bool var ns *internal.TemplateFuncsNamespace v := viper.New() @@ -39,6 +41,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, s, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, s) } diff --git a/tpl/strings/init_test.go b/tpl/strings/init_test.go index 904e486f7..b356896cf 100644 --- a/tpl/strings/init_test.go +++ b/tpl/strings/init_test.go @@ -16,13 +16,16 @@ package strings import ( "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl/internal" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -34,6 +37,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/strings/regexp_test.go b/tpl/strings/regexp_test.go index 3bacd2018..e05b00fb1 100644 --- a/tpl/strings/regexp_test.go +++ b/tpl/strings/regexp_test.go @@ -14,17 +14,16 @@ package strings import ( - "fmt" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestFindRE(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { expr string content interface{} limit interface{} @@ -39,24 +38,23 @@ func TestFindRE(t *testing.T) { {"[G|go", "Hugo is a static site generator written in Go.", nil, false}, {"[G|g]o", t, nil, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) - result, err := ns.FindRE(test.expr, test.content, test.limit) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.DeepEquals, test.expect) } } func TestReplaceRE(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { pattern interface{} repl interface{} s interface{} @@ -71,16 +69,15 @@ func TestReplaceRE(t *testing.T) { {"^https?://([^/]+).*", tstNoStringer{}, "http://gohugo.io/docs", false}, {"^https?://([^/]+).*", "$2", tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.ReplaceRE(test.pattern, test.repl, test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } diff --git a/tpl/strings/strings_test.go b/tpl/strings/strings_test.go index 22695ba08..e852fd51f 100644 --- a/tpl/strings/strings_test.go +++ b/tpl/strings/strings_test.go @@ -14,15 +14,13 @@ package strings import ( - "fmt" "html/template" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/spf13/cast" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var ns = New(&deps.Deps{Cfg: viper.New()}) @@ -31,8 +29,9 @@ type tstNoStringer struct{} func TestChomp(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -45,29 +44,29 @@ func TestChomp(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Chomp(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) // repeat the check with template.HTML input result, err = ns.Chomp(template.HTML(cast.ToString(test.s))) - require.NoError(t, err, errMsg) - assert.Equal(t, template.HTML(cast.ToString(test.expect)), result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, template.HTML(cast.ToString(test.expect))) } } func TestContains(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} substr interface{} expect bool @@ -88,24 +87,24 @@ func TestContains(t *testing.T) { {"", tstNoStringer{}, false, true}, {tstNoStringer{}, "", false, true}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Contains(test.s, test.substr) if test.isErr { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestContainsAny(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} substr interface{} expect bool @@ -132,24 +131,24 @@ func TestContainsAny(t *testing.T) { {"", tstNoStringer{}, false, true}, {tstNoStringer{}, "", false, true}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.ContainsAny(test.s, test.substr) if test.isErr { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestCountRunes(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -159,24 +158,24 @@ func TestCountRunes(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.s) result, err := ns.CountRunes(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestRuneCount(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -186,24 +185,24 @@ func TestRuneCount(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.s) result, err := ns.RuneCount(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestCountWords(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -213,24 +212,24 @@ func TestCountWords(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.s) result, err := ns.CountWords(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestHasPrefix(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} prefix interface{} expect interface{} @@ -247,24 +246,24 @@ func TestHasPrefix(t *testing.T) { {"", tstNoStringer{}, false, true}, {tstNoStringer{}, "", false, true}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.HasPrefix(test.s, test.prefix) if test.isErr { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestHasSuffix(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} suffix interface{} expect interface{} @@ -281,24 +280,24 @@ func TestHasSuffix(t *testing.T) { {"", tstNoStringer{}, false, true}, {tstNoStringer{}, "", false, true}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.HasSuffix(test.s, test.suffix) if test.isErr { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestReplace(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} old interface{} new interface{} @@ -312,25 +311,25 @@ func TestReplace(t *testing.T) { {"a", tstNoStringer{}, "b", false}, {"a", "b", tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Replace(test.s, test.old, test.new) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestSliceString(t *testing.T) { t.Parallel() + c := qt.New(t) var err error - for i, test := range []struct { + for _, test := range []struct { v1 interface{} v2 interface{} v3 interface{} @@ -362,7 +361,6 @@ func TestSliceString(t *testing.T) { {"a", t, nil, false}, {"a", 1, t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) var result string if test.v2 == nil { @@ -374,12 +372,12 @@ func TestSliceString(t *testing.T) { } if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } // Too many arguments @@ -391,8 +389,9 @@ func TestSliceString(t *testing.T) { func TestSplit(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { v1 interface{} v2 string expect interface{} @@ -403,26 +402,25 @@ func TestSplit(t *testing.T) { {123, "2", []string{"1", "3"}}, {tstNoStringer{}, ",", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Split(test.v1, test.v2) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.DeepEquals, test.expect) } } func TestSubstr(t *testing.T) { t.Parallel() + c := qt.New(t) var err error - var n int - for i, test := range []struct { + for _, test := range []struct { v1 interface{} v2 interface{} v3 interface{} @@ -459,10 +457,8 @@ func TestSubstr(t *testing.T) { {"abcdef", "doo", "doo", false}, {"abcdef", 1, "doo", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) var result string - n = i if test.v3 == nil { result, err = ns.Substr(test.v1, test.v2) @@ -471,31 +467,26 @@ func TestSubstr(t *testing.T) { } if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } - n++ _, err = ns.Substr("abcdef") - if err == nil { - t.Errorf("[%d] Substr didn't return an expected error", n) - } + c.Assert(err, qt.Not(qt.IsNil)) - n++ _, err = ns.Substr("abcdef", 1, 2, 3) - if err == nil { - t.Errorf("[%d] Substr didn't return an expected error", n) - } + c.Assert(err, qt.Not(qt.IsNil)) } func TestTitle(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -505,24 +496,24 @@ func TestTitle(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Title(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestToLower(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -532,24 +523,24 @@ func TestToLower(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.ToLower(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestToUpper(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -559,24 +550,24 @@ func TestToUpper(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.ToUpper(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestTrim(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} cutset interface{} expect interface{} @@ -593,24 +584,24 @@ func TestTrim(t *testing.T) { {"", tstNoStringer{}, false}, {tstNoStringer{}, "", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Trim(test.s, test.cutset) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestTrimLeft(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} cutset interface{} expect interface{} @@ -628,24 +619,24 @@ func TestTrimLeft(t *testing.T) { {"", tstNoStringer{}, false}, {tstNoStringer{}, "", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.TrimLeft(test.cutset, test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestTrimPrefix(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} prefix interface{} expect interface{} @@ -658,24 +649,24 @@ func TestTrimPrefix(t *testing.T) { {"", tstNoStringer{}, false}, {tstNoStringer{}, "", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.TrimPrefix(test.prefix, test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestTrimRight(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} cutset interface{} expect interface{} @@ -693,24 +684,24 @@ func TestTrimRight(t *testing.T) { {"", tstNoStringer{}, false}, {tstNoStringer{}, "", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.TrimRight(test.cutset, test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestTrimSuffix(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} suffix interface{} expect interface{} @@ -723,24 +714,24 @@ func TestTrimSuffix(t *testing.T) { {"", tstNoStringer{}, false}, {tstNoStringer{}, "", false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.TrimSuffix(test.suffix, test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestRepeat(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { s interface{} n interface{} expect interface{} @@ -758,16 +749,15 @@ func TestRepeat(t *testing.T) { {tstNoStringer{}, "", false}, {"ab", -1, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Repeat(test.n, test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } diff --git a/tpl/template_test.go b/tpl/template_test.go index 73e9640be..9f89db5ae 100644 --- a/tpl/template_test.go +++ b/tpl/template_test.go @@ -16,16 +16,16 @@ package tpl import ( "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestExtractBaseof(t *testing.T) { - assert := require.New(t) + c := qt.New(t) replaced := extractBaseOf(`failed: template: _default/baseof.html:37:11: executing "_default/baseof.html" at <.Parents>: can't evaluate field Parents in type *hugolib.PageOutput`) - assert.Equal("_default/baseof.html", replaced) - assert.Equal("", extractBaseOf("not baseof for you")) - assert.Equal("blog/baseof.html", extractBaseOf("template: blog/baseof.html:23:11:")) - assert.Equal("blog/baseof.ace", extractBaseOf("template: blog/baseof.ace:23:11:")) + c.Assert(replaced, qt.Equals, "_default/baseof.html") + c.Assert(extractBaseOf("not baseof for you"), qt.Equals, "") + c.Assert(extractBaseOf("template: blog/baseof.html:23:11:"), qt.Equals, "blog/baseof.html") + c.Assert(extractBaseOf("template: blog/baseof.ace:23:11:"), qt.Equals, "blog/baseof.ace") } diff --git a/tpl/templates/init_test.go b/tpl/templates/init_test.go index 9a0533fe8..cdad188bc 100644 --- a/tpl/templates/init_test.go +++ b/tpl/templates/init_test.go @@ -16,12 +16,14 @@ package templates import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +35,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/time/init_test.go b/tpl/time/init_test.go index ed1091b5b..672b03547 100644 --- a/tpl/time/init_test.go +++ b/tpl/time/init_test.go @@ -16,12 +16,15 @@ package time import ( "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +36,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/tplimpl/shortcodes_test.go b/tpl/tplimpl/shortcodes_test.go index da30d4149..08200444d 100644 --- a/tpl/tplimpl/shortcodes_test.go +++ b/tpl/tplimpl/shortcodes_test.go @@ -14,38 +14,37 @@ package tplimpl import ( - "fmt" "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestShortcodesTemplate(t *testing.T) { t.Run("isShortcode", func(t *testing.T) { - assert := require.New(t) - assert.True(isShortcode("shortcodes/figures.html")) - assert.True(isShortcode("_internal/shortcodes/figures.html")) - assert.False(isShortcode("shortcodes\\figures.html")) - assert.False(isShortcode("myshortcodes")) + c := qt.New(t) + c.Assert(isShortcode("shortcodes/figures.html"), qt.Equals, true) + c.Assert(isShortcode("_internal/shortcodes/figures.html"), qt.Equals, true) + c.Assert(isShortcode("shortcodes\\figures.html"), qt.Equals, false) + c.Assert(isShortcode("myshortcodes"), qt.Equals, false) }) t.Run("variantsFromName", func(t *testing.T) { - assert := require.New(t) - assert.Equal([]string{"", "html", "html"}, templateVariants("figure.html")) - assert.Equal([]string{"no", "no", "html"}, templateVariants("figure.no.html")) - assert.Equal([]string{"no", "amp", "html"}, templateVariants("figure.no.amp.html")) - assert.Equal([]string{"amp", "amp", "html"}, templateVariants("figure.amp.html")) + c := qt.New(t) + c.Assert(templateVariants("figure.html"), qt.DeepEquals, []string{"", "html", "html"}) + c.Assert(templateVariants("figure.no.html"), qt.DeepEquals, []string{"no", "no", "html"}) + c.Assert(templateVariants("figure.no.amp.html"), qt.DeepEquals, []string{"no", "amp", "html"}) + c.Assert(templateVariants("figure.amp.html"), qt.DeepEquals, []string{"amp", "amp", "html"}) name, variants := templateNameAndVariants("figure.html") - assert.Equal("figure", name) - assert.Equal([]string{"", "html", "html"}, variants) + c.Assert(name, qt.Equals, "figure") + c.Assert(variants, qt.DeepEquals, []string{"", "html", "html"}) }) t.Run("compareVariants", func(t *testing.T) { - assert := require.New(t) + c := qt.New(t) var s *shortcodeTemplates tests := []struct { @@ -62,15 +61,15 @@ func TestShortcodesTemplate(t *testing.T) { {"One with output format, one without", "figure.amp.html", "figure.html", -1}, } - for i, test := range tests { + for _, test := range tests { w := s.compareVariants(templateVariants(test.name1), templateVariants(test.name2)) - assert.Equal(test.expected, w, fmt.Sprintf("[%d] %s", i, test.name)) + c.Assert(w, qt.Equals, test.expected) } }) t.Run("indexOf", func(t *testing.T) { - assert := require.New(t) + c := qt.New(t) s := &shortcodeTemplates{ variants: []shortcodeVariant{ @@ -79,20 +78,20 @@ func TestShortcodesTemplate(t *testing.T) { }, } - assert.Equal(0, s.indexOf([]string{"a", "b", "c"})) - assert.Equal(1, s.indexOf([]string{"a", "b", "d"})) - assert.Equal(-1, s.indexOf([]string{"a", "b", "x"})) + c.Assert(s.indexOf([]string{"a", "b", "c"}), qt.Equals, 0) + c.Assert(s.indexOf([]string{"a", "b", "d"}), qt.Equals, 1) + c.Assert(s.indexOf([]string{"a", "b", "x"}), qt.Equals, -1) }) t.Run("Name", func(t *testing.T) { - assert := require.New(t) + c := qt.New(t) - assert.Equal("foo.html", templateBaseName(templateShortcode, "shortcodes/foo.html")) - assert.Equal("foo.html", templateBaseName(templateShortcode, "_internal/shortcodes/foo.html")) - assert.Equal("test/foo.html", templateBaseName(templateShortcode, "shortcodes/test/foo.html")) + c.Assert(templateBaseName(templateShortcode, "shortcodes/foo.html"), qt.Equals, "foo.html") + c.Assert(templateBaseName(templateShortcode, "_internal/shortcodes/foo.html"), qt.Equals, "foo.html") + c.Assert(templateBaseName(templateShortcode, "shortcodes/test/foo.html"), qt.Equals, "test/foo.html") - assert.True(true) + c.Assert(true, qt.Equals, true) }) } diff --git a/tpl/tplimpl/template_ast_transformers_test.go b/tpl/tplimpl/template_ast_transformers_test.go index be1efc522..39b5c460a 100644 --- a/tpl/tplimpl/template_ast_transformers_test.go +++ b/tpl/tplimpl/template_ast_transformers_test.go @@ -23,7 +23,7 @@ import ( "github.com/spf13/cast" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) var ( @@ -175,77 +175,78 @@ PARAMS SITE GLOBAL3: {{ $site.Params.LOWER }} func TestParamsKeysToLower(t *testing.T) { t.Parallel() + c := qt.New(t) _, err := applyTemplateTransformers(templateUndefined, nil, nil) - require.Error(t, err) + c.Assert(err, qt.Not(qt.IsNil)) templ, err := template.New("foo").Funcs(testFuncs).Parse(paramsTempl) - require.NoError(t, err) + c.Assert(err, qt.IsNil) - c := newTemplateContext(createParseTreeLookup(templ)) + ctx := newTemplateContext(createParseTreeLookup(templ)) - require.Equal(t, -1, c.decl.indexOfReplacementStart([]string{})) + c.Assert(ctx.decl.indexOfReplacementStart([]string{}), qt.Equals, -1) - c.applyTransformations(templ.Tree.Root) + ctx.applyTransformations(templ.Tree.Root) var b bytes.Buffer - require.NoError(t, templ.Execute(&b, paramsData)) + c.Assert(templ.Execute(&b, paramsData), qt.IsNil) result := b.String() - require.Contains(t, result, "P1: P1L") - require.Contains(t, result, "P1_2: P1L") - require.Contains(t, result, "P1_3: P1L") - require.Contains(t, result, "P1_4: P1L") - require.Contains(t, result, "P2: P2L") - require.Contains(t, result, "P2_2: P2L") - require.Contains(t, result, "P2_3: P2L") - require.Contains(t, result, "P2_4: P2L") - require.Contains(t, result, "P22: P22L") - require.Contains(t, result, "P22_nested: P22L_nested") - require.Contains(t, result, "P3: P3H") - require.Contains(t, result, "P3_2: P3H") - require.Contains(t, result, "P3_3: P3H") - require.Contains(t, result, "P3_4: P3H") - require.Contains(t, result, "P4: 13") - require.Contains(t, result, "P5: P1L") - require.Contains(t, result, "P5_2: P2L") - - require.Contains(t, result, "IF: P1L") - require.Contains(t, result, "ELSE: P1L") - - require.Contains(t, result, "WITH: P1L") - - require.Contains(t, result, "RANGE: 3: P1L") - - require.Contains(t, result, "Hi There") + c.Assert(result, qt.Contains, "P1: P1L") + c.Assert(result, qt.Contains, "P1_2: P1L") + c.Assert(result, qt.Contains, "P1_3: P1L") + c.Assert(result, qt.Contains, "P1_4: P1L") + c.Assert(result, qt.Contains, "P2: P2L") + c.Assert(result, qt.Contains, "P2_2: P2L") + c.Assert(result, qt.Contains, "P2_3: P2L") + c.Assert(result, qt.Contains, "P2_4: P2L") + c.Assert(result, qt.Contains, "P22: P22L") + c.Assert(result, qt.Contains, "P22_nested: P22L_nested") + c.Assert(result, qt.Contains, "P3: P3H") + c.Assert(result, qt.Contains, "P3_2: P3H") + c.Assert(result, qt.Contains, "P3_3: P3H") + c.Assert(result, qt.Contains, "P3_4: P3H") + c.Assert(result, qt.Contains, "P4: 13") + c.Assert(result, qt.Contains, "P5: P1L") + c.Assert(result, qt.Contains, "P5_2: P2L") + + c.Assert(result, qt.Contains, "IF: P1L") + c.Assert(result, qt.Contains, "ELSE: P1L") + + c.Assert(result, qt.Contains, "WITH: P1L") + + c.Assert(result, qt.Contains, "RANGE: 3: P1L") + + c.Assert(result, qt.Contains, "Hi There") // Issue #2740 - require.Contains(t, result, "F1: themes/P2L-theme") - require.Contains(t, result, "F2: themes/P2L-theme") - require.Contains(t, result, "F3: themes/P2L-theme") + c.Assert(result, qt.Contains, "F1: themes/P2L-theme") + c.Assert(result, qt.Contains, "F2: themes/P2L-theme") + c.Assert(result, qt.Contains, "F3: themes/P2L-theme") - require.Contains(t, result, "PSLICE: PSLICE1|PSLICE3|") - require.Contains(t, result, "PARAMS STRING: foo:.Params.toc_hide:[!= true]") - require.Contains(t, result, "PARAMS STRING2: foo:.Params.toc_hide:[!= true]") - require.Contains(t, result, "PARAMS STRING3: .Params.TOC_HIDE:!=:[P1L]") + c.Assert(result, qt.Contains, "PSLICE: PSLICE1|PSLICE3|") + c.Assert(result, qt.Contains, "PARAMS STRING: foo:.Params.toc_hide:[!= true]") + c.Assert(result, qt.Contains, "PARAMS STRING2: foo:.Params.toc_hide:[!= true]") + c.Assert(result, qt.Contains, "PARAMS STRING3: .Params.TOC_HIDE:!=:[P1L]") // Issue #5094 - require.Contains(t, result, "PARAMS COMPOSITE: [1 3]") + c.Assert(result, qt.Contains, "PARAMS COMPOSITE: [1 3]") // Issue #5068 - require.Contains(t, result, "PCurrentSection: pcurrentsection") + c.Assert(result, qt.Contains, "PCurrentSection: pcurrentsection") // Issue #5541 - require.Contains(t, result, "PARAMS TIME: 1972-02-28") - require.Contains(t, result, "PARAMS TIME2: 1972-02-28") + c.Assert(result, qt.Contains, "PARAMS TIME: 1972-02-28") + c.Assert(result, qt.Contains, "PARAMS TIME2: 1972-02-28") // Issue ##5615 - require.Contains(t, result, "PARAMS SITE GLOBAL1: global-site") - require.Contains(t, result, "PARAMS SITE GLOBAL2: global-site") - require.Contains(t, result, "PARAMS SITE GLOBAL3: global-site") + c.Assert(result, qt.Contains, "PARAMS SITE GLOBAL1: global-site") + c.Assert(result, qt.Contains, "PARAMS SITE GLOBAL2: global-site") + c.Assert(result, qt.Contains, "PARAMS SITE GLOBAL3: global-site") } @@ -275,8 +276,10 @@ func BenchmarkTemplateParamsKeysToLower(b *testing.B) { func TestParamsKeysToLowerVars(t *testing.T) { t.Parallel() + c := qt.New(t) + var ( - ctx = map[string]interface{}{ + data = map[string]interface{}{ "Params": map[string]interface{}{ "colors": map[string]interface{}{ "blue": "Amber", @@ -304,31 +307,32 @@ Pretty First3: {{ $__amber_4.COLORS.PRETTY.FIRST}} templ, err := template.New("foo").Parse(paramsTempl) - require.NoError(t, err) + c.Assert(err, qt.IsNil) - c := newTemplateContext(createParseTreeLookup(templ)) + ctx := newTemplateContext(createParseTreeLookup(templ)) - c.applyTransformations(templ.Tree.Root) + ctx.applyTransformations(templ.Tree.Root) var b bytes.Buffer - require.NoError(t, templ.Execute(&b, ctx)) + c.Assert(templ.Execute(&b, data), qt.IsNil) result := b.String() - require.Contains(t, result, "Color: Amber") - require.Contains(t, result, "Blue: Amber") - require.Contains(t, result, "Pretty First1: Indigo") - require.Contains(t, result, "Pretty First2: Indigo") - require.Contains(t, result, "Pretty First3: Indigo") + c.Assert(result, qt.Contains, "Color: Amber") + c.Assert(result, qt.Contains, "Blue: Amber") + c.Assert(result, qt.Contains, "Pretty First1: Indigo") + c.Assert(result, qt.Contains, "Pretty First2: Indigo") + c.Assert(result, qt.Contains, "Pretty First3: Indigo") } func TestParamsKeysToLowerInBlockTemplate(t *testing.T) { t.Parallel() + c := qt.New(t) var ( - ctx = map[string]interface{}{ + data = map[string]interface{}{ "Params": map[string]interface{}{ "lower": "P1L", }, @@ -344,28 +348,29 @@ P2: {{ .Params.LOWER }} ) masterTpl, err := template.New("foo").Parse(master) - require.NoError(t, err) + c.Assert(err, qt.IsNil) overlayTpl, err := template.Must(masterTpl.Clone()).Parse(overlay) - require.NoError(t, err) + c.Assert(err, qt.IsNil) overlayTpl = overlayTpl.Lookup(overlayTpl.Name()) - c := newTemplateContext(createParseTreeLookup(overlayTpl)) + ctx := newTemplateContext(createParseTreeLookup(overlayTpl)) - c.applyTransformations(overlayTpl.Tree.Root) + ctx.applyTransformations(overlayTpl.Tree.Root) var b bytes.Buffer - require.NoError(t, overlayTpl.Execute(&b, ctx)) + c.Assert(overlayTpl.Execute(&b, data), qt.IsNil) result := b.String() - require.Contains(t, result, "P1: P1L") - require.Contains(t, result, "P2: P1L") + c.Assert(result, qt.Contains, "P1: P1L") + c.Assert(result, qt.Contains, "P2: P1L") } // Issue #2927 func TestTransformRecursiveTemplate(t *testing.T) { + c := qt.New(t) recursive := ` {{ define "menu-nodes" }} @@ -378,10 +383,10 @@ func TestTransformRecursiveTemplate(t *testing.T) { ` templ, err := template.New("foo").Parse(recursive) - require.NoError(t, err) + c.Assert(err, qt.IsNil) - c := newTemplateContext(createParseTreeLookup(templ)) - c.applyTransformations(templ.Tree.Root) + ctx := newTemplateContext(createParseTreeLookup(templ)) + ctx.applyTransformations(templ.Tree.Root) } @@ -399,7 +404,7 @@ func (T) Method0() { func TestInsertIsZeroFunc(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) var ( ctx = map[string]interface{}{ @@ -434,33 +439,33 @@ func TestInsertIsZeroFunc(t *testing.T) { ` ) - d := newD(assert) + d := newD(c) h := d.Tmpl.(tpl.TemplateHandler) // HTML templates - assert.NoError(h.AddTemplate("mytemplate.html", templ1)) - assert.NoError(h.AddTemplate("othertemplate.html", templ2)) + c.Assert(h.AddTemplate("mytemplate.html", templ1), qt.IsNil) + c.Assert(h.AddTemplate("othertemplate.html", templ2), qt.IsNil) // Text templates - assert.NoError(h.AddTemplate("_text/mytexttemplate.txt", templ1)) - assert.NoError(h.AddTemplate("_text/myothertexttemplate.txt", templ2)) + c.Assert(h.AddTemplate("_text/mytexttemplate.txt", templ1), qt.IsNil) + c.Assert(h.AddTemplate("_text/myothertexttemplate.txt", templ2), qt.IsNil) - assert.NoError(h.MarkReady()) + c.Assert(h.MarkReady(), qt.IsNil) for _, name := range []string{"mytemplate.html", "mytexttemplate.txt"} { tt, _ := d.Tmpl.Lookup(name) result, err := tt.(tpl.TemplateExecutor).ExecuteToString(ctx) - assert.NoError(err) - - assert.Contains(result, ".True: TRUE") - assert.Contains(result, ".TimeZero1: FALSE") - assert.Contains(result, ".TimeZero2: FALSE") - assert.Contains(result, ".TimeZero3: TRUE") - assert.Contains(result, ".Now: TRUE") - assert.Contains(result, "TimeZero1 with: FALSE") - assert.Contains(result, ".TimeZero1: mytemplate: FALSE") - assert.Contains(result, ".TimeZero1: other-file-template: FALSE") - assert.Contains(result, ".NonEmptyInterfaceTypedNil: FALSE") + c.Assert(err, qt.IsNil) + + c.Assert(result, qt.Contains, ".True: TRUE") + c.Assert(result, qt.Contains, ".TimeZero1: FALSE") + c.Assert(result, qt.Contains, ".TimeZero2: FALSE") + c.Assert(result, qt.Contains, ".TimeZero3: TRUE") + c.Assert(result, qt.Contains, ".Now: TRUE") + c.Assert(result, qt.Contains, "TimeZero1 with: FALSE") + c.Assert(result, qt.Contains, ".TimeZero1: mytemplate: FALSE") + c.Assert(result, qt.Contains, ".TimeZero1: other-file-template: FALSE") + c.Assert(result, qt.Contains, ".NonEmptyInterfaceTypedNil: FALSE") } } @@ -492,16 +497,16 @@ func TestCollectInfo(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - assert := require.New(t) + c := qt.New(t) templ, err := template.New("foo").Funcs(funcs).Parse(test.tplString) - require.NoError(t, err) + c.Assert(err, qt.IsNil) - c := newTemplateContext(createParseTreeLookup(templ)) - c.typ = templateShortcode - c.applyTransformations(templ.Tree.Root) + ctx := newTemplateContext(createParseTreeLookup(templ)) + ctx.typ = templateShortcode + ctx.applyTransformations(templ.Tree.Root) - assert.Equal(test.expected, c.Info) + c.Assert(ctx.Info, qt.Equals, test.expected) }) } @@ -534,16 +539,16 @@ func TestPartialReturn(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - assert := require.New(t) + c := qt.New(t) templ, err := template.New("foo").Funcs(funcs).Parse(test.tplString) - require.NoError(t, err) + c.Assert(err, qt.IsNil) _, err = applyTemplateTransformers(templatePartial, templ.Tree, createParseTreeLookup(templ)) // Just check that it doesn't fail in this test. We have functional tests // in hugoblib. - assert.NoError(err) + c.Assert(err, qt.IsNil) }) } diff --git a/tpl/tplimpl/template_funcs_test.go b/tpl/tplimpl/template_funcs_test.go index faf5b01fe..10fbc2375 100644 --- a/tpl/tplimpl/template_funcs_test.go +++ b/tpl/tplimpl/template_funcs_test.go @@ -25,6 +25,7 @@ import ( "github.com/gohugoio/hugo/resources/page" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/hugo" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/config" @@ -37,7 +38,6 @@ import ( "github.com/gohugoio/hugo/tpl/partials" "github.com/spf13/afero" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) var ( @@ -80,6 +80,7 @@ func newDepsConfig(cfg config.Provider) deps.DepsCfg { func TestTemplateFuncsExamples(t *testing.T) { t.Parallel() + c := qt.New(t) workingDir := "/home/hugo" @@ -99,7 +100,7 @@ func TestTemplateFuncsExamples(t *testing.T) { depsCfg := newDepsConfig(v) depsCfg.Fs = fs d, err := deps.New(depsCfg) - require.NoError(t, err) + c.Assert(err, qt.IsNil) var data struct { Title string @@ -119,15 +120,15 @@ func TestTemplateFuncsExamples(t *testing.T) { for i, example := range mm.Examples { in, expected := example[0], example[1] d.WithTemplate = func(templ tpl.TemplateHandler) error { - require.NoError(t, templ.AddTemplate("test", in)) - require.NoError(t, templ.AddTemplate("partials/header.html", "<title>Hugo Rocks!</title>")) + c.Assert(templ.AddTemplate("test", in), qt.IsNil) + c.Assert(templ.AddTemplate("partials/header.html", "<title>Hugo Rocks!</title>"), qt.IsNil) return nil } - require.NoError(t, d.LoadResources()) + c.Assert(d.LoadResources(), qt.IsNil) var b bytes.Buffer templ, _ := d.Tmpl.Lookup("test") - require.NoError(t, templ.Execute(&b, &data)) + c.Assert(templ.Execute(&b, &data), qt.IsNil) if b.String() != expected { t.Fatalf("%s[%d]: got %q expected %q", ns.Name, i, b.String(), expected) } @@ -141,7 +142,7 @@ func TestTemplateFuncsExamples(t *testing.T) { func TestPartialCached(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) partial := `Now: {{ now.UnixNano }}` name := "testing" @@ -163,25 +164,25 @@ func TestPartialCached(t *testing.T) { } de, err := deps.New(config) - assert.NoError(err) - assert.NoError(de.LoadResources()) + c.Assert(err, qt.IsNil) + c.Assert(de.LoadResources(), qt.IsNil) ns := partials.New(de) res1, err := ns.IncludeCached(name, &data) - assert.NoError(err) + c.Assert(err, qt.IsNil) for j := 0; j < 10; j++ { time.Sleep(2 * time.Nanosecond) res2, err := ns.IncludeCached(name, &data) - assert.NoError(err) + c.Assert(err, qt.IsNil) if !reflect.DeepEqual(res1, res2) { t.Fatalf("cache mismatch") } res3, err := ns.IncludeCached(name, &data, fmt.Sprintf("variant%d", j)) - assert.NoError(err) + c.Assert(err, qt.IsNil) if reflect.DeepEqual(res1, res3) { t.Fatalf("cache mismatch") @@ -205,6 +206,7 @@ func BenchmarkPartialCached(b *testing.B) { } func doBenchmarkPartial(b *testing.B, f func(ns *partials.Namespace) error) { + c := qt.New(b) config := newDepsConfig(viper.New()) config.WithTemplate = func(templ tpl.TemplateHandler) error { err := templ.AddTemplate("partials/bench1", `{{ shuffle (seq 1 10) }}`) @@ -216,8 +218,8 @@ func doBenchmarkPartial(b *testing.B, f func(ns *partials.Namespace) error) { } de, err := deps.New(config) - require.NoError(b, err) - require.NoError(b, de.LoadResources()) + c.Assert(err, qt.IsNil) + c.Assert(de.LoadResources(), qt.IsNil) ns := partials.New(de) diff --git a/tpl/tplimpl/template_info_test.go b/tpl/tplimpl/template_info_test.go index be9d7e2f1..c96e82d06 100644 --- a/tpl/tplimpl/template_info_test.go +++ b/tpl/tplimpl/template_info_test.go @@ -15,38 +15,39 @@ package tplimpl import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/tpl" - "github.com/stretchr/testify/require" ) func TestTemplateInfoShortcode(t *testing.T) { - assert := require.New(t) - d := newD(assert) + c := qt.New(t) + d := newD(c) h := d.Tmpl.(tpl.TemplateHandler) - assert.NoError(h.AddTemplate("shortcodes/mytemplate.html", ` + c.Assert(h.AddTemplate("shortcodes/mytemplate.html", ` {{ .Inner }} -`)) +`), qt.IsNil) + tt, found, _ := d.Tmpl.LookupVariant("mytemplate", tpl.TemplateVariants{}) - assert.True(found) + c.Assert(found, qt.Equals, true) tti, ok := tt.(tpl.TemplateInfoProvider) - assert.True(ok) - assert.True(tti.TemplateInfo().IsInner) + c.Assert(ok, qt.Equals, true) + c.Assert(tti.TemplateInfo().IsInner, qt.Equals, true) } // TODO(bep) move and use in other places -func newD(assert *require.Assertions) *deps.Deps { +func newD(c *qt.C) *deps.Deps { v := newTestConfig() fs := hugofs.NewMem(v) depsCfg := newDepsConfig(v) depsCfg.Fs = fs d, err := deps.New(depsCfg) - assert.NoError(err) + c.Assert(err, qt.IsNil) provider := DefaultTemplateProvider provider.Update(d) diff --git a/tpl/transform/init_test.go b/tpl/transform/init_test.go index 8ac20366c..47bd8a391 100644 --- a/tpl/transform/init_test.go +++ b/tpl/transform/init_test.go @@ -16,12 +16,14 @@ package transform import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +35,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/transform/remarshal_test.go b/tpl/transform/remarshal_test.go index 07414ccb4..06bae42d4 100644 --- a/tpl/transform/remarshal_test.go +++ b/tpl/transform/remarshal_test.go @@ -14,12 +14,11 @@ package transform import ( - "fmt" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/helpers" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) func TestRemarshal(t *testing.T) { @@ -28,7 +27,7 @@ func TestRemarshal(t *testing.T) { v := viper.New() v.Set("contentDir", "content") ns := New(newDeps(v)) - assert := require.New(t) + c := qt.New(t) tomlExample := `title = "Test Metadata" @@ -96,10 +95,10 @@ title: Test Metadata for _, v1 := range variants { for _, v2 := range variants { // Both from and to may be the same here, but that is fine. - fromTo := fmt.Sprintf("%s => %s", v2.format, v1.format) + fromTo := qt.Commentf("%s => %s", v2.format, v1.format) converted, err := ns.Remarshal(v1.format, v2.data) - assert.NoError(err, fromTo) + c.Assert(err, qt.IsNil, fromTo) diff := helpers.DiffStrings(v1.data, converted) if len(diff) > 0 { t.Errorf("[%s] Expected \n%v\ngot\n%v\ndiff:\n%v", fromTo, v1.data, converted, diff) @@ -117,7 +116,7 @@ func TestRemarshalComments(t *testing.T) { v.Set("contentDir", "content") ns := New(newDeps(v)) - assert := require.New(t) + c := qt.New(t) input := ` Hugo = "Rules" @@ -138,14 +137,14 @@ Hugo = "Rules" ` for _, format := range []string{"json", "yaml", "toml"} { - fromTo := fmt.Sprintf("%s => %s", "toml", format) + fromTo := qt.Commentf("%s => %s", "toml", format) converted := input var err error // Do a round-trip conversion for _, toFormat := range []string{format, "toml"} { converted, err = ns.Remarshal(toFormat, converted) - assert.NoError(err, fromTo) + c.Assert(err, qt.IsNil, fromTo) } diff := helpers.DiffStrings(expected, converted) @@ -161,12 +160,12 @@ func TestTestRemarshalError(t *testing.T) { v := viper.New() v.Set("contentDir", "content") ns := New(newDeps(v)) - assert := require.New(t) + c := qt.New(t) _, err := ns.Remarshal("asdf", "asdf") - assert.Error(err) + c.Assert(err, qt.Not(qt.IsNil)) _, err = ns.Remarshal("json", "asdf") - assert.Error(err) + c.Assert(err, qt.Not(qt.IsNil)) } diff --git a/tpl/transform/transform_test.go b/tpl/transform/transform_test.go index a09ec6fbd..13c4bbc29 100644 --- a/tpl/transform/transform_test.go +++ b/tpl/transform/transform_test.go @@ -14,29 +14,28 @@ package transform import ( - "fmt" "html/template" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/langs" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) type tstNoStringer struct{} func TestEmojify(t *testing.T) { t.Parallel() + c := qt.New(t) v := viper.New() ns := New(newDeps(v)) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -45,28 +44,28 @@ func TestEmojify(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %s", i, test.s) result, err := ns.Emojify(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestHighlight(t *testing.T) { t.Parallel() + c := qt.New(t) v := viper.New() v.Set("contentDir", "content") ns := New(newDeps(v)) - for i, test := range []struct { + for _, test := range []struct { s interface{} lang string opts string @@ -77,28 +76,28 @@ func TestHighlight(t *testing.T) { {`<Foo attr=" < "></Foo>`, "xml", "", `&lt;`}, {tstNoStringer{}, "go", "", false}, } { - errMsg := fmt.Sprintf("[%d]", i) result, err := ns.Highlight(test.s, test.lang, test.opts) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Contains(t, result, test.expect.(string), errMsg) + c.Assert(err, qt.IsNil) + c.Assert(string(result), qt.Contains, test.expect.(string)) } } func TestHTMLEscape(t *testing.T) { t.Parallel() + c := qt.New(t) v := viper.New() v.Set("contentDir", "content") ns := New(newDeps(v)) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -107,28 +106,28 @@ func TestHTMLEscape(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %s", i, test.s) result, err := ns.HTMLEscape(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestHTMLUnescape(t *testing.T) { t.Parallel() + c := qt.New(t) v := viper.New() v.Set("contentDir", "content") ns := New(newDeps(v)) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -137,28 +136,28 @@ func TestHTMLUnescape(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %s", i, test.s) result, err := ns.HTMLUnescape(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } func TestMarkdownify(t *testing.T) { t.Parallel() + c := qt.New(t) v := viper.New() v.Set("contentDir", "content") ns := New(newDeps(v)) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -166,26 +165,23 @@ func TestMarkdownify(t *testing.T) { {[]byte("Hello Bytes **World!**"), template.HTML("Hello Bytes <strong>World!</strong>")}, {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %s", i, test.s) result, err := ns.Markdownify(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } // Issue #3040 func TestMarkdownifyBlocksOfText(t *testing.T) { t.Parallel() - - assert := require.New(t) - + c := qt.New(t) v := viper.New() v.Set("contentDir", "content") ns := New(newDeps(v)) @@ -203,20 +199,20 @@ And then some. ` result, err := ns.Markdownify(text) - assert.NoError(err) - assert.Equal(template.HTML( - "<p>#First</p>\n\n<p>This is some <em>bold</em> text.</p>\n\n<h2 id=\"second\">Second</h2>\n\n<p>This is some more text.</p>\n\n<p>And then some.</p>\n"), - result) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, template.HTML( + "<p>#First</p>\n\n<p>This is some <em>bold</em> text.</p>\n\n<h2 id=\"second\">Second</h2>\n\n<p>This is some more text.</p>\n\n<p>And then some.</p>\n")) } func TestPlainify(t *testing.T) { t.Parallel() + c := qt.New(t) v := viper.New() ns := New(newDeps(v)) - for i, test := range []struct { + for _, test := range []struct { s interface{} expect interface{} }{ @@ -224,17 +220,16 @@ func TestPlainify(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %s", i, test.s) result, err := ns.Plainify(test.s) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } diff --git a/tpl/transform/unmarshal_test.go b/tpl/transform/unmarshal_test.go index e91f680c2..7b0caa07f 100644 --- a/tpl/transform/unmarshal_test.go +++ b/tpl/transform/unmarshal_test.go @@ -23,9 +23,9 @@ import ( "github.com/gohugoio/hugo/media" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/resources/resource" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) const ( @@ -82,13 +82,13 @@ func TestUnmarshal(t *testing.T) { v := viper.New() ns := New(newDeps(v)) - assert := require.New(t) + c := qt.New(t) assertSlogan := func(m map[string]interface{}) { - assert.Equal("Hugo Rocks!", m["slogan"]) + c.Assert(m["slogan"], qt.Equals, "Hugo Rocks!") } - for i, test := range []struct { + for _, test := range []struct { data interface{} options interface{} expect interface{} @@ -113,27 +113,27 @@ func TestUnmarshal(t *testing.T) { }}, {testContentResource{key: "r1", content: `1997,Ford,E350,"ac, abs, moon",3000.00 1999,Chevy,"Venture ""Extended Edition""","",4900.00`, mime: media.CSVType}, nil, func(r [][]string) { - assert.Equal(2, len(r)) + c.Assert(len(r), qt.Equals, 2) first := r[0] - assert.Equal(5, len(first)) - assert.Equal("Ford", first[1]) + c.Assert(len(first), qt.Equals, 5) + c.Assert(first[1], qt.Equals, "Ford") }}, {testContentResource{key: "r1", content: `a;b;c`, mime: media.CSVType}, map[string]interface{}{"delimiter": ";"}, func(r [][]string) { - assert.Equal(r, [][]string{{"a", "b", "c"}}) + c.Assert([][]string{{"a", "b", "c"}}, qt.DeepEquals, r) }}, {"a,b,c", nil, func(r [][]string) { - assert.Equal(r, [][]string{{"a", "b", "c"}}) + c.Assert([][]string{{"a", "b", "c"}}, qt.DeepEquals, r) }}, {"a;b;c", map[string]interface{}{"delimiter": ";"}, func(r [][]string) { - assert.Equal(r, [][]string{{"a", "b", "c"}}) + c.Assert([][]string{{"a", "b", "c"}}, qt.DeepEquals, r) }}, {testContentResource{key: "r1", content: ` % This is a comment a;b;c`, mime: media.CSVType}, map[string]interface{}{"DElimiter": ";", "Comment": "%"}, func(r [][]string) { - assert.Equal(r, [][]string{{"a", "b", "c"}}) + c.Assert([][]string{{"a", "b", "c"}}, qt.DeepEquals, r) }}, // errors @@ -144,7 +144,6 @@ a;b;c`, mime: media.CSVType}, map[string]interface{}{"DElimiter": ";", "Comment" {`{ notjson }`, nil, false}, {tstNoStringer{}, nil, false}, } { - errMsg := fmt.Sprintf("[%d]", i) ns.cache.Clear() @@ -159,20 +158,20 @@ a;b;c`, mime: media.CSVType}, map[string]interface{}{"DElimiter": ";", "Comment" result, err := ns.Unmarshal(args...) if b, ok := test.expect.(bool); ok && !b { - assert.Error(err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) } else if fn, ok := test.expect.(func(m map[string]interface{})); ok { - assert.NoError(err, errMsg) + c.Assert(err, qt.IsNil) m, ok := result.(map[string]interface{}) - assert.True(ok, errMsg) + c.Assert(ok, qt.Equals, true) fn(m) } else if fn, ok := test.expect.(func(r [][]string)); ok { - assert.NoError(err, errMsg) + c.Assert(err, qt.IsNil) r, ok := result.([][]string) - assert.True(ok, errMsg) + c.Assert(ok, qt.Equals, true) fn(r) } else { - assert.NoError(err, errMsg) - assert.Equal(test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect) } } diff --git a/tpl/urls/init_test.go b/tpl/urls/init_test.go index a678ee6b1..f88aaf398 100644 --- a/tpl/urls/init_test.go +++ b/tpl/urls/init_test.go @@ -16,13 +16,15 @@ package urls import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" "github.com/spf13/viper" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -34,6 +36,6 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) } diff --git a/tpl/urls/urls_test.go b/tpl/urls/urls_test.go index 7bcef9cd5..9c005d2df 100644 --- a/tpl/urls/urls_test.go +++ b/tpl/urls/urls_test.go @@ -14,14 +14,14 @@ package urls import ( - "fmt" "net/url" "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var ns = New(&deps.Deps{Cfg: viper.New()}) @@ -30,8 +30,9 @@ type tstNoStringer struct{} func TestParse(t *testing.T) { t.Parallel() + c := qt.New(t) - for i, test := range []struct { + for _, test := range []struct { rawurl interface{} expect interface{} }{ @@ -53,16 +54,16 @@ func TestParse(t *testing.T) { // errors {tstNoStringer{}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) result, err := ns.Parse(test.rawurl) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil)) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, + qt.CmpEquals(hqt.DeepAllowUnexported(&url.URL{}, url.Userinfo{})), test.expect) } } |