How can I turn the stdout
of stdout().into_raw_mode().unwrap()
into a string so I can test it? Note: stdout().into_raw_mode().unwrap()
is a RawTerminal<Stdout>
.
use std::io::Write;
fn write_to_stdout(stdout: &mut impl Write) {
write!(stdout, "Enter message: ").unwrap();
stdout.flush().unwrap();
}
#[cfg(test)]
mod tests {
use super::*;
use std::io::stdout;
use termion::raw::IntoRawMode;
#[test]
fn test_write_to_stdout() {
let mut stdout = stdout().into_raw_mode().unwrap();
write_to_stdout(&mut stdout);
// output = ??
assert!(output.contains("Enter message: "));
}
}