pub struct ShellOptions<Cmd = Command> { /* private fields */ }
Expand description

Options for executing commands in the shell. Used in Transcript::from_inputs() and in TestConfig.

The type param maps to extensions available for the shell. For example, StdShell extension allows to specify custom aliases for the executed commands.

Implementations§

Creates options for an sh shell.

Creates options for a Bash shell.

Creates options for PowerShell 6+ (the one with the pwsh executable).

Creates an alias for the binary at path_to_bin, which should be an absolute path. This allows to call the binary using this alias without complex preparations (such as installing it globally via cargo install), and is more flexible than Self::with_cargo_path().

In integration tests, you may use env!("CARGO_BIN_EXE_<name>") to get a path to binary targets.

Limitations
  • For Bash and PowerShell, name must be a valid name of a function. For sh, name must be a valid name for the alias command. The name validity is not checked.

Creates new options with the provided command.

Sets the echoing flag for the shell.

Changes the current directory of the command.

Sets the I/O timeout for shell commands. This determines how long methods like Transcript::from_inputs() wait for output of a command before proceeding to the next command. Longer values allow to capture output more accurately, but result in longer execution.

By default, the I/O timeout is 0.5 seconds.

Sets an additional initialization timeout (relative to the one set by Self::with_io_timeout()) before reading the output of the each command input into the shell.

By default, the initialization timeout is 1.5 seconds.

Adds an initialization command. Such commands are sent to the shell before executing any user input. The corresponding output from the shell is not captured.

Sets the value of an environment variable with the specified name.

Sets the line decoder for the shell. This allows for custom shell text encodings.

The default decoder used is the UTF-8 one. It halts processing with an error if the input is not UTF-8; you may use Self::with_lossy_utf8_decoder() to swallow errors in this case.

Sets the lossy UTF-8 decoder which always succeeds at decoding at the cost of replacing non-UTF-8 chars.

Sets the ExitStatus checker for the shell. See ExitStatus docs for the semantics of exit statuses.

Arguments
  • command is a command that will be executed to check the exit status of the latest executed command. E.g., in sh-like shells one can use echo $?.
  • checker is a closure that transforms the output of command into an ExitStatus. The output is provided as a Captured string; it usually makes sense to use Captured::to_plaintext() to strip it of possible escape sequences (especially important if captured from PTY). If the exit status is inconclusive or not applicable, the closure should return None.

The command will be executed after each UserInput is input into the shell and the corresponding output is captured. After this, the Captured output will be supplied to the checker closure and its output will be recorded as Interaction::exit_status().

Panics

Panics if command contains newline chars ('\n' or '\r').

Adds paths to cargo binaries (including examples) to the PATH env variable for the shell described by these options. This allows to call them by the corresponding filename, without specifying a path or doing complex preparations (e.g., calling cargo install).

Limitations
  • The caller must be a unit or integration test; the method will work improperly otherwise.

Adds a specified path to the PATH env variable for the shell described by these options. This method can be called multiple times to add multiple paths and is composable with Self::with_cargo_path().

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more