From 8d4a5ac0519b1c6c522ead0c5e087e7f1e2fc94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Wed, 31 May 2023 14:25:10 +0200 Subject: [PATCH 1/2] chore(tests): second iteration on improving coverage --- src/lib/cli.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lib/cli.rs b/src/lib/cli.rs index cceb257..c11db95 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,25 @@ 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)); + + assert!(!handle.is_finished()); + } } #[cfg(feature = "cli-complete")] From db076cc55b4b9dcbf902343ed661fcb38d2cc1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Tue, 6 Jun 2023 17:39:26 +0200 Subject: [PATCH 2/2] chore(test): fix when not terminal --- src/lib/cli.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/cli.rs b/src/lib/cli.rs index c11db95..7623886 100644 --- a/src/lib/cli.rs +++ b/src/lib/cli.rs @@ -236,7 +236,11 @@ mod tests { std::thread::sleep(std::time::Duration::from_millis(100)); - assert!(!handle.is_finished()); + if std::io::stdin().is_terminal() { + assert!(!handle.is_finished()); + } else { + assert!(handle.is_finished()); + } } }