Documentation ¶
Overview ¶
Package bazel_testing provides an integration testing framework for testing rules_go with Bazel.
Tests may be written by declaring a go_bazel_test target instead of a go_test (go_bazel_test is defined in def.bzl here), then calling TestMain. Tests are run in a synthetic test workspace. Tests may run bazel commands with RunBazel.
Index ¶
Constants ¶
const ( // Standard Bazel exit codes. // A subset of codes in https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/util/ExitCode.java. SUCCESS = 0 BUILD_FAILURE = 1 COMMAND_LINE_ERROR = 2 TESTS_FAILED = 3 NO_TESTS_FOUND = 4 RUN_FAILURE = 6 ANALYSIS_FAILURE = 7 INTERRUPTED = 8 LOCK_HELD_NOBLOCK_FOR_LOCK = 9 )
Variables ¶
This section is empty.
Functions ¶
func BazelCmd ¶ added in v0.19.9
BazelCmd prepares a bazel command for execution. It chooses the correct bazel binary based on the environment and sanitizes the environment to hide that this code is executing inside a bazel test.
func BazelOutput ¶ added in v0.19.9
BazelOutput invokes a bazel command with a list of arguments and returns the content of stdout.
If the command starts but exits with a non-zero status, a *StderrExitError will be returned which wraps the original *exec.ExitError.
func RunBazel ¶
RunBazel invokes a bazel command with a list of arguments.
If the command starts but exits with a non-zero status, a *StderrExitError will be returned which wraps the original *exec.ExitError.
func TestMain ¶
TestMain should be called by tests using this framework from a function named "TestMain". For example:
func TestMain(m *testing.M) { os.Exit(bazel_testing.TestMain(m, bazel_testing.Args{...})) }
TestMain constructs a set of workspaces and changes the working directory to the main workspace.
Types ¶
type Args ¶
type Args struct { // Main is a text archive containing files in the main workspace. // The text archive format is parsed by // //go/tools/internal/txtar:go_default_library, which is copied from // cmd/go/internal/txtar. If this archive does not contain a WORKSPACE file, // a default file will be synthesized. Main string // Nogo is the nogo target to pass to go_register_toolchains. By default, // nogo is not used. Nogo string // WorkspaceSuffix is a string that should be appended to the end // of the default generated WORKSPACE file. WorkspaceSuffix string // SetUp is a function that is executed inside the context of the testing // workspace. It is executed once and only once before the beginning of // all tests. If SetUp returns a non-nil error, execution is halted and // tests cases are not executed. SetUp func() error }
Args is a list of arguments to TestMain. It's defined as a struct so that new optional arguments may be added without breaking compatibility.
type StderrExitError ¶
StderrExitError wraps *exec.ExitError and prints the complete stderr output from a command.
func (*StderrExitError) Error ¶
func (e *StderrExitError) Error() string
func (*StderrExitError) Unwrap ¶ added in v0.23.0
func (e *StderrExitError) Unwrap() error