Struct subplotlib::steplibrary::runcmd::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
sourceimpl Runcmd
impl Runcmd
sourcepub fn prepend_to_path<S: Into<OsString>>(&mut self, element: S)
pub fn prepend_to_path<S: Into<OsString>>(&mut self, element: S)
Prepend the given location to the run path
sourcepub fn stdout_as_string(&self) -> String
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.
sourcepub fn stderr_as_string(&self) -> String
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.
sourcepub fn setenv<K: Into<OsString>, V: Into<OsString>>(&mut self, key: K, value: V)
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
sourcepub fn getenv<K: AsRef<OsStr>>(&self, key: K) -> Option<&OsStr>
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
sourcepub fn unsetenv<K: AsRef<OsStr>>(&mut self, key: K) -> bool
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.
sourcepub fn join_paths(&self) -> Result<OsString, JoinPathsError>
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");
Trait Implementations
sourceimpl ContextElement for Runcmd
impl ContextElement for Runcmd
sourcefn scenario_starts(&mut self) -> StepResult
fn scenario_starts(&mut self) -> StepResult
Scenario starts Read more
sourcefn scenario_stops(&mut self) -> StepResult
fn scenario_stops(&mut self) -> StepResult
Scenario stops Read more
sourcefn step_starts(&mut self, step_title: &str) -> StepResult
fn step_starts(&mut self, step_title: &str) -> StepResult
Entry to a step function Read more
sourcefn step_stops(&mut self) -> StepResult
fn step_stops(&mut self) -> StepResult
Exit from a step function Read more
Auto Trait Implementations
impl RefUnwindSafe for Runcmd
impl Send for Runcmd
impl Sync for Runcmd
impl Unpin for Runcmd
impl UnwindSafe for Runcmd
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more