Skip to content

NotPanics failures should include the panicking stack #636

@dcormier

Description

@dcormier

If a NotPanics assertion fails, the test output should include the stack from the panic. This would speed up debugging. For example,

func makeNew(c *http.Client) (*http.Response, error) {
	req, err := http.NewRequest(http.MethodPost, "https://example.com/api/v1/things/new", nil)
	if err != nil {
		return nil, err
	}

	return c.Do(req)
}

func TestPanic(t *testing.T) {
	var c *http.Client

	doReq := func() {
		resp, err := makeNew(c)
		require.NoError(t, err)

		resp.Body.Close()
	}

	require.NotPanics(t, doReq)
}

That gives you output like this:

--- FAIL: TestNotPanics (0.00s)
	require.go:945:
			Error Trace:	notpanics_test.go:29
			Error:      	func (assert.PanicTestFunc)(0x171bf90) should not panic
			            		Panic value:	runtime error: invalid memory address or nil pointer dereference
			Test:       	TestNotPanics

Including the stack of the panicked goroutine would help in quickly spotting what the mistake was.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions