]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: add direct call tests to TestMakeFuncVariadic
authorMichael Hudson-Doyle <michael.hudson@linaro.org>
Wed, 8 Oct 2014 22:58:56 +0000 (15:58 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 8 Oct 2014 22:58:56 +0000 (15:58 -0700)
TestMakeFuncVariadic only called the variadic function via Call and
CallSlice, not via a direct function call.

I thought these tests would fail under gccgo tip, but they don't.  Still seems worth having though.

LGTM=iant
R=golang-codereviews, gobot, iant
CC=golang-codereviews
https://golang.org/cl/152060043

src/reflect/all_test.go

index f13b91b742b93121430bad6f8a71cda5e81e3dc3..f0cd6a41280977b2683746d59479a2e57da89370 100644 (file)
@@ -1543,7 +1543,17 @@ func TestMakeFuncVariadic(t *testing.T) {
        fv := MakeFunc(TypeOf(fn), func(in []Value) []Value { return in[1:2] })
        ValueOf(&fn).Elem().Set(fv)
 
-       r := fv.Call([]Value{ValueOf(1), ValueOf(2), ValueOf(3)})[0].Interface().([]int)
+       r := fn(1, 2, 3)
+       if r[0] != 2 || r[1] != 3 {
+               t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
+       }
+
+       r = fn(1, []int{2, 3}...)
+       if r[0] != 2 || r[1] != 3 {
+               t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
+       }
+
+       r = fv.Call([]Value{ValueOf(1), ValueOf(2), ValueOf(3)})[0].Interface().([]int)
        if r[0] != 2 || r[1] != 3 {
                t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
        }
@@ -1552,6 +1562,17 @@ func TestMakeFuncVariadic(t *testing.T) {
        if r[0] != 2 || r[1] != 3 {
                t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
        }
+
+       f := fv.Interface().(func(int, ...int) []int)
+
+       r = f(1, 2, 3)
+       if r[0] != 2 || r[1] != 3 {
+               t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
+       }
+       r = f(1, []int{2, 3}...)
+       if r[0] != 2 || r[1] != 3 {
+               t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
+       }
 }
 
 type Point struct {