Skip to content
This repository was archived by the owner on Dec 29, 2021. It is now read-only.

Commit 67d2f6d

Browse files
committed
feat(stdin): Support binary data
`.stdin()` can now accept anything convertable to bytes, including `str`, `OsStr`, and `[u8]`.
1 parent abe2606 commit 67d2f6d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/assert.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Assert {
1919
expect_success: Option<bool>,
2020
expect_exit_code: Option<i32>,
2121
expect_output: Vec<OutputPredicate>,
22-
stdin_contents: Option<String>,
22+
stdin_contents: Option<Vec<u8>>,
2323
}
2424

2525
impl default::Default for Assert {
@@ -118,8 +118,8 @@ impl Assert {
118118
/// .stdout().contains("42")
119119
/// .unwrap();
120120
/// ```
121-
pub fn stdin(mut self, contents: &str) -> Self {
122-
self.stdin_contents = Some(String::from(contents));
121+
pub fn stdin<S: Into<Vec<u8>>>(mut self, contents: S) -> Self {
122+
self.stdin_contents = Some(contents.into());
123123
self
124124
}
125125

@@ -351,7 +351,7 @@ impl Assert {
351351
.stdin
352352
.as_mut()
353353
.expect("Couldn't get mut ref to command stdin")
354-
.write_all(contents.as_bytes())?;
354+
.write_all(contents)?;
355355
}
356356
let output = spawned.wait_with_output()?;
357357

0 commit comments

Comments
 (0)