Skip to content

Commit 9ccd928

Browse files
committed
test(clitools): allow OsStr-like args in Config::expect*()
1 parent 5d31b52 commit 9ccd928

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/test/clitools.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,20 +224,32 @@ impl Config {
224224
/// Returns an [`Assert`] object to check the output of running the command
225225
/// specified by `args` under the default environment.
226226
#[must_use]
227-
pub async fn expect(&self, args: impl AsRef<[&str]>) -> Assert {
227+
pub async fn expect<S: AsRef<OsStr> + Clone + Debug>(&self, args: impl AsRef<[S]>) -> Assert {
228228
self.expect_with_env(args, &[]).await
229229
}
230230

231231
/// Returns an [`Assert`] object to check the output of running the command
232232
/// specified by `args` and under the environment specified by `env`.
233233
#[must_use]
234-
pub async fn expect_with_env(
234+
pub async fn expect_with_env<S: AsRef<OsStr> + Clone + Debug>(
235235
&self,
236-
args: impl AsRef<[&str]>,
236+
args: impl AsRef<[S]>,
237237
env: impl AsRef<[(&str, &str)]>,
238238
) -> Assert {
239-
let args = args.as_ref();
240-
let output = self.run(args[0], &args[1..], env.as_ref()).await;
239+
let (program, args) = args
240+
.as_ref()
241+
.split_first()
242+
.expect("args should not be empty");
243+
let output = self
244+
.run(
245+
program
246+
.as_ref()
247+
.to_str()
248+
.expect("invalid UTF-8 in program name"),
249+
args,
250+
env.as_ref(),
251+
)
252+
.await;
241253
Assert::new(output)
242254
}
243255

0 commit comments

Comments
 (0)