drop tera dependency

This commit is contained in:
Aleksey Kladov
2019-08-19 11:05:49 +03:00
parent 832b40a075
commit 5633829a16
3 changed files with 25 additions and 152 deletions

View File

@@ -11,8 +11,6 @@ use std::{
use itertools::Itertools;
pub use teraron::{Mode, Overwrite, Verify};
pub use self::codegen::generate;
pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
@@ -26,6 +24,13 @@ pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs.te
pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs";
const TOOLCHAIN: &str = "stable";
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Mode {
Overwrite,
Verify,
}
pub use Mode::*;
#[derive(Debug)]
pub struct Test {
pub name: String,
@@ -222,7 +227,7 @@ pub fn gen_tests(mode: Mode) -> Result<()> {
tests_dir.join(file_name)
}
};
teraron::update(&path, &test.text, mode)?;
update(&path, &test.text, mode)?;
}
Ok(())
}
@@ -306,3 +311,20 @@ fn existing_tests(dir: &Path, ok: bool) -> Result<HashMap<String, (PathBuf, Test
}
Ok(res)
}
/// A helper to update file on disk if it has changed.
/// With verify = false,
pub fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
match fs::read_to_string(path) {
Ok(ref old_contents) if old_contents == contents => {
return Ok(());
}
_ => (),
}
if mode == Verify {
Err(format!("`{}` is not up-to-date", path.display()))?;
}
eprintln!("updating {}", path.display());
fs::write(path, contents)?;
Ok(())
}