diff --git a/src/lib/cli.rs b/src/lib/cli.rs index 03e24e0..5fe0727 100644 --- a/src/lib/cli.rs +++ b/src/lib/cli.rs @@ -36,7 +36,7 @@ where "Reading from STDIN, press [CTRL+D] when you're done." )?; } - let stdin = std::io::stdin(); + let stdin = io::stdin(); while stdin.read_line(buffer)? > 0 {} Ok(()) @@ -219,6 +219,29 @@ mod tests { fn test_cli() { Cli::command().debug_assert(); } + + #[test] + fn test_cli_from_build_cli() { + build_cli().debug_assert(); + } + + #[test] + fn test_read_from_stdin() { + let handle = std::thread::spawn(|| { + let mut sink = io::sink(); + let mut buffer = String::new(); + read_from_stdin(&mut sink, &mut buffer).unwrap(); + buffer + }); + + std::thread::sleep(std::time::Duration::from_millis(100)); + + if std::io::stdin().is_terminal() { + assert!(!handle.is_finished()); + } else { + assert!(handle.is_finished()); + } + } } #[cfg(feature = "cli-complete")]