drop tera dependency
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user