1818//!
1919//! ```rust
2020//! assert_cli::Assert::command(&["echo", "42"])
21- //! .succeeds()
22- //! .and().prints("42")
21+ //! .prints("42")
2322//! .unwrap();
2423//! ```
2524//!
3837//! +42
3938//! ```
4039//!
41- //! ## Assert CLI Crates
40+ //! ## `assert_cmd!` Macro
4241//!
43- //! If you are testing a Rust binary crate, you can start with
44- //! `Assert::main_binary()` to use `cargo run` as command. Or, if you want to
45- //! run a specific binary (if you have more than one), use
46- //! `Assert::cargo_binary`.
42+ //! Alternatively, you can use the `assert_cmd!` macro to construct the command more conveniently,
43+ //! but please carefully read the limitations below, or this may seriously go wrong.
4744//!
48- //! ## `assert_cmd!` Macro
45+ //! ```rust
46+ //! # #[macro_use] extern crate assert_cli;
47+ //! # fn main() {
48+ //! assert_cmd!(echo "42").prints("42").unwrap();
49+ //! # }
50+ //! ```
51+ //!
52+ //! **Tips**
53+ //!
54+ //! - Don't forget to import the crate with `#[macro_use]`. ;-)
55+ //! - Enclose arguments in the `assert_cmd!` macro in quotes `"`,
56+ //! if there are special characters, which the macro doesn't accept, e.g.
57+ //! `assert_cmd!(cat "foo.txt")`.
58+ //!
59+ //! ## Exit Status
4960//!
50- //! Alternatively, you can use the `assert_cmd!` macro to construct the command more conveniently:
61+ //! All assertion default to checking that the command exited with success.
62+ //!
63+ //! However, when you expect a command to fail, you can express it like this:
5164//!
5265//! ```rust
5366//! # #[macro_use] extern crate assert_cli;
5467//! # fn main() {
55- //! assert_cmd!(echo 42).succeeds().prints("42").unwrap();
68+ //! assert_cmd!(cat "non-existing-file")
69+ //! .fails()
70+ //! .and()
71+ //! .prints_error("non-existing-file")
72+ //! .unwrap();
5673//! # }
5774//! ```
5875//!
59- //! Don't forget to import the crate with `#[macro_use]`. ;-)
76+ //! Some notes on this:
77+ //!
78+ //! - Use `fails_with` to assert a specific exit status.
79+ //! - There is also a `succeeds` method, but this is already the implicit default
80+ //! and can usually be omitted.
81+ //! - We can inspect the output of **stderr** with `prints_error` and `prints_error_exactly`.
82+ //! - The `and` method has no effect, other than to make everything more readable.
83+ //! Feel free to use it. :-)
84+ //!
85+ //! ## Assert CLI Crates
86+ //!
87+ //! If you are testing a Rust binary crate, you can start with
88+ //! `Assert::main_binary()` to use `cargo run` as command. Or, if you want to
89+ //! run a specific binary (if you have more than one), use
90+ //! `Assert::cargo_binary`.
6091//!
6192//! ## Don't Panic!
6293//!
6697//! ```rust
6798//! # #[macro_use] extern crate assert_cli;
6899//! # fn main() {
69- //! let x = assert_cmd!(echo 1337).prints_exactly("42").execute();
100+ //! let x = assert_cmd!(echo " 1337" ).prints_exactly("42").execute();
70101//! assert!(x.is_err());
71102//! # }
72103//! ```
@@ -175,7 +206,6 @@ impl Assert {
175206 /// extern crate assert_cli;
176207 ///
177208 /// assert_cli::Assert::command(&["echo", "1337"])
178- /// .succeeds()
179209 /// .unwrap();
180210 /// ```
181211 pub fn command ( cmd : & [ & str ] ) -> Self {
@@ -194,7 +224,6 @@ impl Assert {
194224 ///
195225 /// assert_cli::Assert::command(&["echo"])
196226 /// .with_args(&["42"])
197- /// .succeeds()
198227 /// .prints("42")
199228 /// .unwrap();
200229 /// ```
@@ -211,7 +240,7 @@ impl Assert {
211240 /// extern crate assert_cli;
212241 ///
213242 /// assert_cli::Assert::command(&["echo", "42"])
214- /// .succeeds().and(). prints("42")
243+ /// .prints("42")
215244 /// .unwrap();
216245 /// ```
217246 pub fn and ( self ) -> Self {
@@ -226,7 +255,6 @@ impl Assert {
226255 /// extern crate assert_cli;
227256 ///
228257 /// assert_cli::Assert::command(&["echo", "42"])
229- /// .succeeds()
230258 /// .unwrap();
231259 /// ```
232260 pub fn succeeds ( mut self ) -> Self {
@@ -245,8 +273,10 @@ impl Assert {
245273 /// ```rust
246274 /// extern crate assert_cli;
247275 ///
248- /// assert_cli::Assert::command(&["cat", "non-exisiting -file"])
276+ /// assert_cli::Assert::command(&["cat", "non-existing -file"])
249277 /// .fails()
278+ /// .and()
279+ /// .prints_error("non-existing-file")
250280 /// .unwrap();
251281 /// ```
252282 pub fn fails ( mut self ) -> Self {
@@ -261,8 +291,10 @@ impl Assert {
261291 /// ```rust
262292 /// extern crate assert_cli;
263293 ///
264- /// assert_cli::Assert::command(&["cat", "non-exisiting -file"])
294+ /// assert_cli::Assert::command(&["cat", "non-existing -file"])
265295 /// .fails_with(1)
296+ /// .and()
297+ /// .prints_error_exactly("cat: non-existing-file: No such file or directory")
266298 /// .unwrap();
267299 /// ```
268300 pub fn fails_with ( mut self , expect_exit_code : i32 ) -> Self {
@@ -271,7 +303,7 @@ impl Assert {
271303 self
272304 }
273305
274- /// Expect the command's output to contain `output`.
306+ /// Expect the command's output to ** contain** `output`.
275307 ///
276308 /// # Examples
277309 ///
@@ -290,7 +322,7 @@ impl Assert {
290322 self
291323 }
292324
293- /// Expect the command to output exactly this `output`.
325+ /// Expect the command to output ** exactly** this `output`.
294326 ///
295327 /// # Examples
296328 ///
@@ -309,16 +341,17 @@ impl Assert {
309341 self
310342 }
311343
312- /// Expect the command's stderr output to contain `output`.
344+ /// Expect the command's stderr output to ** contain** `output`.
313345 ///
314346 /// # Examples
315347 ///
316348 /// ```rust
317349 /// extern crate assert_cli;
318350 ///
319- /// assert_cli::Assert::command(&["cat", "non-exisiting -file"])
351+ /// assert_cli::Assert::command(&["cat", "non-existing -file"])
320352 /// .fails()
321- /// .prints_error("non-exisiting-file")
353+ /// .and()
354+ /// .prints_error("non-existing-file")
322355 /// .unwrap();
323356 /// ```
324357 pub fn prints_error < O : Into < String > > ( mut self , output : O ) -> Self {
@@ -329,16 +362,17 @@ impl Assert {
329362 self
330363 }
331364
332- /// Expect the command to output exactly this `output` to stderr.
365+ /// Expect the command to output ** exactly** this `output` to stderr.
333366 ///
334367 /// # Examples
335368 ///
336369 /// ```rust
337370 /// extern crate assert_cli;
338371 ///
339- /// assert_cli::Assert::command(&["cat", "non-exisiting-file"])
340- /// .fails()
341- /// .prints_error_exactly("cat: non-exisiting-file: No such file or directory")
372+ /// assert_cli::Assert::command(&["cat", "non-existing-file"])
373+ /// .fails_with(1)
374+ /// .and()
375+ /// .prints_error_exactly("cat: non-existing-file: No such file or directory")
342376 /// .unwrap();
343377 /// ```
344378 pub fn prints_error_exactly < O : Into < String > > ( mut self , output : O ) -> Self {
@@ -357,7 +391,7 @@ impl Assert {
357391 /// extern crate assert_cli;
358392 ///
359393 /// let test = assert_cli::Assert::command(&["echo", "42"])
360- /// .succeeds( )
394+ /// .prints("42" )
361395 /// .execute();
362396 /// assert!(test.is_ok());
363397 /// ```
0 commit comments