aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/compare/compare_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2019-04-29 10:48:36 +0200
committerBjørn Erik Pedersen <[email protected]>2019-04-29 18:43:44 +0200
commit66b143a01d1c192619839b732ce188923ab15d60 (patch)
tree17b6b8b9d4deea169640582949d8b696869e8440 /tpl/compare/compare_test.go
parent4f93f8c670b26258dc7e3a613c38dbc86d8eda76 (diff)
downloadhugo-66b143a01d1c192619839b732ce188923ab15d60.tar.gz
hugo-66b143a01d1c192619839b732ce188923ab15d60.zip
tpl/compare: Fix nil compare in eq/ne for interface values
Fixes #5905
Diffstat (limited to 'tpl/compare/compare_test.go')
-rw-r--r--tpl/compare/compare_test.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/tpl/compare/compare_test.go b/tpl/compare/compare_test.go
index d83680e53..6c4be7e50 100644
--- a/tpl/compare/compare_test.go
+++ b/tpl/compare/compare_test.go
@@ -27,6 +27,23 @@ import (
"github.com/stretchr/testify/require"
)
+type T struct {
+ NonEmptyInterfaceNil I
+ NonEmptyInterfaceTypedNil I
+}
+
+type I interface {
+ Foo() string
+}
+
+func (t *T) Foo() string {
+ return "foo"
+}
+
+var testT = &T{
+ NonEmptyInterfaceTypedNil: (*T)(nil),
+}
+
type tstEqerType1 string
type tstEqerType2 string
@@ -183,7 +200,12 @@ func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b inte
{"0.37-DEV", hugo.MustParseVersion("0.37").Version(), -1},
{"0.36", hugo.MustParseVersion("0.37-DEV").Version(), -1},
{"0.37-DEV", hugo.MustParseVersion("0.37-DEV").Version(), 0},
+ // https://github.com/gohugoio/hugo/issues/5905
+ {nil, nil, 0},
+ {testT.NonEmptyInterfaceNil, nil, 0},
+ {testT.NonEmptyInterfaceTypedNil, nil, 0},
} {
+
result := funcUnderTest(test.left, test.right)
success := false
@@ -206,7 +228,7 @@ func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b inte
}
if !success {
- t.Errorf("[%d][%s] %v compared to %v: %t", i, path.Base(runtime.FuncForPC(reflect.ValueOf(funcUnderTest).Pointer()).Name()), test.left, test.right, result)
+ t.Fatalf("[%d][%s] %v compared to %v: %t", i, path.Base(runtime.FuncForPC(reflect.ValueOf(funcUnderTest).Pointer()).Name()), test.left, test.right, result)
}
}
}