aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tools/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-08-19 09:05:49 +0100
committerAleksey Kladov <[email protected]>2019-08-19 09:42:39 +0100
commit5633829a1684fb622d44d1aeb3baede4e7c0ff26 (patch)
treefc3d0ce648fd16842de918df2c6d61d60275e865 /crates/ra_tools/src/lib.rs
parent832b40a075285063b857bf05a69a8cf979d9078a (diff)
drop tera dependency
Diffstat (limited to 'crates/ra_tools/src/lib.rs')
-rw-r--r--crates/ra_tools/src/lib.rs28
1 files changed, 25 insertions, 3 deletions
diff --git a/crates/ra_tools/src/lib.rs b/crates/ra_tools/src/lib.rs
index de8c472d1..c02dee953 100644
--- a/crates/ra_tools/src/lib.rs
+++ b/crates/ra_tools/src/lib.rs
@@ -11,8 +11,6 @@ use std::{
11 11
12use itertools::Itertools; 12use itertools::Itertools;
13 13
14pub use teraron::{Mode, Overwrite, Verify};
15
16pub use self::codegen::generate; 14pub use self::codegen::generate;
17 15
18pub type Result<T> = std::result::Result<T, Box<dyn Error>>; 16pub 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
26pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs"; 24pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs";
27const TOOLCHAIN: &str = "stable"; 25const TOOLCHAIN: &str = "stable";
28 26
27#[derive(Debug, PartialEq, Eq, Clone, Copy)]
28pub enum Mode {
29 Overwrite,
30 Verify,
31}
32pub use Mode::*;
33
29#[derive(Debug)] 34#[derive(Debug)]
30pub struct Test { 35pub struct Test {
31 pub name: String, 36 pub name: String,
@@ -222,7 +227,7 @@ pub fn gen_tests(mode: Mode) -> Result<()> {
222 tests_dir.join(file_name) 227 tests_dir.join(file_name)
223 } 228 }
224 }; 229 };
225 teraron::update(&path, &test.text, mode)?; 230 update(&path, &test.text, mode)?;
226 } 231 }
227 Ok(()) 232 Ok(())
228 } 233 }
@@ -306,3 +311,20 @@ fn existing_tests(dir: &Path, ok: bool) -> Result<HashMap<String, (PathBuf, Test
306 } 311 }
307 Ok(res) 312 Ok(res)
308} 313}
314
315/// A helper to update file on disk if it has changed.
316/// With verify = false,
317pub fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
318 match fs::read_to_string(path) {
319 Ok(ref old_contents) if old_contents == contents => {
320 return Ok(());
321 }
322 _ => (),
323 }
324 if mode == Verify {
325 Err(format!("`{}` is not up-to-date", path.display()))?;
326 }
327 eprintln!("updating {}", path.display());
328 fs::write(path, contents)?;
329 Ok(())
330}