]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: show FAIL for errors during test setup
authorRuss Cox <rsc@golang.org>
Tue, 10 Sep 2013 18:43:57 +0000 (14:43 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 10 Sep 2013 18:43:57 +0000 (14:43 -0400)
For example, if an x_test.go file contains a syntax error,
b.test fails with an error message. But it wasn't printing
the same FAIL line that a build failure later would print.
This makes all the test failures that happen (once we
decide to start running tests) consistently say FAIL.

Fixes #4701.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13431044

src/cmd/go/test.bash
src/cmd/go/test.go
src/cmd/go/testdata/src/syntaxerror/x.go [new file with mode: 0644]
src/cmd/go/testdata/src/syntaxerror/x_test.go [new file with mode: 0644]

index b55989c2075c8d5223a8d3e6440e412fd9260bc8..52d2f08337900b1cce7c864672faf5475e8a30f8 100755 (executable)
@@ -104,6 +104,19 @@ cp -R testdata/local "testdata/$bad"
 testlocal "$bad" 'with bad characters in path'
 rm -rf "testdata/$bad"
 
+TEST error message for syntax error in test go file says FAIL
+export GOPATH=$(pwd)/testdata
+if ./testgo test syntaxerror 2>testdata/err; then
+       echo 'go test syntaxerror succeeded'
+       ok=false
+elif ! grep FAIL testdata/err >/dev/null; then
+       echo 'go test did not say FAIL:'
+       cat testdata/err
+       ok=false
+fi
+rm -f ./testdata/err
+unset GOPATH
+
 # Test tests with relative imports.
 TEST relative imports '(go test)'
 if ! ./testgo test ./testdata/testimport; then
index ebc9d28548585074f7c376e12c119fa4ae368dde..eab075db7c33f83f01ab8c965bdaebf9953ee377 100644 (file)
@@ -423,10 +423,12 @@ func runTest(cmd *Command, args []string) {
                        if strings.HasPrefix(str, "\n") {
                                str = str[1:]
                        }
+                       failed := fmt.Sprintf("FAIL\t%s [setup failed]\n", p.ImportPath)
+
                        if p.ImportPath != "" {
-                               errorf("# %s\n%s", p.ImportPath, str)
+                               errorf("# %s\n%s\n%s", p.ImportPath, str, failed)
                        } else {
-                               errorf("%s", str)
+                               errorf("%s\n%s", str, failed)
                        }
                        continue
                }
diff --git a/src/cmd/go/testdata/src/syntaxerror/x.go b/src/cmd/go/testdata/src/syntaxerror/x.go
new file mode 100644 (file)
index 0000000..c89cd18
--- /dev/null
@@ -0,0 +1 @@
+package p
diff --git a/src/cmd/go/testdata/src/syntaxerror/x_test.go b/src/cmd/go/testdata/src/syntaxerror/x_test.go
new file mode 100644 (file)
index 0000000..2460743
--- /dev/null
@@ -0,0 +1,4 @@
+package p
+
+func f() (x.y, z int) {
+}