Skip to content

x/playground: Unit tests not working with multiple files #68327

@x1unix

Description

@x1unix

Go version

go version go1.22.4 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/x1unix/Library/Caches/go-build'
GOENV='/Users/x1unix/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/x1unix/go/pkg/mod'
GONOSUMDB='off'
GOOS='darwin'
GOPATH='/Users/x1unix/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.4/libexec'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.4/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/x1unix/prj/go-playground/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/7q/wj_9b_vd5699c2ldbt4_z5wm0000gn/T/go-build1040282864=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I opened the Go Playground and tried to write a simple unit test that imports a sub-package.
Go playground claims to support unit tests execution and provides unit test snippet example.

image

Snippet: https://go.dev/play/p/eSN-TbF14vE

What did you see happen?

Playground can't play unit tests when:

If snippet contains file name directive, Playground returns error:

play.ground: no non-test Go files in /tmp/sandbox1158510457

Go build failed.

What did you expect to see?

Expected to have a working unit test runner.

Probably issue is caused by a buggy unit test file detector.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions