Documentation ¶
Overview ¶
Cptest copies test functions from a package into a new file. The test functions should be normal, public functions in non-test source files. Usage:
cptest --output from_tests.go --package to_test pkg/from/tests
This is intended to support shared tests for an interface, such as github.com/diffeo/go-coordinate/coordinate/coordinatetest. "go test" requires test functions to be declared in the package itself -- even dot imports don't count -- and so if you do have a directory of reusable tests you need a tool like this to copy them.
The generated file just calls the original test functions:
package to_test import "testing" import "pkg/from/tests" func TestFromThing(t *testing.T) { tests.TestFromThing(t) }
You probably need, in a separate file, an init or TestMain function that sets up a global variable to tell the tests what object is being tested, or how to construct that object.