1
0
mirror of https://github.com/golang/go synced 2024-11-23 12:10:11 -07:00

cmd/go: fix go test using package main_test

A package main binary (that is, a command) being installed
does not mean we can skip the build of the package archive
during a test.

Fixes #3417.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13462046
This commit is contained in:
Russ Cox 2013-09-10 14:43:35 -04:00
parent 90f9192886
commit 627d17cf29
4 changed files with 36 additions and 1 deletions

View File

@ -138,6 +138,27 @@ elif ! test -x testdata/bin/go-cmd-test; then
ok=false
fi
TEST package main_test imports archive not binary
export GOBIN=$(pwd)/testdata/bin
mkdir -p $GOBIN
export GOPATH=$(pwd)/testdata
touch ./testdata/src/main_test/m.go
if ! ./testgo test main_test; then
echo "go test main_test failed without install"
ok=false
elif ! ./testgo install main_test; then
echo "go test main_test failed"
ok=false
elif [ "$(./testgo list -f '{{.Stale}}' main_test)" != false ]; then
echo "after go install, main listed as stale"
ok=false
elif ! ./testgo test main_test; then
echo "go test main_test failed after install"
ok=false
fi
rm -rf $GOBIN
unset GOBIN
# And with $GOBIN set, binaries get installed to $GOBIN.
TEST install into GOBIN
if ! GOBIN=$(pwd)/testdata/bin1 GOPATH=$(pwd)/testdata ./testgo install go-cmd-test; then

View File

@ -590,7 +590,7 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
localCover := testCover && testCoverPaths == nil
// Test package.
if len(p.TestGoFiles) > 0 || localCover {
if len(p.TestGoFiles) > 0 || localCover || p.Name == "main" {
ptest = new(Package)
*ptest = *p
ptest.GoFiles = nil

View File

@ -0,0 +1,4 @@
package main
func F() {}
func main() {}

View File

@ -0,0 +1,10 @@
package main_test
import (
. "main_test"
"testing"
)
func Test1(t *testing.T) {
F()
}