Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/test/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ impl Assert {
self
}

pub fn remove_redactions(&mut self, vars: impl IntoIterator<Item = &'static str>) -> &mut Self {
for var in vars {
self.redactions
.remove(var)
.expect("invalid redactions detected");
}
self
}

/// Asserts that the command exited with an ok status.
pub fn is_ok(&self) -> &Self {
assert!(self.output.ok);
Expand Down Expand Up @@ -224,20 +233,32 @@ impl Config {
/// Returns an [`Assert`] object to check the output of running the command
/// specified by `args` under the default environment.
#[must_use]
pub async fn expect(&self, args: impl AsRef<[&str]>) -> Assert {
pub async fn expect<S: AsRef<OsStr> + Clone + Debug>(&self, args: impl AsRef<[S]>) -> Assert {
self.expect_with_env(args, &[]).await
}

/// Returns an [`Assert`] object to check the output of running the command
/// specified by `args` and under the environment specified by `env`.
#[must_use]
pub async fn expect_with_env(
pub async fn expect_with_env<S: AsRef<OsStr> + Clone + Debug>(
&self,
args: impl AsRef<[&str]>,
args: impl AsRef<[S]>,
env: impl AsRef<[(&str, &str)]>,
) -> Assert {
let args = args.as_ref();
let output = self.run(args[0], &args[1..], env.as_ref()).await;
let (program, args) = args
.as_ref()
.split_first()
.expect("args should not be empty");
let output = self
.run(
program
.as_ref()
.to_str()
.expect("invalid UTF-8 in program name"),
args,
env.as_ref(),
)
.await;
Assert::new(output)
}

Expand Down
Loading