mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
tests: Convert from testify to quicktest
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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{})
|
||||
}
|
||||
|
@@ -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)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user