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

cmd/go: go test does not parse -overlay files for test functions #44946

Closed
eandre opened this issue Mar 11, 2021 · 6 comments
Closed

cmd/go: go test does not parse -overlay files for test functions #44946

eandre opened this issue Mar 11, 2021 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@eandre
Copy link

eandre commented Mar 11, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16 darwin/arm64

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
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/eandre/Library/Caches/go-build"
GOENV="/Users/eandre/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/eandre/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/eandre"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.16/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.16/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hc/w9bwjfwd69dd6_6thw6xqmkw0000gn/T/go-build1638807139=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Consider this txtar:

-- go.mod --
module test.pkg
-- foo/foo_test.go --
package foo

import "testing"

func TestFoo(t *testing.T) { }
-- tmp/bar_test.go --
package foo

import "testing"

func TestBar(t *testing.T) {
	t.Fatal("dummy failure")
}
-- foo/overlay.json --
{"Replace": {"bar_test.go": "../tmp/bar_test.go"}}

Running go test -overlay=overlay.json in the foo folder should result in TestBar running.

What did you expect to see?

cd foo
go test -overlay=overlay.json .
--- FAIL: TestBar (0.00s)
    bar_test.go:5: dummy failure
FAIL
FAIL	test.app	0.138s
FAIL

What did you see instead?

# test.pkg
open /Users/eandre/tmp/foo/bar_test.go: no such file or directory
FAIL	test.app [setup failed]
FAIL

The issue is because https://github.com/golang/go/blob/master/src/cmd/go/internal/load/test.go#L579 implicitly reads from the filesystem instead of using the overlay file data (due to src == nil).

@eandre
Copy link
Author

eandre commented Mar 11, 2021

Making this change fixes the issue for me: https://gist.github.com/eandre/45f5a554faff3b23f6f5d92f794a222b

@jayconrod jayconrod added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 11, 2021
@jayconrod jayconrod added this to the Go1.17 milestone Mar 11, 2021
@jayconrod
Copy link
Contributor

cc @matloob

@matloob
Copy link
Contributor

matloob commented Mar 12, 2021

@eandre Your change looks reasonable. Do you want to contribute it? If not I can make a change myself.

@eandre
Copy link
Author

eandre commented Mar 12, 2021

@matloob great! Either way, up to you. I can get around to doing it sometime next week.

@matloob
Copy link
Contributor

matloob commented Mar 12, 2021

Go for it! I look forward to your CL!

@gopherbot
Copy link

Change https://golang.org/cl/305071 mentions this issue: cmd/go/internal/load/test: parse overlay files for test functions

@golang golang locked and limited conversation to collaborators Mar 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants