shell

package
v0.40.16 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: Apache-2.0 Imports: 12 Imported by: 170

Documentation

Overview

Package shell allows to run commands in a shell.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExitCodeForRunCommandError

func GetExitCodeForRunCommandError(err error) (int, error)

GetExitCodeForRunCommandError tries to read the exit code for the error object returned from running a shell command. This is a bit tricky to do in a way that works across platforms.

func RunCommand

func RunCommand(t testing.TestingT, command Command)

RunCommand runs a shell command and redirects its stdout and stderr to the stdout of the atomic script itself. If there are any errors, fail the test.

func RunCommandAndGetOutput

func RunCommandAndGetOutput(t testing.TestingT, command Command) string

RunCommandAndGetOutput runs a shell command and returns its stdout and stderr as a string. The stdout and stderr of that command will also be logged with Command.Log to make debugging easier. If there are any errors, fail the test.

func RunCommandAndGetOutputE

func RunCommandAndGetOutputE(t testing.TestingT, command Command) (string, error)

RunCommandAndGetOutputE runs a shell command and returns its stdout and stderr as a string. The stdout and stderr of that command will also be logged with Command.Log to make debugging easier. Any returned error will be of type ErrWithCmdOutput, containing the output streams and the underlying error.

func RunCommandAndGetStdOut added in v0.17.2

func RunCommandAndGetStdOut(t testing.TestingT, command Command) string

RunCommandAndGetStdOut runs a shell command and returns solely its stdout (but not stderr) as a string. The stdout and stderr of that command will also be logged with Command.Log to make debugging easier. If there are any errors, fail the test.

func RunCommandAndGetStdOutE added in v0.17.2

func RunCommandAndGetStdOutE(t testing.TestingT, command Command) (string, error)

RunCommandAndGetStdOutE runs a shell command and returns solely its stdout (but not stderr) as a string. The stdout and stderr of that command will also be printed to the stdout and stderr of this Go program to make debugging easier. Any returned error will be of type ErrWithCmdOutput, containing the output streams and the underlying error.

func RunCommandE

func RunCommandE(t testing.TestingT, command Command) error

RunCommandE runs a shell command and redirects its stdout and stderr to the stdout of the atomic script itself. Any returned error will be of type ErrWithCmdOutput, containing the output streams and the underlying error.

Types

type Command

type Command struct {
	Command    string            // The command to run
	Args       []string          // The args to pass to the command
	WorkingDir string            // The working directory
	Env        map[string]string // Additional environment variables to set
	// Use the specified logger for the command's output. Use logger.Discard to not print the output while executing the command.
	Logger *logger.Logger
}

Command is a simpler struct for defining commands than Go's built-in Cmd.

type ErrWithCmdOutput added in v0.28.0

type ErrWithCmdOutput struct {
	Underlying error
	Output     *output
}

func (*ErrWithCmdOutput) Error added in v0.28.0

func (e *ErrWithCmdOutput) Error() string

Jump to

Keyboard shortcuts

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