]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: print finally FAIL if a test has failed in package list mode
authorLuka Zitnik <luka.zitnik@gmail.com>
Sun, 7 Apr 2019 14:41:11 +0000 (16:41 +0200)
committerBryan C. Mills <bcmills@google.com>
Mon, 13 May 2019 19:26:01 +0000 (19:26 +0000)
Fixes #30507

Change-Id: Ic598e4d5f71c624fcde051982bf85533e2f18e8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/170948
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/alldocs.go
src/cmd/go/internal/base/base.go
src/cmd/go/internal/test/test.go
src/cmd/go/testdata/script/test_status.txt [new file with mode: 0644]

index 0ea0bad9a91676e3c4e1027417427bc7a15a1ac9..b774ac2da75d4cbe852384fbea179a73f66abdf8 100644 (file)
 // line. If a package test fails, go test prints the full test output.
 // If invoked with the -bench or -v flag, go test prints the full
 // output even for passing package tests, in order to display the
-// requested benchmark results or verbose logging.
+// requested benchmark results or verbose logging. After the package
+// tests for all of the listed packages finish, and their output is
+// printed, go test prints a final 'FAIL' status if any package test
+// has failed.
 //
 // In package list mode only, go test caches successful package test
 // results to avoid unnecessary repeated running of tests. When the
index 028f9b6aeff1f1354130fad8a8a3ef6681b9c183..272da55681258dff961bb67a6f1c13dbf36ba1e5 100644 (file)
@@ -132,6 +132,10 @@ func SetExitStatus(n int) {
        exitMu.Unlock()
 }
 
+func GetExitStatus() int {
+       return exitStatus
+}
+
 // Run runs the command, with stdout and stderr
 // connected to the go command's own stdout and stderr.
 // If the command fails, Run reports the error using Errorf.
index 98a8c8756c6a1f0a6aa14b68b37d86e1394f27be..fa6205918ef43d3ceb804510e585f9d5b4bfe48d 100644 (file)
@@ -102,7 +102,10 @@ package test passes, go test prints only the final 'ok' summary
 line. If a package test fails, go test prints the full test output.
 If invoked with the -bench or -v flag, go test prints the full
 output even for passing package tests, in order to display the
-requested benchmark results or verbose logging.
+requested benchmark results or verbose logging. After the package
+tests for all of the listed packages finish, and their output is
+printed, go test prints a final 'FAIL' status if any package test
+has failed.
 
 In package list mode only, go test caches successful package test
 results to avoid unnecessary repeated running of tests. When the
@@ -735,7 +738,7 @@ func runTest(cmd *base.Command, args []string) {
        }
 
        // Ultimately the goal is to print the output.
-       root := &work.Action{Mode: "go test", Deps: prints}
+       root := &work.Action{Mode: "go test", Func: printExitStatus, Deps: prints}
 
        // Force the printing of results to happen in order,
        // one at a time.
@@ -1632,3 +1635,14 @@ func builderNoTest(b *work.Builder, a *work.Action) error {
        fmt.Fprintf(stdout, "?   \t%s\t[no test files]\n", a.Package.ImportPath)
        return nil
 }
+
+// printExitStatus is the action for printing the exit status
+func printExitStatus(b *work.Builder, a *work.Action) error {
+       if !testJSON && len(pkgArgs) != 0 {
+               if base.GetExitStatus() != 0 {
+                       fmt.Println("FAIL")
+                       return nil
+               }
+       }
+       return nil
+}
diff --git a/src/cmd/go/testdata/script/test_status.txt b/src/cmd/go/testdata/script/test_status.txt
new file mode 100644 (file)
index 0000000..aa6ad3c
--- /dev/null
@@ -0,0 +1,18 @@
+env GO111MODULE=off
+
+! go test x y
+stdout ^FAIL\s+x
+stdout ^ok\s+y
+stdout (?-m)FAIL\n$
+
+-- x/x_test.go --
+package x
+
+import "testing"
+
+func TestNothingJustFail(t *testing.T) {
+    t.Fail()
+}
+
+-- y/y_test.go --
+package y