Skip to content

Commit eae70c6

Browse files
committed
Command docs: Check three unchecked exit statuses
These three doctests called `.status()` but ignored the result. Fix this. In two cases, with an assertion, and in the case where we are just printing something, by printing the exit status value. Signed-off-by: Ian Jackson <[email protected]>
1 parent 0076a3b commit eae70c6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

library/std/src/process.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,15 +493,17 @@ impl fmt::Debug for ChildStderr {
493493
/// let mut list_dir = Command::new("ls");
494494
///
495495
/// // Execute `ls` in the current directory of the program.
496-
/// list_dir.status().expect("process failed to execute");
496+
/// let status = list_dir.status().expect("process failed to execute");
497+
/// assert!(status.success());
497498
///
498499
/// println!();
499500
///
500501
/// // Change `ls` to execute in the root directory.
501502
/// list_dir.current_dir("/");
502503
///
503504
/// // And then execute `ls` again but in the root directory.
504-
/// list_dir.status().expect("process failed to execute");
505+
/// let status = list_dir.status().expect("process failed to execute");
506+
/// assert!(status.success());
505507
/// ```
506508
#[stable(feature = "process", since = "1.0.0")]
507509
pub struct Command {
@@ -1596,8 +1598,8 @@ impl Child {
15961598
///
15971599
/// let mut command = Command::new("ls");
15981600
/// if let Ok(mut child) = command.spawn() {
1599-
/// child.wait().expect("command wasn't running");
1600-
/// println!("Child has finished its execution!");
1601+
/// let status = child.wait().expect("command wasn't running");
1602+
/// println!("Child has finished its execution, status = {}!", status);
16011603
/// } else {
16021604
/// println!("ls command didn't start");
16031605
/// }

0 commit comments

Comments
 (0)