From 5cea8c6536a9a690bd5af89835b6548986974da8 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 23 Dec 2021 11:52:32 -0800 Subject: [PATCH] Allow users to turn off in-place update for specific `Expect`s --- src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index dd877be..4c5c1a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -178,6 +178,7 @@ macro_rules! expect { }, data: $data, indent: true, + update: true, }}; [[]] => { $crate::expect![[""]] }; } @@ -205,6 +206,8 @@ pub struct Expect { pub data: &'static str, #[doc(hidden)] pub indent: bool, + #[doc(hidden)] + pub update: bool, } /// Self-updating file. @@ -252,6 +255,11 @@ impl Expect { self.indent = yes; } + /// If `true` (default), in-place update will be enabled for this `Expect`. + pub fn update(&mut self, yes: bool) { + self.update = yes; + } + fn trimmed(&self) -> String { if !self.data.contains('\n') { return self.data.to_string(); @@ -321,7 +329,7 @@ static RT: Lazy> = Lazy::new(Default::default); impl Runtime { fn fail_expect(expect: &Expect, expected: &str, actual: &str) { let mut rt = RT.lock().unwrap_or_else(|poisoned| poisoned.into_inner()); - if update_expect() { + if expect.update && update_expect() { println!("\x1b[1m\x1b[92mupdating\x1b[0m: {}", expect.position); rt.per_file .entry(expect.position.file)