aboutsummaryrefslogtreecommitdiffhomepage
path: root/output
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2019-08-10 21:05:17 +0200
committerBjørn Erik Pedersen <[email protected]>2019-08-12 13:26:32 +0200
commit9e571827055dedb46b78c5db3d17d6913f14870b (patch)
treef5f0108afe0c9385ff6dc27664943d9f719f57ad /output
parent6027ee11082d0b9d72de1d4d1980a702be294ad2 (diff)
downloadhugo-9e571827055dedb46b78c5db3d17d6913f14870b.tar.gz
hugo-9e571827055dedb46b78c5db3d17d6913f14870b.zip
tests: Convert from testify to quicktest
Diffstat (limited to 'output')
-rw-r--r--output/layout_base_test.go10
-rw-r--r--output/layout_test.go16
-rw-r--r--output/outputFormat_test.go185
3 files changed, 116 insertions, 95 deletions
diff --git a/output/layout_base_test.go b/output/layout_base_test.go
index 25294c918..8eea9e61e 100644
--- a/output/layout_base_test.go
+++ b/output/layout_base_test.go
@@ -18,10 +18,11 @@ import (
"strings"
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestLayoutBase(t *testing.T) {
+ c := qt.New(t)
var (
workingDir = "/sites/mysite/"
@@ -117,7 +118,7 @@ func TestLayoutBase(t *testing.T) {
MasterFilename: "_default/single-baseof.json",
}},
} {
- t.Run(this.name, func(t *testing.T) {
+ c.Run(this.name, func(c *qt.C) {
this.basePathMatchStrings = filepath.FromSlash(this.basePathMatchStrings)
@@ -152,8 +153,9 @@ func TestLayoutBase(t *testing.T) {
id, err := CreateTemplateNames(this.d)
- require.NoError(t, err)
- require.Equal(t, this.expect, id, this.name)
+ c.Assert(err, qt.IsNil)
+ msg := qt.Commentf(this.name)
+ c.Assert(id, qt.Equals, this.expect, msg)
})
}
diff --git a/output/layout_test.go b/output/layout_test.go
index e5f2b5b6f..c6267b274 100644
--- a/output/layout_test.go
+++ b/output/layout_test.go
@@ -21,10 +21,11 @@ import (
"github.com/gohugoio/hugo/media"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestLayout(t *testing.T) {
+ c := qt.New(t)
noExtNoDelimMediaType := media.TextType
noExtNoDelimMediaType.Suffixes = nil
@@ -111,14 +112,14 @@ func TestLayout(t *testing.T) {
{"Reserved section, partials", LayoutDescriptor{Kind: "section", Section: "partials", Type: "partials"}, "", ampType,
[]string{"section/partials.amp.html"}, 12},
} {
- t.Run(this.name, func(t *testing.T) {
+ c.Run(this.name, func(c *qt.C) {
l := NewLayoutHandler()
layouts, err := l.For(this.d, this.tp)
- require.NoError(t, err)
- require.NotNil(t, layouts)
- require.True(t, len(layouts) >= len(this.expect), fmt.Sprint(layouts))
+ c.Assert(err, qt.IsNil)
+ c.Assert(layouts, qt.Not(qt.IsNil))
+ c.Assert(len(layouts) >= len(this.expect), qt.Equals, true)
// Not checking the complete list for now ...
got := layouts[:len(this.expect)]
if len(layouts) != this.expectCount || !reflect.DeepEqual(got, this.expect) {
@@ -136,12 +137,13 @@ func TestLayout(t *testing.T) {
}
func BenchmarkLayout(b *testing.B) {
+ c := qt.New(b)
descriptor := LayoutDescriptor{Kind: "taxonomyTerm", Section: "categories"}
l := NewLayoutHandler()
for i := 0; i < b.N; i++ {
layouts, err := l.For(descriptor, HTMLFormat)
- require.NoError(b, err)
- require.NotEmpty(b, layouts)
+ c.Assert(err, qt.IsNil)
+ c.Assert(layouts, qt.Not(qt.HasLen), 0)
}
}
diff --git a/output/outputFormat_test.go b/output/outputFormat_test.go
index aef1403a9..2b10c5a9e 100644
--- a/output/outputFormat_test.go
+++ b/output/outputFormat_test.go
@@ -14,88 +14,101 @@
package output
import (
- "fmt"
"sort"
"testing"
+ qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/media"
- "github.com/stretchr/testify/require"
+ "github.com/google/go-cmp/cmp"
+)
+
+var eq = qt.CmpEquals(
+ cmp.Comparer(func(m1, m2 media.Type) bool {
+ return m1.Type() == m2.Type()
+ }),
+ cmp.Comparer(func(o1, o2 Format) bool {
+ return o1.Name == o2.Name
+ }),
)
func TestDefaultTypes(t *testing.T) {
- require.Equal(t, "Calendar", CalendarFormat.Name)
- require.Equal(t, media.CalendarType, CalendarFormat.MediaType)
- require.Equal(t, "webcal://", CalendarFormat.Protocol)
- require.Empty(t, CalendarFormat.Path)
- require.True(t, CalendarFormat.IsPlainText)
- require.False(t, CalendarFormat.IsHTML)
-
- require.Equal(t, "CSS", CSSFormat.Name)
- require.Equal(t, media.CSSType, CSSFormat.MediaType)
- require.Empty(t, CSSFormat.Path)
- require.Empty(t, CSSFormat.Protocol) // Will inherit the BaseURL protocol.
- require.True(t, CSSFormat.IsPlainText)
- require.False(t, CSSFormat.IsHTML)
-
- require.Equal(t, "CSV", CSVFormat.Name)
- require.Equal(t, media.CSVType, CSVFormat.MediaType)
- require.Empty(t, CSVFormat.Path)
- require.Empty(t, CSVFormat.Protocol)
- require.True(t, CSVFormat.IsPlainText)
- require.False(t, CSVFormat.IsHTML)
- require.False(t, CSVFormat.Permalinkable)
-
- require.Equal(t, "HTML", HTMLFormat.Name)
- require.Equal(t, media.HTMLType, HTMLFormat.MediaType)
- require.Empty(t, HTMLFormat.Path)
- require.Empty(t, HTMLFormat.Protocol)
- require.False(t, HTMLFormat.IsPlainText)
- require.True(t, HTMLFormat.IsHTML)
- require.True(t, AMPFormat.Permalinkable)
-
- require.Equal(t, "AMP", AMPFormat.Name)
- require.Equal(t, media.HTMLType, AMPFormat.MediaType)
- require.Equal(t, "amp", AMPFormat.Path)
- require.Empty(t, AMPFormat.Protocol)
- require.False(t, AMPFormat.IsPlainText)
- require.True(t, AMPFormat.IsHTML)
- require.True(t, AMPFormat.Permalinkable)
-
- require.Equal(t, "RSS", RSSFormat.Name)
- require.Equal(t, media.RSSType, RSSFormat.MediaType)
- require.Empty(t, RSSFormat.Path)
- require.False(t, RSSFormat.IsPlainText)
- require.True(t, RSSFormat.NoUgly)
- require.False(t, CalendarFormat.IsHTML)
+ c := qt.New(t)
+ c.Assert(CalendarFormat.Name, qt.Equals, "Calendar")
+ c.Assert(CalendarFormat.MediaType, eq, media.CalendarType)
+ c.Assert(CalendarFormat.Protocol, qt.Equals, "webcal://")
+ c.Assert(CalendarFormat.Path, qt.HasLen, 0)
+ c.Assert(CalendarFormat.IsPlainText, qt.Equals, true)
+ c.Assert(CalendarFormat.IsHTML, qt.Equals, false)
+
+ c.Assert(CSSFormat.Name, qt.Equals, "CSS")
+ c.Assert(CSSFormat.MediaType, eq, media.CSSType)
+ c.Assert(CSSFormat.Path, qt.HasLen, 0)
+ c.Assert(CSSFormat.Protocol, qt.HasLen, 0) // Will inherit the BaseURL protocol.
+ c.Assert(CSSFormat.IsPlainText, qt.Equals, true)
+ c.Assert(CSSFormat.IsHTML, qt.Equals, false)
+
+ c.Assert(CSVFormat.Name, qt.Equals, "CSV")
+ c.Assert(CSVFormat.MediaType, eq, media.CSVType)
+ c.Assert(CSVFormat.Path, qt.HasLen, 0)
+ c.Assert(CSVFormat.Protocol, qt.HasLen, 0)
+ c.Assert(CSVFormat.IsPlainText, qt.Equals, true)
+ c.Assert(CSVFormat.IsHTML, qt.Equals, false)
+ c.Assert(CSVFormat.Permalinkable, qt.Equals, false)
+
+ c.Assert(HTMLFormat.Name, qt.Equals, "HTML")
+ c.Assert(HTMLFormat.MediaType, eq, media.HTMLType)
+ c.Assert(HTMLFormat.Path, qt.HasLen, 0)
+ c.Assert(HTMLFormat.Protocol, qt.HasLen, 0)
+ c.Assert(HTMLFormat.IsPlainText, qt.Equals, false)
+ c.Assert(HTMLFormat.IsHTML, qt.Equals, true)
+ c.Assert(AMPFormat.Permalinkable, qt.Equals, true)
+
+ c.Assert(AMPFormat.Name, qt.Equals, "AMP")
+ c.Assert(AMPFormat.MediaType, eq, media.HTMLType)
+ c.Assert(AMPFormat.Path, qt.Equals, "amp")
+ c.Assert(AMPFormat.Protocol, qt.HasLen, 0)
+ c.Assert(AMPFormat.IsPlainText, qt.Equals, false)
+ c.Assert(AMPFormat.IsHTML, qt.Equals, true)
+ c.Assert(AMPFormat.Permalinkable, qt.Equals, true)
+
+ c.Assert(RSSFormat.Name, qt.Equals, "RSS")
+ c.Assert(RSSFormat.MediaType, eq, media.RSSType)
+ c.Assert(RSSFormat.Path, qt.HasLen, 0)
+ c.Assert(RSSFormat.IsPlainText, qt.Equals, false)
+ c.Assert(RSSFormat.NoUgly, qt.Equals, true)
+ c.Assert(CalendarFormat.IsHTML, qt.Equals, false)
}
func TestGetFormatByName(t *testing.T) {
+ c := qt.New(t)
formats := Formats{AMPFormat, CalendarFormat}
tp, _ := formats.GetByName("AMp")
- require.Equal(t, AMPFormat, tp)
+ c.Assert(tp, eq, AMPFormat)
_, found := formats.GetByName("HTML")
- require.False(t, found)
+ c.Assert(found, qt.Equals, false)
_, found = formats.GetByName("FOO")
- require.False(t, found)
+ c.Assert(found, qt.Equals, false)
}
func TestGetFormatByExt(t *testing.T) {
+ c := qt.New(t)
formats1 := Formats{AMPFormat, CalendarFormat}
formats2 := Formats{AMPFormat, HTMLFormat, CalendarFormat}
tp, _ := formats1.GetBySuffix("html")
- require.Equal(t, AMPFormat, tp)
+ c.Assert(tp, eq, AMPFormat)
tp, _ = formats1.GetBySuffix("ics")
- require.Equal(t, CalendarFormat, tp)
+ c.Assert(tp, eq, CalendarFormat)
_, found := formats1.GetBySuffix("not")
- require.False(t, found)
+ c.Assert(found, qt.Equals, false)
// ambiguous
_, found = formats2.GetBySuffix("html")
- require.False(t, found)
+ c.Assert(found, qt.Equals, false)
}
func TestGetFormatByFilename(t *testing.T) {
+ c := qt.New(t)
noExtNoDelimMediaType := media.TextType
noExtNoDelimMediaType.Delimiter = ""
@@ -116,25 +129,26 @@ func TestGetFormatByFilename(t *testing.T) {
formats := Formats{AMPFormat, HTMLFormat, noExtDelimFormat, noExt, CalendarFormat}
f, found := formats.FromFilename("my.amp.html")
- require.True(t, found)
- require.Equal(t, AMPFormat, f)
+ c.Assert(found, qt.Equals, true)
+ c.Assert(f, eq, AMPFormat)
_, found = formats.FromFilename("my.ics")
- require.True(t, found)
+ c.Assert(found, qt.Equals, true)
f, found = formats.FromFilename("my.html")
- require.True(t, found)
- require.Equal(t, HTMLFormat, f)
+ c.Assert(found, qt.Equals, true)
+ c.Assert(f, eq, HTMLFormat)
f, found = formats.FromFilename("my.nem")
- require.True(t, found)
- require.Equal(t, noExtDelimFormat, f)
+ c.Assert(found, qt.Equals, true)
+ c.Assert(f, eq, noExtDelimFormat)
f, found = formats.FromFilename("my.nex")
- require.True(t, found)
- require.Equal(t, noExt, f)
+ c.Assert(found, qt.Equals, true)
+ c.Assert(f, eq, noExt)
_, found = formats.FromFilename("my.css")
- require.False(t, found)
+ c.Assert(found, qt.Equals, false)
}
func TestDecodeFormats(t *testing.T) {
+ c := qt.New(t)
mediaTypes := media.Types{media.JSONType, media.XMLType}
@@ -153,11 +167,12 @@ func TestDecodeFormats(t *testing.T) {
"isPlainText": "false"}}},
false,
func(t *testing.T, name string, f Formats) {
- require.Len(t, f, len(DefaultFormats), name)
+ msg := qt.Commentf(name)
+ c.Assert(len(f), qt.Equals, len(DefaultFormats), msg)
json, _ := f.GetByName("JSON")
- require.Equal(t, "myindex", json.BaseName)
- require.Equal(t, media.JSONType, json.MediaType)
- require.False(t, json.IsPlainText)
+ c.Assert(json.BaseName, qt.Equals, "myindex")
+ c.Assert(json.MediaType, eq, media.JSONType)
+ c.Assert(json.IsPlainText, qt.Equals, false)
}},
{
@@ -170,15 +185,15 @@ func TestDecodeFormats(t *testing.T) {
}}},
false,
func(t *testing.T, name string, f Formats) {
- require.Len(t, f, len(DefaultFormats)+1, name)
+ c.Assert(len(f), qt.Equals, len(DefaultFormats)+1)
xml, found := f.GetByName("MYXMLFORMAT")
- require.True(t, found)
- require.Equal(t, "myxml", xml.BaseName, fmt.Sprint(xml))
- require.Equal(t, media.XMLType, xml.MediaType)
+ c.Assert(found, qt.Equals, true)
+ c.Assert(xml.BaseName, qt.Equals, "myxml")
+ c.Assert(xml.MediaType, eq, media.XMLType)
// Verify that we haven't changed the DefaultFormats slice.
json, _ := f.GetByName("JSON")
- require.Equal(t, "index", json.BaseName, name)
+ c.Assert(json.BaseName, qt.Equals, "index")
}},
{
@@ -208,29 +223,31 @@ func TestDecodeFormats(t *testing.T) {
},
false,
func(t *testing.T, name string, f Formats) {
- require.Len(t, f, len(DefaultFormats)+1, name)
+ c.Assert(len(f), qt.Equals, len(DefaultFormats)+1)
xml, found := f.GetByName("MYOTHERXMLFORMAT")
- require.True(t, found)
- require.Equal(t, "myredefined", xml.BaseName, fmt.Sprint(xml))
- require.Equal(t, media.XMLType, xml.MediaType)
+ c.Assert(found, qt.Equals, true)
+ c.Assert(xml.BaseName, qt.Equals, "myredefined")
+ c.Assert(xml.MediaType, eq, media.XMLType)
}},
}
for _, test := range tests {
result, err := DecodeFormats(mediaTypes, test.maps...)
+ msg := qt.Commentf(test.name)
+
if test.shouldError {
- require.Error(t, err, test.name)
+ c.Assert(err, qt.Not(qt.IsNil), msg)
} else {
- require.NoError(t, err, test.name)
+ c.Assert(err, qt.IsNil, msg)
test.assert(t, test.name, result)
}
}
}
func TestSort(t *testing.T) {
- assert := require.New(t)
- assert.Equal("HTML", DefaultFormats[0].Name)
- assert.Equal("AMP", DefaultFormats[1].Name)
+ c := qt.New(t)
+ c.Assert(DefaultFormats[0].Name, qt.Equals, "HTML")
+ c.Assert(DefaultFormats[1].Name, qt.Equals, "AMP")
json := JSONFormat
json.Weight = 1
@@ -243,8 +260,8 @@ func TestSort(t *testing.T) {
sort.Sort(formats)
- assert.Equal("JSON", formats[0].Name)
- assert.Equal("HTML", formats[1].Name)
- assert.Equal("AMP", formats[2].Name)
+ c.Assert(formats[0].Name, qt.Equals, "JSON")
+ c.Assert(formats[1].Name, qt.Equals, "HTML")
+ c.Assert(formats[2].Name, qt.Equals, "AMP")
}