Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go example won't run

Tags:

testing

go

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?

like image 208
phemmer Avatar asked Mar 28 '15 04:03

phemmer


1 Answers

From the documentation:

Example functions without output comments are compiled but not executed.

Add an output comment:

func Example() {
    junk.Poke()
    // Output: MOOOO!
}
like image 182
Bayta Darell Avatar answered Sep 17 '22 14:09

Bayta Darell