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

Commit cc2d7be

Browse files
committed
documentation tweaks
- note: std has `.` at the end of one-line doc-strings.
1 parent ed19a66 commit cc2d7be

File tree

1 file changed

+52
-28
lines changed

1 file changed

+52
-28
lines changed

src/lib.rs

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
//!
33
//! This crate's goal is to provide you some very easy tools to test your CLI
44
//! applications. It can currently execute child processes and validate their
5-
//! exit status as well as stdout output against your assertions.
5+
//! exit status as well as stdout and stderr output against your assertions.
66
//!
7-
//! ## Examples
7+
//! Include the crate like
88
//!
9-
//! Here's a trivial example:
9+
//! ```rust
10+
//! #[macro_use] // <-- import the convenience macro (optional)
11+
//! extern crate assert_cli;
12+
//! # fn main() { }
13+
//! ```
1014
//!
11-
//! ```rust extern crate assert_cli;
15+
//! ## Basic Examples
16+
//!
17+
//! Here's a trivial example:
1218
//!
19+
//! ```rust
1320
//! assert_cli::Assert::command(&["echo", "42"])
1421
//! .succeeds()
1522
//! .and().prints("42")
@@ -20,7 +27,7 @@
2027
//!
2128
//! ```rust,should_panic
2229
//! assert_cli::Assert::command(&["echo", "42"])
23-
//! .prints("1337")
30+
//! .prints_exactly("1337")
2431
//! .unwrap();
2532
//! ```
2633
//!
@@ -31,29 +38,33 @@
3138
//! +42
3239
//! ```
3340
//!
41+
//! ## Assert CLI Crates
42+
//!
3443
//! If you are testing a Rust binary crate, you can start with
3544
//! `Assert::main_binary()` to use `cargo run` as command. Or, if you want to
3645
//! run a specific binary (if you have more than one), use
3746
//! `Assert::cargo_binary`.
3847
//!
39-
//! Alternatively, you can use the `assert_cmd!` macro to construct the command:
48+
//! ## `assert_cmd!` Macro
4049
//!
41-
//! ```rust
42-
//! #[macro_use] extern crate assert_cli;
50+
//! Alternatively, you can use the `assert_cmd!` macro to construct the command more conveniently:
4351
//!
52+
//! ```rust
53+
//! # #[macro_use] extern crate assert_cli;
4454
//! # fn main() {
4555
//! assert_cmd!(echo 42).succeeds().prints("42").unwrap();
4656
//! # }
4757
//! ```
4858
//!
49-
//! (Make sure to include the crate as `#[macro_use] extern crate assert_cli;`!)
59+
//! Don't forget to import the crate with `#[macro_use]`. ;-)
60+
//!
61+
//! ## Don't Panic!
5062
//!
5163
//! If you don't want it to panic when the assertions are not met, simply call
5264
//! `.execute` instead of `.unwrap` to get a `Result`:
5365
//!
5466
//! ```rust
55-
//! #[macro_use] extern crate assert_cli;
56-
//!
67+
//! # #[macro_use] extern crate assert_cli;
5768
//! # fn main() {
5869
//! let x = assert_cmd!(echo 1337).prints_exactly("42").execute();
5970
//! assert!(x.is_err());
@@ -74,7 +85,7 @@ use errors::*;
7485

7586
mod diff;
7687

