Skip to content

Commit 50763ae

Browse files
authored
Merge pull request #33 from epage/audit
docs: Quick and dirty audit
2 parents 4cc90ee + c518c58 commit 50763ae

6 files changed

Lines changed: 138 additions & 56 deletions

File tree

src/assert.rs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//! `process::Output` assertions.
1+
//! [`Output`][Output] assertions.
2+
//!
3+
//! [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
24
35
use std::fmt;
46
use std::process;
@@ -10,7 +12,7 @@ use predicates::str::PredicateStrExt;
1012
use errors::dump_buffer;
1113
use errors::output_fmt;
1214

13-
/// Assert the state of an `Output`.
15+
/// Assert the state of an [`Output`][Output].
1416
///
1517
/// # Examples
1618
///
@@ -24,8 +26,10 @@ use errors::output_fmt;
2426
/// .assert()
2527
/// .success();
2628
/// ```
29+
///
30+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
2731
pub trait OutputAssertExt {
28-
/// Wrap with an interface for that provides assertions on the `process::Output`.
32+
/// Wrap with an interface for that provides assertions on the [`Output`][Output].
2933
///
3034
/// # Examples
3135
///
@@ -39,6 +43,8 @@ pub trait OutputAssertExt {
3943
/// .assert()
4044
/// .success();
4145
/// ```
46+
///
47+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
4248
fn assert(self) -> Assert;
4349
}
4450

@@ -55,9 +61,9 @@ impl<'c> OutputAssertExt for &'c mut process::Command {
5561
}
5662
}
5763

