From 64c766b18b7551f9c96ccb8c7f0464630a2da105 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 21 Sep 2017 21:02:31 -0600 Subject: [PATCH] Document new output assertions --- src/assert.rs | 7 ++++--- src/lib.rs | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/assert.rs b/src/assert.rs index ca03e26..0732c35 100644 --- a/src/assert.rs +++ b/src/assert.rs @@ -283,11 +283,12 @@ impl Assert { } } +/// Assertions for command output. #[derive(Debug)] pub struct OutputAssertionBuilder { - pub assertion: Assert, - pub kind: OutputKind, - pub expected_result: bool, + assertion: Assert, + kind: OutputKind, + expected_result: bool, } impl OutputAssertionBuilder { diff --git a/src/lib.rs b/src/lib.rs index f36cbc7..5d103da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,8 +67,6 @@ //! # fn main() { //! assert_cmd!(cat "non-existing-file") //! .fails() -//! .and() -//! .stderr().contains("non-existing-file") //! .unwrap(); //! # } //! ``` @@ -78,10 +76,25 @@ //! - Use `fails_with` to assert a specific exit status. //! - There is also a `succeeds` method, but this is already the implicit default //! and can usually be omitted. -//! - We can inspect the output of **stderr** with `stderr().contains` and `stderr().is`. //! - The `and` method has no effect, other than to make everything more readable. //! Feel free to use it. :-) //! +//! ## stdout / stderr +//! +//! You can add assertions on the content of **stdout** and **stderr**. They +//! can be mixed together or even multiple of one stream can be used. +//! +//! ```rust +//! # #[macro_use] extern crate assert_cli; +//! # fn main() { +//! assert_cmd!(echo "Hello world! The ansswer is 42.") +//! .stdout().contains("Hello world") +//! .stdout().contains("42") +//! .stderr().is("") +//! .unwrap(); +//! # } +//! ``` +//! //! ## Assert CLI Crates //! //! If you are testing a Rust binary crate, you can start with @@ -119,3 +132,4 @@ mod diff; mod assert; pub use assert::Assert; +pub use assert::OutputAssertionBuilder;