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

Commit 64c766b

Browse files
committed
Document new output assertions
1 parent 1f042ba commit 64c766b

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/assert.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,12 @@ impl Assert {
283283
}
284284
}
285285

286+
/// Assertions for command output.
286287
#[derive(Debug)]
287288
pub struct OutputAssertionBuilder {
288-
pub assertion: Assert,
289-
pub kind: OutputKind,
290-
pub expected_result: bool,
289+
assertion: Assert,
290+
kind: OutputKind,
291+
expected_result: bool,
291292
}
292293

293294
impl OutputAssertionBuilder {

src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@
6767
//! # fn main() {
6868
//! assert_cmd!(cat "non-existing-file")
6969
//! .fails()
70-
//! .and()
71-
//! .stderr().contains("non-existing-file")
7270
//! .unwrap();
7371
//! # }
7472
//! ```
@@ -78,10 +76,25 @@
7876
//! - Use `fails_with` to assert a specific exit status.
7977
//! - There is also a `succeeds` method, but this is already the implicit default
8078
//! and can usually be omitted.
81-
//! - We can inspect the output of **stderr** with `stderr().contains` and `stderr().is`.
8279
//! - The `and` method has no effect, other than to make everything more readable.
8380
//! Feel free to use it. :-)
8481
//!
82+
//! ## stdout / stderr
83+
//!
84+
//! You can add assertions on the content of **stdout** and **stderr**. They
85+
//! can be mixed together or even multiple of one stream can be used.
86+
//!
87+
//! ```rust
88+
//! # #[macro_use] extern crate assert_cli;
89+
//! # fn main() {
90+
//! assert_cmd!(echo "Hello world! The ansswer is 42.")
91+
//! .stdout().contains("Hello world")
92+
//! .stdout().contains("42")
93+
//! .stderr().is("")
94+
//! .unwrap();
95+
//! # }
96+
//! ```
97+
//!
8598
//! ## Assert CLI Crates
8699
//!
87100
//! If you are testing a Rust binary crate, you can start with
@@ -119,3 +132,4 @@ mod diff;
119132

120133
mod assert;
121134
pub use assert::Assert;
135+
pub use assert::OutputAssertionBuilder;

0 commit comments

Comments
 (0)