how does "go test" work?

614 views
Skip to first unread message

Dougx

unread,
May 17, 2013, 9:10:03 PM5/17/13
to golan...@googlegroups.com
Anyone point me in the right direction for finding out how I might implement something similar to "go test".

I'm particularly intrigued by how you have blah_test.go, blah2_test.go and they share a scope, can access blah.go (the package itself) but don't get build as part of go build.

(purpose: adding some kind of blah_gen.go which is processed by a macro engine and converted to a blah.go as a pre-build step)

~
Doug.

David Symonds

unread,
May 17, 2013, 9:12:35 PM5/17/13
to Dougx, golan...@googlegroups.com
On Fri, May 17, 2013 at 6:10 PM, Dougx <douglas...@gmail.com> wrote:

> I'm particularly intrigued by how you have blah_test.go, blah2_test.go and
> they share a scope, can access blah.go (the package itself) but don't get
> build as part of go build.

The go tool knows that files named "blah_test.go" are test files, and
will ignore them for builds but not for tests.

Dave Cheney

unread,
May 17, 2013, 9:33:49 PM5/17/13
to David Symonds, Dougx, golang-nuts
The magic is in cmd/go/test.go, you'll see it sniffs all public
methods that match ^(Test|Benchmark) and constructs a new main package
that passes them to the test runner inside the test package. Look for
the template about 2/3rds of the way down the file.
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Dougx

unread,
May 17, 2013, 9:36:32 PM5/17/13
to golan...@googlegroups.com, David Symonds, Dougx
thats exactly what I was looking for, thanks. :)
Reply all
Reply to author
Forward
0 new messages