Skip to content

Commit

Permalink
runtime: test Goexit/defer iteraction.
Browse files Browse the repository at this point in the history
Make sure Goexit runs defers.
Make sure recover() during a Goexit defer returns nil.

LGTM=dvyukov, bradfitz
R=golang-codereviews, dvyukov, bradfitz, khr
CC=golang-codereviews
https://golang.org/cl/140650043
  • Loading branch information
randall77 committed Sep 15, 2014
1 parent 1e4f86e commit 7e62316
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/runtime/crash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ func TestGoexitCrash(t *testing.T) {
}
}

func TestGoexitDefer(t *testing.T) {
c := make(chan struct{})
go func() {
defer func() {
r := recover()
if r != nil {
t.Errorf("non-nil recover during Goexit")
}
c <- struct{}{}
}()
runtime.Goexit()
}()
// Note: if the defer fails to run, we will get a deadlock here
<-c
}

func TestGoNil(t *testing.T) {
output := executeTest(t, goNilSource, nil)
want := "go of nil func value"
Expand Down

0 comments on commit 7e62316

Please sign in to comment.