use a generic Write instance for command output

This commit is contained in:
Dustin J. Mitchell
2020-12-20 19:45:24 -05:00
parent 6b550e7516
commit 7d17740ca8
13 changed files with 154 additions and 46 deletions

View File

@@ -1,3 +1,4 @@
use std::io;
use taskchampion::{server, taskstorage, Replica, ServerConfig};
use tempdir::TempDir;
@@ -12,3 +13,38 @@ pub(super) fn test_server(dir: &TempDir) -> Box<dyn server::Server> {
})
.unwrap()
}
pub(super) struct TestWriter {
data: Vec<u8>,
}
impl TestWriter {
pub(super) fn into_string(self) -> String {
String::from_utf8(self.data).unwrap()
}
}
impl io::Write for TestWriter {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.data.write(buf)
}
fn flush(&mut self) -> io::Result<()> {
self.data.flush()
}
}
impl termcolor::WriteColor for TestWriter {
fn supports_color(&self) -> bool {
false
}
fn set_color(&mut self, _spec: &termcolor::ColorSpec) -> io::Result<()> {
Ok(())
}
fn reset(&mut self) -> io::Result<()> {
Ok(())
}
}
pub(super) fn test_writer() -> TestWriter {
TestWriter { data: vec![] }
}