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

the testing package may cause a crash #70218

Closed
daocoder2 opened this issue Nov 6, 2024 · 2 comments
Closed

the testing package may cause a crash #70218

daocoder2 opened this issue Nov 6, 2024 · 2 comments

Comments

@daocoder2
Copy link

Go version

go version go1.22.7 linux/amd64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/usr/local/go'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.7'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/assert_rdg/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3465843287=/tmp/go-build -gno-record-gcc-switches'

What did you do?

package main


import (
    "testing"
    "fmt"
    "github.com/stretchr/testify/assert"
)

func main() {
    t := &testing.T{}
    res := assert.EqualValues(t, "1", "0", nil)
    fmt.Println(res)
}

What did you see happen?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4c0460]

goroutine 1 [running]:
testing.(*common).decorate(0x7ff35d8668c8?, {0xc000200540, 0x1b7}, 0x1c0?)
/usr/local/go/src/testing/testing.go:777 +0xa0
testing.(*common).logDepth(0xc0001384e0, {0xc000200540, 0x1b7}, 0x3)
/usr/local/go/src/testing/testing.go:1044 +0x1dd
testing.(*common).log(...)
/usr/local/go/src/testing/testing.go:1013
testing.(*common).Errorf(0xc0001384e0, {0x58d565?, 0x40b845?}, {0xc000014370?, 0x55af60?, 0x101?})
/usr/local/go/src/testing/testing.go:1077 +0x54
github.com/stretchr/testify/assert.Fail({0x5e14e0, 0xc0001384e0}, {0xc0000242a0, 0x59}, {0xc00018ff20, 0x1, 0x1})
/root/go/pkg/mod/github.com/stretchr/[email protected]/assert/assertions.go:363 +0x370
github.com/stretchr/testify/assert.EqualValues({0x5e14e0, 0xc0001384e0}, {0x55a960, 0x5e0868}, {0x55a960, 0x5e0878}, {0xc00018ff20, 0x1, 0x1})
/root/go/pkg/mod/github.com/stretchr/[email protected]/assert/assertions.go:587 +0x1fd
main.main()
/assert_rdg/main.go:12 +0x5f

What did you expect to see?

I'm not sure if it's just my usage problem.
The test package did not use the go test command, so the variable fullPath was not initialized.
Finally, it crashes when the assertion is wrong.

The possible reasons are as follows:

	if file != "" {
		if *fullPath {
			// If relative path, truncate file name at last file name separator.
		} else if index := strings.LastIndexAny(file, `/\`); index >= 0 {
			file = file[index+1:]
		}
	} else {
		file = "???"
	}
@daocoder2 daocoder2 changed the title import/path: issue title the testing package may cause a crash Nov 6, 2024
@seankhliao
Copy link
Member

testing.T is not intended to be used outside of tests.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants