Converts a type to an [`OutputResult`]. This is for example implemented on [`std::process::Output`]. # Examples ```rust use assert_cmd::prelude::*; use std::process::Command; let result = Command::new("echo") .args(&["42"]) .ok(); assert!(result.is_ok()); ```
| 23 | /// ``` |
| 24 | /// |
| 25 | pub trait OutputOkExt |
| 26 | where |
| 27 | Self: ::std::marker::Sized, |
| 28 | { |
| 29 | /// Convert an [`Output`] to an [`OutputResult`]. |
| 30 | /// |
| 31 | /// # Examples |
| 32 | /// |
| 33 | /// ```rust |
| 34 | /// use assert_cmd::prelude::*; |
| 35 | /// |
| 36 | /// use std::process::Command; |
| 37 | /// |
| 38 | /// let result = Command::new("echo") |
| 39 | /// .args(&["42"]) |
| 40 | /// .ok(); |
| 41 | /// assert!(result.is_ok()); |
| 42 | /// ``` |
| 43 | /// |
| 44 | /// [`Output`]: std::process::Output |
| 45 | fn ok(self) -> OutputResult; |
| 46 | |
| 47 | /// Unwrap a [`Output`] but with a prettier message than `.ok().unwrap()`. |
| 48 | /// |
| 49 | /// # Examples |
| 50 | /// |
| 51 | /// ```rust |
| 52 | /// use assert_cmd::prelude::*; |
| 53 | /// |
| 54 | /// use std::process::Command; |
| 55 | /// |
| 56 | /// let output = Command::new("echo") |
| 57 | /// .args(&["42"]) |
| 58 | /// .unwrap(); |
| 59 | /// ``` |
| 60 | /// |
| 61 | /// [`Output`]: std::process::Output |
| 62 | #[track_caller] |
| 63 | fn unwrap(self) -> process::Output { |
| 64 | match self.ok() { |
| 65 | Ok(output) => output, |
| 66 | Err(err) => panic!("{}", err), |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /// Unwrap a [`Output`] but with a prettier message than `ok().err().unwrap()`. |
| 71 | /// |
| 72 | /// # Examples |
| 73 | /// |
| 74 | /// ```rust,no_run |
| 75 | /// use assert_cmd::prelude::*; |
| 76 | /// |
| 77 | /// use std::process::Command; |
| 78 | /// |
| 79 | /// let err = Command::new("a-command") |
| 80 | /// .args(&["--will-fail"]) |
| 81 | /// .unwrap_err(); |
| 82 | /// ``` |
no outgoing calls
no test coverage detected