Struct Runcmd

Source
pub struct Runcmd { /* private fields */ }
Expand description

The Runcmd context gives a step function access to the ability to run subprocesses as part of a scenario. These subprocesses are run with various environment variables set, and we record the stdout/stderr of the most recent-to-run command for testing purposes.

Implementations§

Source§

impl Runcmd

Source

pub fn prepend_to_path<S: Into<OsString>>(&mut self, element: S)

Prepend the given location to the run path

Source

pub fn stdout_as_string(&self) -> String

Retrieve the last run command’s stdout as a string.

This does a lossy conversion from utf8 so should always succeed.

Source

pub fn stderr_as_string(&self) -> String

Retrieve the last run command’s stderr as a string.

This does a lossy conversion from utf8 so should always succeed.

Source

pub fn setenv<K: Into<OsString>, V: Into<OsString>>(&mut self, key: K, value: V)

Set an env var in the Runcmd context

This sets an environment variable into the Runcmd context for use during execution

Source

pub fn getenv<K: AsRef<OsStr>>(&self, key: K) -> Option<&OsStr>

Get an env var from the Runcmd context

This retrieves a set environment variable from the Runcmd context

Source

pub fn unsetenv<K: AsRef<OsStr>>(&mut self, key: K) -> bool

Unset an env var in the Runcmd context

This removes an environment variable (if set) from the Runcmd context and returns whether or not it was removed.

Source

pub fn join_paths(&self) -> Result<OsString, JoinPathsError>

Join the PATH environment variable and the paths attribute together properly.

This prepends the paths (in reverse order) to the PATH environment variable and then returns it.

If there is no PATH in the stored environment then the resultant path will be entirely made up of the pushed path elements


let mut rc = Runcmd::default();

assert_eq!(rc.join_paths().unwrap(), "");

rc.setenv("PATH", "one");
assert_eq!(rc.join_paths().unwrap(), "one");

rc.prepend_to_path("two");
assert_eq!(rc.join_paths().unwrap(), "two:one");

rc.unsetenv("PATH");
assert_eq!(rc.join_paths().unwrap(), "two");

rc.prepend_to_path("three");
assert_eq!(rc.join_paths().unwrap(), "three:two");

rc.setenv("PATH", "one");
assert_eq!(rc.join_paths().unwrap(), "three:two:one");
Source

pub fn with_forklock<F, R>(&mut self, func: F) -> Result<R, StepError>
where F: FnOnce() -> Result<R, StepError>,

Perform an operation with the fork-lock held.

In order to prevent races where one scenario creates a file which is related to executables, and another forks, defeating the sequencing of creation and cleanup, the runcmd core will hold the fork lock while creating subprocesses.

The implied contract therefore is that any step involved in the creation of an executable in-process must hold the fork-lock for the duration of the any code involved in the creation of it which has file descriptors open. For example, the writing out of a script file

Trait Implementations§

Source§

impl ContextElement for Runcmd

Source§

fn scenario_starts(&mut self) -> StepResult

Scenario starts Read more
Source§

fn created(&mut self, scenario: &Scenario)

A new context element was created. Read more
Source§

fn scenario_stops(&mut self) -> StepResult

Scenario stops Read more
Source§

fn step_starts(&mut self, step_title: &str) -> StepResult

Entry to a step function Read more
Source§

fn step_stops(&mut self) -> StepResult

Exit from a step function Read more
Source§

impl Debug for Runcmd

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Runcmd

Source§

fn default() -> Runcmd

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Runcmd

§

impl RefUnwindSafe for Runcmd

§

impl Send for Runcmd

§

impl Sync for Runcmd

§

impl Unpin for Runcmd

§

impl UnwindSafe for Runcmd

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.