mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Allow to update files en masse
This commit is contained in:
parent
3c9d8ff423
commit
1401f5af4a
1 changed files with 13 additions and 5 deletions
|
@ -22,8 +22,8 @@ fn read_text(path: &Path) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dir_tests<F>(paths: &[&str], f: F)
|
pub fn dir_tests<F>(paths: &[&str], f: F)
|
||||||
where
|
where
|
||||||
F: Fn(&str) -> String,
|
F: Fn(&str) -> String,
|
||||||
{
|
{
|
||||||
for path in collect_tests(paths) {
|
for path in collect_tests(paths) {
|
||||||
let actual = {
|
let actual = {
|
||||||
|
@ -73,16 +73,24 @@ fn test_from_dir(dir: &Path) -> Vec<PathBuf> {
|
||||||
acc
|
acc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const REWRITE: bool = false;
|
||||||
|
|
||||||
fn print_difference(expected: &str, actual: &str, path: &Path) {
|
fn print_difference(expected: &str, actual: &str, path: &Path) {
|
||||||
let dir = project_dir();
|
let dir = project_dir();
|
||||||
let path = path.strip_prefix(&dir).unwrap_or_else(|_| path);
|
let path = path.strip_prefix(&dir).unwrap_or_else(|_| path);
|
||||||
if expected.trim() == actual.trim() {
|
if expected.trim() == actual.trim() {
|
||||||
println!("whitespace difference, rewriting");
|
println!("whitespace difference, rewriting");
|
||||||
|
println!("file: {}\n", path.display());
|
||||||
file::put_text(path, actual).unwrap();
|
file::put_text(path, actual).unwrap();
|
||||||
} else {
|
return;
|
||||||
let changeset = Changeset::new(actual, expected, "\n");
|
|
||||||
print!("{}", changeset);
|
|
||||||
}
|
}
|
||||||
|
if REWRITE {
|
||||||
|
println!("rewriting {}", path.display());
|
||||||
|
file::put_text(path, actual).unwrap();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let changeset = Changeset::new(actual, expected, "\n");
|
||||||
|
print!("{}", changeset);
|
||||||
println!("file: {}\n", path.display());
|
println!("file: {}\n", path.display());
|
||||||
panic!("Comparison failed")
|
panic!("Comparison failed")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue