Skip to content

testing: Helper does not appear to work in presence of panic #31154

Description

@myitcv

What version of Go are you using (go version)?

$ go version
go version go1.12.1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="$WORK/gopath"
GOPROXY=""
GORACE=""
GOROOT="/home/myitcv/gos"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/tmp/go-build690459405=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Came to light in https://go-review.googlesource.com/c/go/+/168886

Ran testscript on the following:

! go test
stdout 'main_test.go:6: expected panic'
stdout 'main_test.go:7: expected S, got string'

-- main_test.go --
package main

import "testing"

func Test(t *testing.T) {
        blah(t, func() {})
        blah2(t, func() { panic("oh dear") })
}

func blah(t *testing.T, f func()) {
        t.Helper()

        defer func() {
                t.Helper()

                err := recover()
                if err == nil {
                        t.Errorf("expected panic")
                }
        }()
        f()
}

func blah2(t *testing.T, f func()) {
        t.Helper()

        defer func() {
                t.Helper()
                err := recover()
                if _, ok := err.(S); !ok {
                        t.Errorf("expected S, got %T", err)
                }
        }()
        f()
}

type S struct{}

What did you expect to see?

A passing test

What did you see instead?

> ! go test
[stdout]
--- FAIL: Test (0.00s)
    main_test.go:6: expected panic
    panic.go:522: expected S, got string
FAIL
exit status 1
FAIL    _$WORK  0.002s

[exit status 1]
> stdout 'main_test.go:6: expected panic'
> stdout 'main_test.go:7: expected S, got string'
FAIL: /tmp/testscript728881261/0/script.txt:5: no match for `main_test.go:7: expected S, got string` found in stdout
error running t_helper_panic.txt in /tmp/testscript728881261/0

FYI @neelance

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions