|
| 1 | +#![cfg(feature = "cli")] |
| 2 | + |
| 3 | +pub mod _utils; |
| 4 | +pub use _utils::*; |
| 5 | + |
| 6 | +use command_extra::CommandExtra; |
| 7 | +use pipe_trait::Pipe; |
| 8 | +use pretty_assertions::assert_eq; |
| 9 | +use std::process::{Command, Output, Stdio}; |
| 10 | + |
| 11 | +fn stdio(command: Command) -> Command { |
| 12 | + command |
| 13 | + .with_stdin(Stdio::null()) |
| 14 | + .with_stdout(Stdio::piped()) |
| 15 | + .with_stderr(Stdio::piped()) |
| 16 | +} |
| 17 | + |
| 18 | +#[test] |
| 19 | +fn min_ratio_1() { |
| 20 | + let workspace = SampleWorkspace::default(); |
| 21 | + let Output { |
| 22 | + status, |
| 23 | + stdout, |
| 24 | + stderr, |
| 25 | + } = Command::new(PDU) |
| 26 | + .with_current_dir(workspace.as_path()) |
| 27 | + .with_arg("--min-ratio=1") |
| 28 | + .pipe(stdio) |
| 29 | + .output() |
| 30 | + .expect("spawn command"); |
| 31 | + let stderr = String::from_utf8(stderr).expect("parse stderr as UTF-8"); |
| 32 | + let stderr = stderr.trim(); |
| 33 | + dbg!(&status); |
| 34 | + eprintln!("STDERR:\n{}\n", stderr); |
| 35 | + assert!(!status.success()); |
| 36 | + assert_eq!( |
| 37 | + stderr, |
| 38 | + "error: Invalid value for '--min-ratio <min-ratio>': greater than or equal to 1" |
| 39 | + ); |
| 40 | + assert_eq!(&stdout, &[] as &[u8]); |
| 41 | +} |
| 42 | + |
| 43 | +#[test] |
| 44 | +fn max_depth_0() { |
| 45 | + let workspace = SampleWorkspace::default(); |
| 46 | + let Output { |
| 47 | + status, |
| 48 | + stdout, |
| 49 | + stderr, |
| 50 | + } = Command::new(PDU) |
| 51 | + .with_current_dir(workspace.as_path()) |
| 52 | + .with_arg("--max-depth=0") |
| 53 | + .pipe(stdio) |
| 54 | + .output() |
| 55 | + .expect("spawn command"); |
| 56 | + let stderr = String::from_utf8(stderr).expect("parse stderr as UTF-8"); |
| 57 | + let stderr = stderr.trim(); |
| 58 | + dbg!(&status); |
| 59 | + eprintln!("STDERR:\n{}\n", stderr); |
| 60 | + assert!(!status.success()); |
| 61 | + assert_eq!( |
| 62 | + stderr, |
| 63 | + "error: Invalid value for '--max-depth <max-depth>': number would be zero for non-zero type" |
| 64 | + ); |
| 65 | + assert_eq!(&stdout, &[] as &[u8]); |
| 66 | +} |
0 commit comments