]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: always build package during "go test" command
authorAlex Brainman <alex.brainman@gmail.com>
Thu, 10 Apr 2014 04:02:24 +0000 (14:02 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 10 Apr 2014 04:02:24 +0000 (14:02 +1000)
even when there are no *_test.go files present.
rsc suggested this change

Fixes #7108

LGTM=r, adg
R=golang-codereviews, r, adg
CC=golang-codereviews
https://golang.org/cl/84300043

src/cmd/go/test.bash
src/cmd/go/test.go
src/cmd/go/testdata/src/notest/hello.go [new file with mode: 0644]

index 45215de4ded9ce2f197087c5c603b63a568f874e..4bde166110421b558a3ac815917410dafb18d8a3 100755 (executable)
@@ -700,6 +700,14 @@ if ! ./testgo list -f "GOARCH: {{context.GOARCH}}"; then
        ok=false
 fi
 
+TEST 'Issue 7108: cmd/go: "go test" should fail if package does not build'
+export GOPATH=$(pwd)/testdata
+if ./testgo test notest >/dev/null 2>&1; then
+       echo 'go test notest succeeded, but should fail'
+       ok=false
+fi
+unset GOPATH
+
 # clean up
 if $started; then stop; fi
 rm -rf testdata/bin testdata/bin1
index 20a9e74af14fce5657de99de1538694388daf158..a5497e71a3d724138bdc2bd9b782816b86674ef9 100644 (file)
@@ -524,7 +524,7 @@ func contains(x []string, s string) bool {
 
 func (b *builder) test(p *Package) (buildAction, runAction, printAction *action, err error) {
        if len(p.TestGoFiles)+len(p.XTestGoFiles) == 0 {
-               build := &action{p: p}
+               build := b.action(modeBuild, modeBuild, p)
                run := &action{p: p, deps: []*action{build}}
                print := &action{f: (*builder).notest, p: p, deps: []*action{run}}
                return build, run, print, nil
diff --git a/src/cmd/go/testdata/src/notest/hello.go b/src/cmd/go/testdata/src/notest/hello.go
new file mode 100644 (file)
index 0000000..7c42c32
--- /dev/null
@@ -0,0 +1,6 @@
+package notest
+
+func hello() {
+       println("hello world")
+}
+Hello world