]> Cypherpunks repositories - gostls13.git/commitdiff
gotest: don't run examples that have no expected output
authorAndrew Gerrand <adg@golang.org>
Mon, 7 Nov 2011 23:11:07 +0000 (10:11 +1100)
committerAndrew Gerrand <adg@golang.org>
Mon, 7 Nov 2011 23:11:07 +0000 (10:11 +1100)
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5364041

src/cmd/gotest/doc.go
src/cmd/gotest/gotest.go

index aedc55f11e3d4820cfd26fca1b9f0713ddde3a6a..c0a972af8c9015314d72bb58ce404d04cbe0ede3 100644 (file)
@@ -37,6 +37,7 @@ os.Stdout and os.Stderr is compared against their doc comment.
 
 Multiple example functions may be provided for a given name XXX if they are
 discriminated by a distinct suffix starting with "_", such as ExampleXXX_2.
+Example functions without doc comments are compiled but not executed.
 
 See the documentation of the testing package for more information.
 
index 9a4d2e916d101ab0b32622bdbfd154210b3f9fff..e8e2ec892f18ff20334c598a829fb10fa32718ec 100644 (file)
@@ -231,9 +231,14 @@ func getTestNames() {
                        } else if isTest(name, "Benchmark") {
                                f.benchmarks = append(f.benchmarks, name)
                        } else if isTest(name, "Example") {
+                               output := doc.CommentText(n.Doc)
+                               if output == "" {
+                                       // Don't run examples with no output.
+                                       continue
+                               }
                                f.examples = append(f.examples, example{
                                        name:   name,
-                                       output: doc.CommentText(n.Doc),
+                                       output: output,
                                })
                        }
                        // TODO: worth checking the signature? Probably not.
@@ -372,7 +377,7 @@ func writeTestmainGo() {
        insideTests := false
        for _, f := range files {
                //println(f.name, f.pkg)
-               if len(f.tests) == 0 && len(f.benchmarks) == 0 {
+               if len(f.tests) == 0 && len(f.benchmarks) == 0 && len(f.examples) == 0 {
                        continue
                }
                if isOutsideTest(f.pkg) {