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

Closed
myitcv opened this issue Mar 29, 2019 · 3 comments
Closed

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

myitcv opened this issue Mar 29, 2019 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@myitcv
Copy link
Member

myitcv 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
Copy link
Contributor

josharian commented Mar 29, 2019

@cespare

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 12, 2019
@bcmills bcmills added this to the Unplanned milestone Apr 12, 2019
@gopherbot
Copy link

gopherbot commented Aug 28, 2021

Change https://golang.org/cl/345909 mentions this issue: testing: skip panics when picking the line number for decoration

@cespare
Copy link
Contributor

cespare commented Aug 28, 2021

Sure, this is easy to change. I sent a PR. It's surprising to me that nobody else has seemingly noticed or complained.

@golang golang locked and limited conversation to collaborators Sep 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants