Skip to content

testing: silly typo in subtests causes hard-to-understand error message #21175

Description

@barnex

What did you do?

Run go test on this (wrong) test file. The subtest is wrongfully referring to the outer testing.T:

package main

import "testing"

func TestPanic(t *testing.T) {
        t.Run("", func(typo *testing.T) {
                t.Fatalf("...") // wrong, should be typo.Fatalf, not t.Fatalf
        })
}

What did you expect to see?

Perhaps a somewhat informative error message. At least not a panic(nil) leading to a long debug session.

What did you see instead?

A very confusing panic(nil):

> go test
panic: test executed panic(nil) or runtime.Goexit

goroutine 6 [running]:
testing.tRunner.func1(0xc4200941e0)
        /home/arne/bin/go/src/testing/testing.go:712 +0x2d2
runtime.Goexit()
        /home/arne/bin/go/src/runtime/panic.go:366 +0x147
testing.(*common).FailNow(0xc4200940f0)
        /home/arne/bin/go/src/testing/testing.go:544 +0x39
testing.(*common).Fatalf(0xc4200940f0, 0x53665f, 0xd, 0x0, 0x0, 0x0)
        /home/arne/bin/go/src/testing/testing.go:588 +0x83
_/home/arne/tmp.TestPanic.func1(0xc4200941e0)
        /home/arne/tmp/panic_test.go:7 +0x5c
testing.tRunner(0xc4200941e0, 0xc42000e400)
        /home/arne/bin/go/src/testing/testing.go:747 +0xd0
created by testing.(*T).Run
        /home/arne/bin/go/src/testing/testing.go:790 +0x2de
exit status 2
FAIL    _/home/arne/tmp 0.003s

Does this issue reproduce with the latest release (go1.8.3)?

Yes. Also with go1.9rc1.

System details

go version go1.9rc1 linux/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/arne"
GORACE=""
GOROOT="/home/arne/bin/go"
GOTOOLDIR="/home/arne/bin/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build514931481=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOROOT/bin/go version: go version go1.9rc1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.9rc1
uname -sr: Linux 4.4.0-83-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.2 LTS
Release:	16.04
Codename:	xenial
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.23-0ubuntu9) stable release version 2.23, by Roland McGrath et al.
gdb --version: GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1

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

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions