OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // This package aids in the testing of code that uses channels. | 5 // This package aids in the testing of code that uses channels. |
6 package script | 6 package script |
7 | 7 |
8 import ( | 8 import ( |
9 "fmt" | 9 "fmt" |
10 "os" | 10 "os" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 func newEmptyInterface(e empty) reflect.Value { | 136 func newEmptyInterface(e empty) reflect.Value { |
137 return reflect.NewValue(e).(*reflect.StructValue).Field(0) | 137 return reflect.NewValue(e).(*reflect.StructValue).Field(0) |
138 } | 138 } |
139 | 139 |
140 func (s Send) send() { | 140 func (s Send) send() { |
141 // With reflect.ChanValue.Send, we must match the types exactly. So, if | 141 // With reflect.ChanValue.Send, we must match the types exactly. So, if |
142 // s.Channel is a chan interface{} we convert s.Value to an interface{} | 142 // s.Channel is a chan interface{} we convert s.Value to an interface{} |
143 // first. | 143 // first. |
144 c := reflect.NewValue(s.Channel).(*reflect.ChanValue) | 144 c := reflect.NewValue(s.Channel).(*reflect.ChanValue) |
145 var v reflect.Value | 145 var v reflect.Value |
146 » if iface, ok := c.Type().(*reflect.ChanType).Elem().(*reflect.InterfaceT
ype); ok && iface.NumMethod() == 0 { | 146 » if iface := c.Type().Elem(); iface.Kind() == reflect.Interface && iface.
NumMethod() == 0 { |
147 v = newEmptyInterface(empty{s.Value}) | 147 v = newEmptyInterface(empty{s.Value}) |
148 } else { | 148 } else { |
149 v = reflect.NewValue(s.Value) | 149 v = reflect.NewValue(s.Value) |
150 } | 150 } |
151 c.Send(v) | 151 c.Send(v) |
152 } | 152 } |
153 | 153 |
154 // A Close action closes the given channel. | 154 // A Close action closes the given channel. |
155 type Close struct { | 155 type Close struct { |
156 Channel interface{} | 156 Channel interface{} |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 continue | 350 continue |
351 } | 351 } |
352 names[j] = event.name | 352 names[j] = event.name |
353 } | 353 } |
354 | 354 |
355 return nil, SetupError("dependency cycle in events. These events
are waiting to run but cannot: " + strings.Join(names, ", ")) | 355 return nil, SetupError("dependency cycle in events. These events
are waiting to run but cannot: " + strings.Join(names, ", ")) |
356 } | 356 } |
357 | 357 |
358 return ready[0:j], nil | 358 return ready[0:j], nil |
359 } | 359 } |
OLD | NEW |