aboutsummaryrefslogtreecommitdiff
path: root/src/testing/quick/quick.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/quick/quick.go')
-rw-r--r--src/testing/quick/quick.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/testing/quick/quick.go b/src/testing/quick/quick.go
index 35b7b636b4..0e36810eb6 100644
--- a/src/testing/quick/quick.go
+++ b/src/testing/quick/quick.go
@@ -102,12 +102,16 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) {
v.SetMapIndex(key, value)
}
case reflect.Ptr:
- elem, ok := Value(concrete.Elem(), rand)
- if !ok {
- return reflect.Value{}, false
+ if rand.Intn(complexSize) == 0 {
+ v.Set(reflect.Zero(concrete)) // Generate nil pointer.
+ } else {
+ elem, ok := Value(concrete.Elem(), rand)
+ if !ok {
+ return reflect.Value{}, false
+ }
+ v.Set(reflect.New(concrete.Elem()))
+ v.Elem().Set(elem)
}
- v.Set(reflect.New(concrete.Elem()))
- v.Elem().Set(elem)
case reflect.Slice:
numElems := rand.Intn(complexSize)
v.Set(reflect.MakeSlice(concrete, numElems, numElems))