cptest

command
v0.0.0-...-6f34b33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 11 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL