gotesting only example functions

87 views
Skip to first unread message

Archos

unread,
Jan 3, 2012, 6:53:11 AM1/3/12
to golang-nuts
I've a test file only with example functions (they're to test the
ouput) but gotest can not run it.

testing: warning: no tests to run


Is there any way for that gotest can run those example functions?

Jan Mercl

unread,
Jan 3, 2012, 7:02:40 AM1/3/12
to golan...@googlegroups.com
It's clearly stated in the error message IMO. Add:

func Test(t *testing.T) {} // or TestWhatsoever so gotest will find at least one valid test function signature.

dupoxy

unread,
Jan 3, 2012, 7:26:58 AM1/3/12
to golan...@googlegroups.com
//file name : example_test.go
package XXX_test


// The output of this example function. func ExampleXXX() { fmt.Println("The output of this example function.") }

$ go test
ok XXX
PASS

edit :
// The output of this example functionXXX. then
$ go test
FAIL XXX
--- FAIL: ExampleXXX (0.00 seconds)
got:
The output of this example functionXXX
want:
The output of this example function.
FAIL

dupoxy

unread,
Jan 3, 2012, 7:38:42 AM1/3/12
to golan...@googlegroups.com
please see /pkg/sort/example_test.go for a working example

chris dollin

unread,
Jan 3, 2012, 7:43:10 AM1/3/12
to golan...@googlegroups.com
Gosh, I'd missed that gotest handled examples as well as tests & benchmarks.
Thanks to dupoxy for bringing it to my attention!

Chris

--
Chris "allusive" Dollin

Archos

unread,
Jan 3, 2012, 8:17:08 AM1/3/12
to golang-nuts
"gotest" can not handle it because I did it using gotest, else the new
tool "go" with the command "test". Thanks dupoxy

dupoxy

unread,
Jan 3, 2012, 8:37:11 AM1/3/12
to golan...@googlegroups.com
@Archos I Tried on go tip :
go/src/pkg/sort$ gotest
rm -f _test/sort.a
rm -f _test/sort.a
gopack grc _test/sort.a _gotest_.6
--- FAIL: ExampleInts (0.00 seconds)
got:
[1 2 3 4 5 6]
want:
[1 2 3 4 5 7]
FAIL
gotest: "./6.out" failed: exit status 1
so gotest should work for you to

Archos

unread,
Jan 3, 2012, 8:53:42 AM1/3/12
to golang-nuts
It also works in weekly. But I'm confused because in that directory it
doesn't this warning

testing: warning: no tests to run

In change it is showed when I run it in my project. I copy that same
function to my project and comment all another code.

dupoxy

unread,
Jan 3, 2012, 9:50:19 AM1/3/12
to golan...@googlegroups.com
I tested out of GOROOT :
copyed sort.go and example_test.go to /home/olivier/Goenv/test/src/sorttest
edited sort.go : line 7 package sort to package sorttest
edited example_test.go : line 5 package sort_test to package sorttest_test
edited example_test.go : line 9 package "sort" to     sort "sorttest"
$ export GOPATH=/home/olivier/Goenv/test
$ cd /home/olivier/Goenv/test/src/sorttest
$ go test
ok      sorttest

testing: warning: no tests to run
PASS
so edited example_test.go to FAIL
and
$ go test
FAIL    sorttest

testing: warning: no tests to run
--- FAIL: ExampleInts (0.00 seconds)
got:
[1 2 3 4 5 6]
want:
[1 2 3 4 5 7]
FAIL

warning: no tests to run  tells you you should write tests and is right examples are examples not tests ;)



Archos

unread,
Jan 3, 2012, 10:10:00 AM1/3/12
to golang-nuts
Yes. And it is not showed there because there are another test files
which they have tests

$ cd $GOROOT/src/pkg/sort
$ gotest -v
Reply all
Reply to author
Forward
0 new messages