bazel_testing

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: Apache-2.0 Imports: 18 Imported by: 3

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

This section is empty.

Variables

This section is empty.

Functions

func BazelCmd added in v0.19.9

func BazelCmd(args ...string) *exec.Cmd

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

func BazelOutput(args ...string) ([]byte, error)

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

func RunBazel(args ...string) error

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

func TestMain(m *testing.M, args Args)

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

type StderrExitError struct {
	Err *exec.ExitError
}

StderrExitError wraps *exec.ExitError and prints the complete stderr output from a command.

func (*StderrExitError) Error

func (e *StderrExitError) Error() string

Jump to

Keyboard shortcuts

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