mirror of
https://github.com/golang/go
synced 2024-11-25 12:07:56 -07:00
gotest: don't run examples that have no expected output
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5364041
This commit is contained in:
parent
46ee09eff1
commit
2fcb045242
@ -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
|
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.
|
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.
|
See the documentation of the testing package for more information.
|
||||||
|
|
||||||
|
@ -231,9 +231,14 @@ func getTestNames() {
|
|||||||
} else if isTest(name, "Benchmark") {
|
} else if isTest(name, "Benchmark") {
|
||||||
f.benchmarks = append(f.benchmarks, name)
|
f.benchmarks = append(f.benchmarks, name)
|
||||||
} else if isTest(name, "Example") {
|
} 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{
|
f.examples = append(f.examples, example{
|
||||||
name: name,
|
name: name,
|
||||||
output: doc.CommentText(n.Doc),
|
output: output,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// TODO: worth checking the signature? Probably not.
|
// TODO: worth checking the signature? Probably not.
|
||||||
@ -372,7 +377,7 @@ func writeTestmainGo() {
|
|||||||
insideTests := false
|
insideTests := false
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
//println(f.name, f.pkg)
|
//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
|
continue
|
||||||
}
|
}
|
||||||
if isOutsideTest(f.pkg) {
|
if isOutsideTest(f.pkg) {
|
||||||
|
Loading…
Reference in New Issue
Block a user