I'm trying to add an example to a package, and run the example via go test
, however the example is never run.
For example, see this gist: https://gist.github.com/85469ecc65bb5bb85857
The gist has example_test.go
:
package cow_test
import (
cow "gist.github.com/85469ecc65bb5bb85857"
)
func Example() {
cow.Poke()
}
Yet when I run this:
# go test -v example_test.go
testing: warning: no tests to run
PASS
ok command-line-arguments 0.002s
However other packages from stdlib work just fine:
# cd /usr/lib/go/src/errors
# go test -v example_test.go
=== RUN: Example
--- PASS: Example (0.00s)
PASS
ok command-line-arguments 0.002s
What is wrong with my example?
From the documentation:
Example functions without output comments are compiled but not executed.
Add an output comment:
func Example() {
junk.Poke()
// Output: MOOOO!
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With