aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-01 09:37:55 +0100
committerAleksey Kladov <[email protected]>2020-07-01 09:44:16 +0100
commit977b688144fb997fdf5dd5bdb587e4f357d853f2 (patch)
treef0fc4901a4fbe04cf07723d2f37eda8c7dc074cb /crates
parent686e115e7397028a94bde57df1acf0f066651285 (diff)
Don't fail tests when updating snapshot
Diffstat (limited to 'crates')
-rw-r--r--crates/expect/src/lib.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/crates/expect/src/lib.rs b/crates/expect/src/lib.rs
index dd7b96aab..d678b1817 100644
--- a/crates/expect/src/lib.rs
+++ b/crates/expect/src/lib.rs
@@ -2,7 +2,7 @@
2//! https://github.com/rust-analyzer/rust-analyzer/pull/5101 2//! https://github.com/rust-analyzer/rust-analyzer/pull/5101
3use std::{ 3use std::{
4 collections::HashMap, 4 collections::HashMap,
5 env, fmt, fs, 5 env, fmt, fs, mem,
6 ops::Range, 6 ops::Range,
7 panic, 7 panic,
8 path::{Path, PathBuf}, 8 path::{Path, PathBuf},
@@ -97,24 +97,25 @@ static RT: Lazy<Mutex<Runtime>> = Lazy::new(Default::default);
97impl Runtime { 97impl Runtime {
98 fn fail(expect: &Expect, expected: &str, actual: &str) { 98 fn fail(expect: &Expect, expected: &str, actual: &str) {
99 let mut rt = RT.lock().unwrap_or_else(|poisoned| poisoned.into_inner()); 99 let mut rt = RT.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
100 let mut updated = "";
101 if update_expect() { 100 if update_expect() {
102 updated = " (updated)"; 101 println!(
102 "\x1b[1m\x1b[92mupdating\x1b[0m: {}:{}:{}",
103 expect.file, expect.line, expect.column
104 );
103 rt.per_file 105 rt.per_file
104 .entry(expect.file) 106 .entry(expect.file)
105 .or_insert_with(|| FileRuntime::new(expect)) 107 .or_insert_with(|| FileRuntime::new(expect))
106 .update(expect, actual); 108 .update(expect, actual);
109 return;
107 } 110 }
108 let print_help = !rt.help_printed && !update_expect(); 111 let print_help = !mem::replace(&mut rt.help_printed, true);
109 rt.help_printed = true;
110
111 let help = if print_help { HELP } else { "" }; 112 let help = if print_help { HELP } else { "" };
112 113
113 let diff = Changeset::new(actual, expected, "\n"); 114 let diff = Changeset::new(actual, expected, "\n");
114 115
115 println!( 116 println!(
116 "\n 117 "\n
117\x1b[1m\x1b[91merror\x1b[97m: expect test failed\x1b[0m{} 118\x1b[1m\x1b[91merror\x1b[97m: expect test failed\x1b[0m
118 \x1b[1m\x1b[34m-->\x1b[0m {}:{}:{} 119 \x1b[1m\x1b[34m-->\x1b[0m {}:{}:{}
119{} 120{}
120\x1b[1mExpect\x1b[0m: 121\x1b[1mExpect\x1b[0m:
@@ -132,7 +133,7 @@ impl Runtime {
132{} 133{}
133---- 134----
134", 135",
135 updated, expect.file, expect.line, expect.column, help, expected, actual, diff 136 expect.file, expect.line, expect.column, help, expected, actual, diff
136 ); 137 );
137 // Use resume_unwind instead of panic!() to prevent a backtrace, which is unnecessary noise. 138 // Use resume_unwind instead of panic!() to prevent a backtrace, which is unnecessary noise.
138 panic::resume_unwind(Box::new(())); 139 panic::resume_unwind(Box::new(()));