Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-10 22:05:17 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-12 14:26:32 +0300
commit9e571827055dedb46b78c5db3d17d6913f14870b (patch)
treef5f0108afe0c9385ff6dc27664943d9f719f57ad /tpl/transform
parent6027ee11082d0b9d72de1d4d1980a702be294ad2 (diff)
tests: Convert from testify to quicktest
Diffstat (limited to 'tpl/transform')
-rw-r--r--tpl/transform/init_test.go8
-rw-r--r--tpl/transform/remarshal_test.go21
-rw-r--r--tpl/transform/transform_test.go75
-rw-r--r--tpl/transform/unmarshal_test.go37
4 files changed, 68 insertions, 73 deletions
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=" &lt; "></Foo>`, "xml", "", `&amp;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)
}
}