1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 func fBool(a bool) bool { return a }
16 func fFloat32(a float32) float32 { return a }
18 func fFloat64(a float64) float64 { return a }
20 func fComplex64(a complex64) complex64 { return a }
22 func fComplex128(a complex128) complex128 { return a }
24 func fInt16(a int16) int16 { return a }
26 func fInt32(a int32) int32 { return a }
28 func fInt64(a int64) int64 { return a }
30 func fInt8(a int8) int8 { return a }
32 func fInt(a int) int { return a }
34 func fUInt8(a uint8) uint8 { return a }
36 func fMap(a map[int]int) map[int]int { return a }
38 func fSlice(a []byte) []byte { return a }
40 func fString(a string) string { return a }
42 type TestStruct struct {
47 func fStruct(a TestStruct) TestStruct { return a }
49 func fUint16(a uint16) uint16 { return a }
51 func fUint32(a uint32) uint32 { return a }
53 func fUint64(a uint64) uint64 { return a }
55 func fUint8(a uint8) uint8 { return a }
57 func fUint(a uint) uint { return a }
59 func fUintptr(a uintptr) uintptr { return a }
61 func fIntptr(a *int) *int {
66 func reportError(property string, err os.Error, t *testing.T) {
68 t.Errorf("%s: %s", property, err)
72 func TestCheckEqual(t *testing.T) {
73 reportError("fBool", CheckEqual(fBool, fBool, nil), t)
74 reportError("fFloat32", CheckEqual(fFloat32, fFloat32, nil), t)
75 reportError("fFloat64", CheckEqual(fFloat64, fFloat64, nil), t)
76 reportError("fComplex64", CheckEqual(fComplex64, fComplex64, nil), t)
77 reportError("fComplex128", CheckEqual(fComplex128, fComplex128, nil), t)
78 reportError("fInt16", CheckEqual(fInt16, fInt16, nil), t)
79 reportError("fInt32", CheckEqual(fInt32, fInt32, nil), t)
80 reportError("fInt64", CheckEqual(fInt64, fInt64, nil), t)
81 reportError("fInt8", CheckEqual(fInt8, fInt8, nil), t)
82 reportError("fInt", CheckEqual(fInt, fInt, nil), t)
83 reportError("fUInt8", CheckEqual(fUInt8, fUInt8, nil), t)
84 reportError("fInt32", CheckEqual(fInt32, fInt32, nil), t)
85 reportError("fMap", CheckEqual(fMap, fMap, nil), t)
86 reportError("fSlice", CheckEqual(fSlice, fSlice, nil), t)
87 reportError("fString", CheckEqual(fString, fString, nil), t)
88 reportError("fStruct", CheckEqual(fStruct, fStruct, nil), t)
89 reportError("fUint16", CheckEqual(fUint16, fUint16, nil), t)
90 reportError("fUint32", CheckEqual(fUint32, fUint32, nil), t)
91 reportError("fUint64", CheckEqual(fUint64, fUint64, nil), t)
92 reportError("fUint8", CheckEqual(fUint8, fUint8, nil), t)
93 reportError("fUint", CheckEqual(fUint, fUint, nil), t)
94 reportError("fUintptr", CheckEqual(fUintptr, fUintptr, nil), t)
95 reportError("fIntptr", CheckEqual(fIntptr, fIntptr, nil), t)
98 // This tests that ArbitraryValue is working by checking that all the arbitrary
99 // values of type MyStruct have x = 42.
100 type myStruct struct {
104 func (m myStruct) Generate(r *rand.Rand, _ int) reflect.Value {
105 return reflect.ValueOf(myStruct{x: 42})
108 func myStructProperty(in myStruct) bool { return in.x == 42 }
110 func TestCheckProperty(t *testing.T) {
111 reportError("myStructProperty", Check(myStructProperty, nil), t)
114 func TestFailure(t *testing.T) {
115 f := func(x int) bool { return false }
118 t.Errorf("Check didn't return an error")
120 if _, ok := err.(*CheckError); !ok {
121 t.Errorf("Error was not a CheckError: %s", err)
124 err = CheckEqual(fUint, fUint32, nil)
126 t.Errorf("#1 CheckEqual didn't return an error")
128 if _, ok := err.(SetupError); !ok {
129 t.Errorf("#1 Error was not a SetupError: %s", err)
132 err = CheckEqual(func(x, y int) {}, func(x int) {}, nil)
134 t.Errorf("#2 CheckEqual didn't return an error")
136 if _, ok := err.(SetupError); !ok {
137 t.Errorf("#2 Error was not a SetupError: %s", err)
140 err = CheckEqual(func(x int) int { return 0 }, func(x int) int32 { return 0 }, nil)
142 t.Errorf("#3 CheckEqual didn't return an error")
144 if _, ok := err.(SetupError); !ok {
145 t.Errorf("#3 Error was not a SetupError: %s", err)