Upstream oklog/run state of the touched files before 8b4632a8c6
This commit is contained in:
1 parent
db24f770ca
commit
b0e6917276
2 files changed
+5
-27
No files matched your search
@@ -82,15 +82,14 @@ func (e SignalError) Is(err error) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// As fixes a design error in the SignalError type, so that errors.As with the
|
// As fixes a design error in the SignalError type, so that errors.As with the
|
||||||
// literal `&SignalError{}` will return true and, per the errors.As contract,
|
// literal `&SignalError{}` will return true.
|
||||||
// populate target with the underlying signal.
|
|
||||||
func (e SignalError) As(target interface{}) bool {
|
func (e SignalError) As(target interface{}) bool {
|
||||||
t, ok := target.(*SignalError)
|
switch target.(type) {
|
||||||
if !ok {
|
case *SignalError, SignalError:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
*t = e
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrSignal is returned by SignalHandler when a signal triggers termination.
|
// ErrSignal is returned by SignalHandler when a signal triggers termination.
|
||||||
|
|||||||
@@ -58,27 +58,6 @@ func TestSignalError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// errors.As must populate a value-typed SignalError target, not merely
|
|
||||||
// report a match; #27 made it return true without ever assigning.
|
|
||||||
func TestSignalErrorAsAssignsTarget(t *testing.T) {
|
|
||||||
testc := make(chan os.Signal, 1)
|
|
||||||
ctx := putTestSigChan(context.Background(), testc)
|
|
||||||
|
|
||||||
var rg Group
|
|
||||||
rg.Add(SignalHandler(ctx, os.Interrupt))
|
|
||||||
testc <- os.Interrupt
|
|
||||||
err := rg.Run()
|
|
||||||
|
|
||||||
var target SignalError
|
|
||||||
if want, have := true, errors.As(err, &target); want != have {
|
|
||||||
t.Fatalf("errors.As(err, &target): want %v, have %v", want, have)
|
|
||||||
}
|
|
||||||
|
|
||||||
if want, have := os.Interrupt, target.Signal; want != have {
|
|
||||||
t.Errorf("target.Signal: want %v, have %v (errors.As reported success but did not assign the target)", want, have)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSignalHandlerNil(t *testing.T) {
|
func TestSignalHandlerNil(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
var rg Group
|
var rg Group
|
||||||
|
|||||||
Reference in new issue
Block a user