aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/testing
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-05-20 00:18:15 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-05-20 00:18:15 +0000
commit9ff56c9570642711d5b7ab29920ecf5dbff14a27 (patch)
treec891bdec1e6f073f73fedeef23718bc3ac30d499 /libgo/go/testing
parent37cb25ed7acdb844b218231130e54b8b7a0ff6e6 (diff)
downloadgcc-9ff56c9570642711d5b7ab29920ecf5dbff14a27.zip
gcc-9ff56c9570642711d5b7ab29920ecf5dbff14a27.tar.gz
gcc-9ff56c9570642711d5b7ab29920ecf5dbff14a27.tar.bz2
Update to current version of Go library.
From-SVN: r173931
Diffstat (limited to 'libgo/go/testing')
-rw-r--r--libgo/go/testing/iotest/reader.go3
-rw-r--r--libgo/go/testing/quick/quick.go120
-rw-r--r--libgo/go/testing/quick/quick_test.go2
-rw-r--r--libgo/go/testing/script/script.go16
-rw-r--r--libgo/go/testing/testing.go2
5 files changed, 70 insertions, 73 deletions
diff --git a/libgo/go/testing/iotest/reader.go b/libgo/go/testing/iotest/reader.go
index 647520a..e4003d7 100644
--- a/libgo/go/testing/iotest/reader.go
+++ b/libgo/go/testing/iotest/reader.go
@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// The iotest package implements Readers and Writers
-// useful only for testing.
+// Package iotest implements Readers and Writers useful only for testing.
package iotest
import (
diff --git a/libgo/go/testing/quick/quick.go b/libgo/go/testing/quick/quick.go
index a5568b0..756a60e 100644
--- a/libgo/go/testing/quick/quick.go
+++ b/libgo/go/testing/quick/quick.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// This package implements utility functions to help with black box testing.
+// Package quick implements utility functions to help with black box testing.
package quick
import (
@@ -53,96 +53,93 @@ const complexSize = 50
// If the type implements the Generator interface, that will be used.
// Note: in order to create arbitrary values for structs, all the members must be public.
func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) {
- if m, ok := reflect.MakeZero(t).Interface().(Generator); ok {
+ if m, ok := reflect.Zero(t).Interface().(Generator); ok {
return m.Generate(rand, complexSize), true
}
- switch concrete := t.(type) {
- case *reflect.BoolType:
- return reflect.NewValue(rand.Int()&1 == 0), true
- case *reflect.FloatType, *reflect.IntType, *reflect.UintType, *reflect.ComplexType:
- switch t.Kind() {
- case reflect.Float32:
- return reflect.NewValue(randFloat32(rand)), true
- case reflect.Float64:
- return reflect.NewValue(randFloat64(rand)), true
- case reflect.Complex64:
- return reflect.NewValue(complex(randFloat32(rand), randFloat32(rand))), true
- case reflect.Complex128:
- return reflect.NewValue(complex(randFloat64(rand), randFloat64(rand))), true
- case reflect.Int16:
- return reflect.NewValue(int16(randInt64(rand))), true
- case reflect.Int32:
- return reflect.NewValue(int32(randInt64(rand))), true
- case reflect.Int64:
- return reflect.NewValue(randInt64(rand)), true
- case reflect.Int8:
- return reflect.NewValue(int8(randInt64(rand))), true
- case reflect.Int:
- return reflect.NewValue(int(randInt64(rand))), true
- case reflect.Uint16:
- return reflect.NewValue(uint16(randInt64(rand))), true
- case reflect.Uint32:
- return reflect.NewValue(uint32(randInt64(rand))), true
- case reflect.Uint64:
- return reflect.NewValue(uint64(randInt64(rand))), true
- case reflect.Uint8:
- return reflect.NewValue(uint8(randInt64(rand))), true
- case reflect.Uint:
- return reflect.NewValue(uint(randInt64(rand))), true
- case reflect.Uintptr:
- return reflect.NewValue(uintptr(randInt64(rand))), true
- }
- case *reflect.MapType:
+ switch concrete := t; concrete.Kind() {
+ case reflect.Bool:
+ return reflect.ValueOf(rand.Int()&1 == 0), true
+ case reflect.Float32:
+ return reflect.ValueOf(randFloat32(rand)), true
+ case reflect.Float64:
+ return reflect.ValueOf(randFloat64(rand)), true
+ case reflect.Complex64:
+ return reflect.ValueOf(complex(randFloat32(rand), randFloat32(rand))), true
+ case reflect.Complex128:
+ return reflect.ValueOf(complex(randFloat64(rand), randFloat64(rand))), true
+ case reflect.Int16:
+ return reflect.ValueOf(int16(randInt64(rand))), true
+ case reflect.Int32:
+ return reflect.ValueOf(int32(randInt64(rand))), true
+ case reflect.Int64:
+ return reflect.ValueOf(randInt64(rand)), true
+ case reflect.Int8:
+ return reflect.ValueOf(int8(randInt64(rand))), true
+ case reflect.Int:
+ return reflect.ValueOf(int(randInt64(rand))), true
+ case reflect.Uint16:
+ return reflect.ValueOf(uint16(randInt64(rand))), true
+ case reflect.Uint32:
+ return reflect.ValueOf(uint32(randInt64(rand))), true
+ case reflect.Uint64:
+ return reflect.ValueOf(uint64(randInt64(rand))), true
+ case reflect.Uint8:
+ return reflect.ValueOf(uint8(randInt64(rand))), true
+ case reflect.Uint:
+ return reflect.ValueOf(uint(randInt64(rand))), true
+ case reflect.Uintptr:
+ return reflect.ValueOf(uintptr(randInt64(rand))), true
+ case reflect.Map:
numElems := rand.Intn(complexSize)
m := reflect.MakeMap(concrete)
for i := 0; i < numElems; i++ {
key, ok1 := Value(concrete.Key(), rand)
value, ok2 := Value(concrete.Elem(), rand)
if !ok1 || !ok2 {
- return nil, false
+ return reflect.Value{}, false
}
- m.SetElem(key, value)
+ m.SetMapIndex(key, value)
}
return m, true
- case *reflect.PtrType:
+ case reflect.Ptr:
v, ok := Value(concrete.Elem(), rand)
if !ok {
- return nil, false
+ return reflect.Value{}, false
}
- p := reflect.MakeZero(concrete)
- p.(*reflect.PtrValue).PointTo(v)
+ p := reflect.New(concrete.Elem())
+ p.Elem().Set(v)
return p, true
- case *reflect.SliceType:
+ case reflect.Slice:
numElems := rand.Intn(complexSize)
s := reflect.MakeSlice(concrete, numElems, numElems)
for i := 0; i < numElems; i++ {
v, ok := Value(concrete.Elem(), rand)
if !ok {
- return nil, false
+ return reflect.Value{}, false
}
- s.Elem(i).SetValue(v)
+ s.Index(i).Set(v)
}
return s, true
- case *reflect.StringType:
+ case reflect.String:
numChars := rand.Intn(complexSize)
codePoints := make([]int, numChars)
for i := 0; i < numChars; i++ {
codePoints[i] = rand.Intn(0x10ffff)
}
- return reflect.NewValue(string(codePoints)), true
- case *reflect.StructType:
- s := reflect.MakeZero(t).(*reflect.StructValue)
+ return reflect.ValueOf(string(codePoints)), true
+ case reflect.Struct:
+ s := reflect.New(t).Elem()
for i := 0; i < s.NumField(); i++ {
v, ok := Value(concrete.Field(i).Type, rand)
if !ok {
- return nil, false
+ return reflect.Value{}, false
}
- s.Field(i).SetValue(v)
+ s.Field(i).Set(v)
}
return s, true
default:
- return nil, false
+ return reflect.Value{}, false
}
return
@@ -247,7 +244,7 @@ func Check(function interface{}, config *Config) (err os.Error) {
err = SetupError("function returns more than one value.")
return
}
- if _, ok := fType.Out(0).(*reflect.BoolType); !ok {
+ if fType.Out(0).Kind() != reflect.Bool {
err = SetupError("function does not return a bool")
return
}
@@ -262,7 +259,7 @@ func Check(function interface{}, config *Config) (err os.Error) {
return
}
- if !f.Call(arguments)[0].(*reflect.BoolValue).Get() {
+ if !f.Call(arguments)[0].Bool() {
err = &CheckError{i + 1, toInterfaces(arguments)}
return
}
@@ -320,7 +317,7 @@ func CheckEqual(f, g interface{}, config *Config) (err os.Error) {
// arbitraryValues writes Values to args such that args contains Values
// suitable for calling f.
-func arbitraryValues(args []reflect.Value, f *reflect.FuncType, config *Config, rand *rand.Rand) (err os.Error) {
+func arbitraryValues(args []reflect.Value, f reflect.Type, config *Config, rand *rand.Rand) (err os.Error) {
if config.Values != nil {
config.Values(args, rand)
return
@@ -338,12 +335,13 @@ func arbitraryValues(args []reflect.Value, f *reflect.FuncType, config *Config,
return
}
-func functionAndType(f interface{}) (v *reflect.FuncValue, t *reflect.FuncType, ok bool) {
- v, ok = reflect.NewValue(f).(*reflect.FuncValue)
+func functionAndType(f interface{}) (v reflect.Value, t reflect.Type, ok bool) {
+ v = reflect.ValueOf(f)
+ ok = v.Kind() == reflect.Func
if !ok {
return
}
- t = v.Type().(*reflect.FuncType)
+ t = v.Type()
return
}
diff --git a/libgo/go/testing/quick/quick_test.go b/libgo/go/testing/quick/quick_test.go
index b126e4a..f2618c3 100644
--- a/libgo/go/testing/quick/quick_test.go
+++ b/libgo/go/testing/quick/quick_test.go
@@ -102,7 +102,7 @@ type myStruct struct {
}
func (m myStruct) Generate(r *rand.Rand, _ int) reflect.Value {
- return reflect.NewValue(myStruct{x: 42})
+ return reflect.ValueOf(myStruct{x: 42})
}
func myStructProperty(in myStruct) bool { return in.x == 42 }
diff --git a/libgo/go/testing/script/script.go b/libgo/go/testing/script/script.go
index b341b1f..afb286f 100644
--- a/libgo/go/testing/script/script.go
+++ b/libgo/go/testing/script/script.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// This package aids in the testing of code that uses channels.
+// Package script aids in the testing of code that uses channels.
package script
import (
@@ -134,19 +134,19 @@ type empty struct {
}
func newEmptyInterface(e empty) reflect.Value {
- return reflect.NewValue(e).(*reflect.StructValue).Field(0)
+ return reflect.ValueOf(e).Field(0)
}
func (s Send) send() {
// With reflect.ChanValue.Send, we must match the types exactly. So, if
// s.Channel is a chan interface{} we convert s.Value to an interface{}
// first.
- c := reflect.NewValue(s.Channel).(*reflect.ChanValue)
+ c := reflect.ValueOf(s.Channel)
var v reflect.Value
- if iface, ok := c.Type().(*reflect.ChanType).Elem().(*reflect.InterfaceType); ok && iface.NumMethod() == 0 {
+ if iface := c.Type().Elem(); iface.Kind() == reflect.Interface && iface.NumMethod() == 0 {
v = newEmptyInterface(empty{s.Value})
} else {
- v = reflect.NewValue(s.Value)
+ v = reflect.ValueOf(s.Value)
}
c.Send(v)
}
@@ -162,7 +162,7 @@ func (s Close) getSend() sendAction { return s }
func (s Close) getChannel() interface{} { return s.Channel }
-func (s Close) send() { reflect.NewValue(s.Channel).(*reflect.ChanValue).Close() }
+func (s Close) send() { reflect.ValueOf(s.Channel).Close() }
// A ReceivedUnexpected error results if no active Events match a value
// received from a channel.
@@ -278,7 +278,7 @@ func getChannels(events []*Event) ([]interface{}, os.Error) {
continue
}
c := event.action.getChannel()
- if _, ok := reflect.NewValue(c).(*reflect.ChanValue); !ok {
+ if reflect.ValueOf(c).Kind() != reflect.Chan {
return nil, SetupError("one of the channel values is not a channel")
}
@@ -303,7 +303,7 @@ func getChannels(events []*Event) ([]interface{}, os.Error) {
// channel repeatedly, wrapping them up as either a channelRecv or
// channelClosed structure, and forwards them to the multiplex channel.
func recvValues(multiplex chan<- interface{}, channel interface{}) {
- c := reflect.NewValue(channel).(*reflect.ChanValue)
+ c := reflect.ValueOf(channel)
for {
v, ok := c.Recv()
diff --git a/libgo/go/testing/testing.go b/libgo/go/testing/testing.go
index 1e65528..8781b20 100644
--- a/libgo/go/testing/testing.go
+++ b/libgo/go/testing/testing.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// The testing package provides support for automated testing of Go packages.
+// Package testing provides support for automated testing of Go packages.
// It is intended to be used in concert with the ``gotest'' utility, which automates
// execution of any function of the form
// func TestXxx(*testing.T)