Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
myitcv opened this Issue Mar 29, 2019 · 1 comment

Comments

Projects
None yet
3 participants
@myitcv
Copy link
Member

commented Mar 29, 2019

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

@josharian

This comment has been minimized.

Copy link
Contributor

commented Mar 29, 2019

@cespare

@bcmills bcmills added this to the Unplanned milestone Apr 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.