Skip to content

Commit

Permalink
Apply PR-136 by @liggitt from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 12, 2024
1 parent 3d36928 commit 0d94cfb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ jobs:
- name: Download dependencies
run: make deps

- name: Run tests
working-directory: ${{env.SRC_DIR}}
- name: Run tests (panicnil=0)
env:
GODEBUG: panicnil=0
run: make test

- name: Run tests (panicnil=1)
env:
GODEBUG: panicnil=1
run: make test
19 changes: 17 additions & 2 deletions checkers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package check_test

import (
"errors"
"fmt"
"reflect"
"runtime"

Expand Down Expand Up @@ -240,7 +241,7 @@ func (s *CheckersS) TestPanics(c *check.C) {
c.Assert(names[0], check.Equals, "panic")

// Verify a nil panic
testCheck(c, check.Panics, true, "", func() { panic(nil) }, nil)
testCheck(c, check.Panics, true, "", func() { panic(nil) }, propagatedNilPanicValue())
testCheck(c, check.Panics, false, "", func() { panic(nil) }, "NOPE")
}

Expand All @@ -266,7 +267,21 @@ func (s *CheckersS) TestPanicMatches(c *check.C) {
c.Assert(names[0], check.Equals, "panic")

// Verify a nil panic
testCheck(c, check.PanicMatches, false, "Panic value is not a string or an error", func() { panic(nil) }, "")
if v := propagatedNilPanicValue(); v == nil {
// Verify a propagated nil panic
testCheck(c, check.PanicMatches, false, "Panic value is not a string or an error", func() { panic(nil) }, "")
} else {
// Verify a non-nil propagation from a nil panic
testCheck(c, check.PanicMatches, true, "", func() { panic(nil) }, fmt.Sprintf("%s", v))
}
}

// propagatedNilPanicValue returns the value propagated when a nil panic occurs.
// Prior to go1.21, this is always nil.
// In go1.21+, this is *runtime.PanicNilError unless GODEBUG=panicnil=1 is set.
func propagatedNilPanicValue() (v interface{}) {
defer func() { v = recover() }()
panic(nil)
}

func (s *CheckersS) TestFitsTypeOf(c *check.C) {
Expand Down

0 comments on commit 0d94cfb

Please sign in to comment.