Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ macro_rules! expect {
},
data: $data,
indent: true,
update: true,
}};
[[]] => { $crate::expect![[""]] };
}
Expand Down Expand Up @@ -205,6 +206,8 @@ pub struct Expect {
pub data: &'static str,
#[doc(hidden)]
pub indent: bool,
#[doc(hidden)]
pub update: bool,
}

/// Self-updating file.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -321,7 +329,7 @@ static RT: Lazy<Mutex<Runtime>> = 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)
Expand Down