77-
/// Assertions for a specific command
88+
/// Assertions for a specific command.
7889
#[derive(Debug)]
7990
pub struct Assert {
8091
cmd: Vec<String>,
@@ -88,6 +99,8 @@ pub struct Assert {
8899

89100
impl std::default::Default for Assert {
90101
/// Construct an assert using `cargo run --` as command.
102+
///
103+
/// Defaults to asserting _successful_ execution.
91104
fn default() -> Self {
92105
Assert {
93106
cmd: vec!["cargo", "run", "--"]
@@ -103,12 +116,16 @@ impl std::default::Default for Assert {
103116
}
104117

105118
impl Assert {
106-
/// Use the crate's main binary as command
119+
/// Run the crate's main binary.
120+
///
121+
/// Defaults to asserting _successful_ execution.
107122
pub fn main_binary() -> Self {
108123
Assert::default()
109124
}
110125

111-
/// Use the crate's main binary as command
126+
/// Run a specific binary of the current crate.
127+
///
128+
/// Defaults to asserting _successful_ execution.
112129
pub fn cargo_binary(name: &str) -> Self {
113130
Assert {
114131
cmd: vec!["cargo", "run", "--bin", name, "--"]
@@ -117,7 +134,9 @@ impl Assert {
117134
}
118135
}
119136

120-
/// Use custom command
137+
/// Run a custom command.
138+
///
139+
/// Defaults to asserting _successful_ execution.
121140
///
122141
/// # Examples
123142
///
@@ -135,7 +154,7 @@ impl Assert {
135154
}
136155
}
137156

138-
/// Add arguments to the command
157+
/// Add arguments to the command.
139158
///
140159
/// # Examples
141160
///
@@ -153,7 +172,7 @@ impl Assert {
153172
self
154173
}
155174

156-
/// Small helper to make chains more readable
175+
/// Small helper to make chains more readable.
157176
///
158177
/// # Examples
159178
///
@@ -168,7 +187,9 @@ impl Assert {
168187
self
169188
}
170189

171-
/// Expect the command to be executed successfully
190+
/// Expect the command to be executed successfully.
191+
///
192+
/// Note: This is already set by default, so you only need this for explicitness.
172193
///
173194
/// # Examples
174195
///
@@ -184,7 +205,10 @@ impl Assert {
184205
self
185206
}
186207

187-
/// Expect the command to fail
208+
/// Expect the command to fail.
209+
///
210+
/// Note: This does not include shell failures like `command not found`. I.e. the
211+
/// command must _run_ and fail for this assertion to pass.
188212
///
189213
/// # Examples
190214
///
@@ -200,7 +224,7 @@ impl Assert {
200224
self
201225
}
202226

203-
/// Expect the command to fail and return a specific error code
227+
/// Expect the command to fail and return a specific error code.
204228
///
205229
/// # Examples
206230
///
@@ -217,7 +241,7 @@ impl Assert {
217241
self
218242
}
219243

220-
/// Expect the command's output to contain `output`
244+
/// Expect the command's output to contain `output`.
221245
///
222246
/// # Examples
223247
///
@@ -234,7 +258,7 @@ impl Assert {
234258
self
235259
}
236260

237-
/// Expect the command to output exactly this `output`
261+
/// Expect the command to output exactly this `output`.
238262
///
239263
/// # Examples
240264
///
@@ -251,7 +275,7 @@ impl Assert {
251275
self
252276
}
253277

254-
/// Expect the command's stderr output to contain `output`
278+
/// Expect the command's stderr output to contain `output`.
255279
///
256280
/// # Examples
257281
///
@@ -269,7 +293,7 @@ impl Assert {
269293
self
270294
}
271295

272-
/// Expect the command to output exactly this `output` to stderr
296+
/// Expect the command to output exactly this `output` to stderr.
273297
///
274298
/// # Examples
275299
///
@@ -287,7 +311,7 @@ impl Assert {
287311
self
288312
}
289313

290-
/// Execute the command and check the assertions
314+
/// Execute the command and check the assertions.
291315
///
292316
/// # Examples
293317
///
@@ -362,7 +386,7 @@ impl Assert {
362386
Ok(())
363387
}
364388

365-
/// Execute the command, check the assertions, and panic when they fail
389+
/// Execute the command, check the assertions, and panic when they fail.
366390
///
367391
/// # Examples
368392
///
@@ -380,7 +404,7 @@ impl Assert {
380404
}
381405
}
382406

383-
/// Easily construct an `Assert` with a custom command
407+
/// Easily construct an `Assert` with a custom command.
384408
///
385409
/// Make sure to include the crate as `#[macro_use] extern crate assert_cli;` if
386410
/// you want to use this macro.
@@ -394,7 +418,7 @@ impl Assert {
394418
/// No errors whatsoever
395419
/// ```
396420
///
397-
/// you would call it like this:
421+
/// ..., you would call it like this:
398422
///
399423
/// ```rust
400424
/// #[macro_use] extern crate assert_cli;

0 commit comments

Comments
 (0)