summaryrefslogtreecommitdiff
path: root/src/util/test_support.rs
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-06-22 19:56:40 +0300
committerA Farzat <a@farzat.xyz>2026-06-22 19:56:40 +0300
commit1293ea92bdbf3eb2086ec117e355714b6ee54ae9 (patch)
tree9de76726abd8c4de07904c7ed0284599211a53db /src/util/test_support.rs
parent711df9de70e8a61a441b7ba7200ae006258ce978 (diff)
downloadrepo2markdown-1293ea92bdbf3eb2086ec117e355714b6ee54ae9.tar.gz
repo2markdown-1293ea92bdbf3eb2086ec117e355714b6ee54ae9.zip
Make Logger's output destination customizableHEADmaster
This aids in testing and might allow logging to a file at a later point.
Diffstat (limited to 'src/util/test_support.rs')
-rw-r--r--src/util/test_support.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/util/test_support.rs b/src/util/test_support.rs
new file mode 100644
index 0000000..14a7a62
--- /dev/null
+++ b/src/util/test_support.rs
@@ -0,0 +1,40 @@
+use std::{
+ cell::RefCell,
+ io::{self, Write},
+ rc::Rc,
+};
+
+use crate::logger::{Logger, Verbosity};
+
+#[derive(Clone, Debug, Default)]
+pub(crate) struct SharedLog {
+ bytes: Rc<RefCell<Vec<u8>>>,
+}
+
+impl SharedLog {
+ pub(crate) fn contents(&self) -> String {
+ String::from_utf8(self.bytes.borrow().clone()).unwrap()
+ }
+}
+
+impl Write for SharedLog {
+ fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
+ self.bytes.borrow_mut().extend_from_slice(buf);
+ Ok(buf.len())
+ }
+
+ fn flush(&mut self) -> io::Result<()> {
+ Ok(())
+ }
+}
+
+pub(crate) fn quiet_logger() -> Logger<Vec<u8>> {
+ Logger::with_writer(Verbosity::Quiet, Vec::new())
+}
+
+pub(crate) fn logger_with_shared_log(verbosity: Verbosity) -> (Logger<SharedLog>, SharedLog) {
+ let shared_log = SharedLog::default();
+ let logger = Logger::with_writer(verbosity, shared_log.clone());
+
+ (logger, shared_log)
+}