58-
/// Assert the state of an `Output`.
64+
/// Assert the state of an [`Output`][Output].
5965
///
60-
/// Create an `Assert` through the `OutputAssertExt` trait.
66+
/// Create an `Assert` through the [`OutputAssertExt`][OutputAssertExt] trait.
6167
///
6268
/// # Examples
6369
///
@@ -71,13 +77,18 @@ impl<'c> OutputAssertExt for &'c mut process::Command {
7177
/// .assert()
7278
/// .success();
7379
/// ```
80+
///
81+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
82+
/// [OutputAssertExt]: trait.OutputAssertExt.html
7483
pub struct Assert {
7584
output: process::Output,
7685
context: Vec<(&'static str, Box<fmt::Display>)>,
7786
}
7887

7988
impl Assert {
80-
/// Create an `Assert` for a given `Output`.
89+
/// Create an `Assert` for a given [`Output`][Output].
90+
///
91+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
8192
pub fn new(output: process::Output) -> Self {
8293
Self {
8394
output,
@@ -94,7 +105,9 @@ impl Assert {
94105
self
95106
}
96107

97-
/// Access the contained `std::process::Output`.
108+
/// Access the contained [`Output`][Output].
109+
///
110+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
98111
pub fn get_output(&self) -> &process::Output {
99112
&self.output
100113
}
@@ -307,7 +320,8 @@ impl fmt::Debug for Assert {
307320
}
308321
}
309322

310-
/// Used by `Assert::code` to convert `Self` into the needed `Predicate<i32>`.
323+
/// Used by [`Assert::code`][Assert_code] to convert `Self` into the needed
324+
/// [`Predicate<i32>`][Predicate].
311325
///
312326
/// # Examples
313327
///
@@ -328,6 +342,9 @@ impl fmt::Debug for Assert {
328342
/// .assert()
329343
/// .code(predicates::ord::eq(42));
330344
/// ```
345+
///
346+
/// [Assert_code]: struct.Assert.html#method.code
347+
/// [Predicate]: https://docs.rs/predicates/0.5.2/predicates/trait.Predicate.html
331348
pub trait IntoCodePredicate<P>
332349
where
333350
P: predicates::Predicate<i32>,
@@ -374,7 +391,12 @@ impl IntoCodePredicate<predicates::iter::InPredicate<i32>> for &'static [i32] {
374391
}
375392
}
376393

377-
/// Used by `Assert` to convert Self into the needed `Predicate<[u8]>`.
394+
/// Used by [`Assert::stdout`][Assert_stdout] and [`Assert::stderr`][Assert_stderr] to convert Self
395+
/// into the needed [`Predicate<[u8]>`][Predicate].
396+
///
397+
/// [Assert_stdout]: struct.Assert.html#method.stdout
398+
/// [Assert_stderr]: struct.Assert.html#method.stderr
399+
/// [Predicate]: https://docs.rs/predicates/0.5.2/predicates/trait.Predicate.html
378400
pub trait IntoOutputPredicate<P>
379401
where
380402
P: predicates::Predicate<[u8]>,
@@ -398,7 +420,10 @@ where
398420
}
399421

400422
// Keep `predicates` concrete Predicates out of our public API.
401-
/// Predicate used by `IntoOutputPredicate` for bytes
423+
/// [Predicate][Predicate] used by [`IntoOutputPredicate`][IntoOutputPredicate] for bytes.
424+
///
425+
/// [IntoOutputPredicate]: trait.IntoOutputPredicate.html
426+
/// [Predicate]: https://docs.rs/predicates/0.5.2/predicates/trait.Predicate.html
402427
#[derive(Debug)]
403428
pub struct BytesContentOutputPredicate(predicates::ord::EqPredicate<&'static [u8]>);
404429

@@ -430,7 +455,10 @@ impl IntoOutputPredicate<BytesContentOutputPredicate> for &'static [u8] {
430455
}
431456

432457
// Keep `predicates` concrete Predicates out of our public API.
433-
/// Predicate used by `IntoOutputPredicate` for `str`
458+
/// [Predicate][Predicate] used by [`IntoOutputPredicate`][IntoOutputPredicate] for `str`.
459+
///
460+
/// [IntoOutputPredicate]: trait.IntoOutputPredicate.html
461+
/// [Predicate]: https://docs.rs/predicates/0.5.2/predicates/trait.Predicate.html
434462
#[derive(Debug, Clone)]
435463
pub struct StrContentOutputPredicate(
436464
predicates::str::Utf8Predicate<predicates::str::DifferencePredicate>,

src/cargo.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//! Simplify running `bin`s in a Cargo project.
22
//!
3-
//! `CommandCargoExt` is an extension trait for `std::process::Command` to easily launch a crate's
3+
//! [`CommandCargoExt`][CommandCargoExt] is an extension trait for [`Command`][Command] to easily launch a crate's
44
//! binaries.
55
//!
66
//! In addition, the underlying functions for looking up the crate's binaries are exposed to allow
77
//! for optimizations, if needed.
88
//!
9-
//! # Simple Example
9+
//! # Examples
10+
//!
11+
//! Simple case:
1012
//!
1113
//! ```rust
1214
//! use assert_cmd::prelude::*;
@@ -18,7 +20,7 @@
1820
//! .unwrap();
1921
//! ```
2022
//!
21-
//! # Caching Example
23+
//! Caching the binary's location:
2224
//!
2325
//! ```rust
2426
//! use assert_cmd::prelude::*;
@@ -30,9 +32,11 @@
3032
//! .unwrap();
3133
//! ```
3234
//!
33-
//! Tip: Use [`lazy_static][lazy_static] to cache `bin_under_test` across test functions.
35+
//! Tip: Use [`lazy_static`][lazy_static] to cache `bin_under_test` across test functions.
3436
//!
3537
//! [lazy_static]: https://crates.io/crates/lazy_static
38+
//! [CommandCargoExt]: trait.CommandCargoExt.html
39+
//! [Command]: https://doc.rust-lang.org/std/process/struct.Command.html
3640
3741
use std::error::Error;
3842
use std::ffi;
@@ -42,12 +46,14 @@ use std::process;
4246

4347
use escargot;
4448

45-
/// Create a `Command` for a `bin` in the Cargo project.
49+
/// Create a [`Command`][Command] for a `bin` in the Cargo project.
50+
///
51+
/// [Command]: https://doc.rust-lang.org/std/process/struct.Command.html
4652
pub trait CommandCargoExt
4753
where
4854
Self: Sized,
4955
{
50-
/// Create a `Command` to run the crate's main binary.
56+
/// Create a [`Command`][Command] to run the crate's main binary.
5157
///
5258
/// Note: only works if there one bin in the crate.
5359
///
@@ -62,9 +68,11 @@ where
6268
/// .unwrap()
6369
/// .unwrap();
6470
/// ```
71+
///
72+
/// [Command]: https://doc.rust-lang.org/std/process/struct.Command.html
6573
fn main_binary() -> Result<Self, CargoError>;
6674

67-
/// Create a `Command` to run a specific binary of the current crate.
75+
/// Create a [`Command`][Command] to run a specific binary of the current crate.
6876
///
6977
/// # Examples
7078
///
@@ -77,9 +85,11 @@ where
7785
/// .unwrap()
7886
/// .unwrap();
7987
/// ```
88+
///
89+
/// [Command]: https://doc.rust-lang.org/std/process/struct.Command.html
8090
fn cargo_bin<S: AsRef<ffi::OsStr>>(name: S) -> Result<Self, CargoError>;
8191

82-
/// Create a `Command` to run a specific example of the current crate.
92+
/// Create a [`Command`][Command] to run a specific example of the current crate.
8393
///
8494
/// # Examples
8595
///
@@ -92,6 +102,8 @@ where
92102
/// .unwrap()
93103
/// .unwrap();
94104
/// ```
105+
///
106+
/// [Command]: https://doc.rust-lang.org/std/process/struct.Command.html
95107
fn cargo_example<S: AsRef<ffi::OsStr>>(name: S) -> Result<Self, CargoError>;
96108
}
97109

src/cmd.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use errors::dump_buffer;
44
use errors::OutputError;
55
use errors::OutputResult;
66

7-
/// Convert an `Output` to a `OutputResult`.
7+
/// Convert an [`Output`][Output] to an [`OutputResult`][OutputResult].
88
///
99
/// # Examples
1010
///
@@ -18,11 +18,14 @@ use errors::OutputResult;
1818
/// .ok();
1919
/// assert!(result.is_ok());
2020
/// ```
21+
///
22+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
23+
/// [OutputResult]: type.OutputResult.html
2124
pub trait OutputOkExt
2225
where
2326
Self: ::std::marker::Sized,
2427
{
25-
/// Convert an `std::process::Output` into an `OutputResult`.
28+
/// Convert an [`Output`][Output] to an [`OutputResult`][OutputResult].
2629
///
2730
/// # Examples
2831
///
@@ -36,9 +39,12 @@ where
3639
/// .ok();
3740
/// assert!(result.is_ok());
3841
/// ```
42+
///
43+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
44+
/// [OutputResult]: type.OutputResult.html
3945
fn ok(self) -> OutputResult;
4046

41-
/// Unwrap a `std::process::Output` but with a prettier message than `.ok().unwrap()`.
47+
/// Unwrap a [`Output`][Output] but with a prettier message than `.ok().unwrap()`.
4248
///
4349
/// # Examples
4450
///
@@ -51,14 +57,16 @@ where
5157
/// .args(&["42"])
5258
/// .unwrap();
5359
/// ```
60+
///
61+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
5462
fn unwrap(self) -> process::Output {
5563
match self.ok() {
5664
Ok(output) => output,
5765
Err(err) => panic!("{}", err),
5866
}
5967
}
6068

61-
/// Unwrap a `std::process::Output` but with a prettier message than `.ok().unwrap()`.
69+
/// Unwrap a [`Output`][Output] but with a prettier message than `ok().err().unwrap()`.
6270
///
6371
/// # Examples
6472
///
@@ -72,6 +80,8 @@ where
7280
/// .env("exit", "42")
7381
/// .unwrap_err();
7482
/// ```
83+
///
84+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
7585
fn unwrap_err(self) -> OutputError {
7686
match self.ok() {
7787
Ok(output) => panic!(

src/errors.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::fmt;
33
use std::process;
44
use std::str;
55

6-
/// `std::process::Output` represented as a `Result`.
6+
/// [`Output`][Output] represented as a [`Result`][Result].
7+
///
8+
/// Generally produced by [`OutputOkExt`][OutputOkExt].
79
///
810
/// # Examples
911
///
@@ -17,9 +19,15 @@ use std::str;
1719
/// .ok();
1820
/// assert!(result.is_ok());
1921
/// ```
22+
///
23+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
24+
/// [Result]: https://doc.rust-lang.org/std/result/enum.Result.html
25+
/// [OutputOkExt]: trait.OutputOkExt.html
2026
pub type OutputResult = Result<process::Output, OutputError>;
2127

22-
/// `Command` error.
28+
/// [`Command`][Command] error.
29+
///
30+
/// Generally produced by [`OutputOkExt`][OutputOkExt].
2331
///
2432
/// # Examples
2533
///
@@ -33,6 +41,9 @@ pub type OutputResult = Result<process::Output, OutputError>;
3341
/// .env("exit", "42")
3442
/// .unwrap_err();
3543
/// ```
44+
///
45+
/// [Command]: https://doc.rust-lang.org/std/process/struct.Command.html
46+
/// [OutputOkExt]: trait.OutputOkExt.html
3647
#[derive(Debug)]
3748
pub struct OutputError {
3849
cmd: Option<String>,
@@ -41,7 +52,10 @@ pub struct OutputError {
4152
}
4253

4354
impl OutputError {
44-
/// Convert `std::process::Output` into an `Error`.
55+
/// Convert [`Output`][Output] into an [`Error`][Error].
56+
///
57+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
58+
/// [Error]: https://doc.rust-lang.org/std/error/trait.Error.html
4559
pub fn new(output: process::Output) -> Self {
4660
Self {
4761
cmd: None,
@@ -50,7 +64,9 @@ impl OutputError {
5064
}
5165
}
5266

53-
/// For errors that happen in creating a `std::process::Output`.
67+
/// For errors that happen in creating a [`Output`][Output].
68+
///
69+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
5470
pub fn with_cause<E>(cause: E) -> Self
5571
where
5672
E: Error + Send + Sync + 'static,
@@ -74,7 +90,7 @@ impl OutputError {
7490
self
7591
}
7692

77-
/// Access the contained `std::process::Output`.
93+
/// Access the contained [`Output`][Output].
7894
///
7995
/// # Examples
8096
///
@@ -92,6 +108,8 @@ impl OutputError {
92108
/// .unwrap();
93109
/// assert_eq!(Some(42), output.status.code());
94110
/// ```
111+
///
112+
/// [Output]: https://doc.rust-lang.org/std/process/struct.Output.html
95113
pub fn as_output(&self) -> Option<&process::Output> {
96114
match self.cause {
97115
OutputCause::Expected(ref e) => Some(&e.output),
@@ -113,6 +131,7 @@ impl Error for OutputError {
113131
}
114132
}
115133
}
134+
116135
impl fmt::Display for OutputError {
117136
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
118137
if let Some(ref cmd) = self.cmd {
@@ -144,7 +163,6 @@ impl fmt::Display for OutputCause {
144163
}
145164
}
146165

147-
/// Wrap `Output` to be `Dislay`able.
148166
#[derive(Debug)]
149167
struct Output {
150168
output: process::Output,

0 commit comments

Comments
 (0)