mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
fix tests
This commit is contained in:
parent
0b6d4983de
commit
b43bcd43c6
3 changed files with 23 additions and 46 deletions
|
@ -1,13 +1,15 @@
|
|||
extern crate itertools;
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
extern crate teraron;
|
||||
|
||||
use itertools::Itertools;
|
||||
use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use itertools::Itertools;
|
||||
|
||||
pub use teraron::{Mode, Verify, Overwrite};
|
||||
|
||||
pub type Result<T> = ::std::result::Result<T, failure::Error>;
|
||||
|
||||
pub const GRAMMAR: &str = "ra_syntax/src/grammar.ron";
|
||||
|
@ -54,22 +56,23 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> {
|
|||
res
|
||||
}
|
||||
|
||||
pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> {
|
||||
match fs::read_to_string(path) {
|
||||
Ok(ref old_contents) if old_contents == contents => {
|
||||
return Ok(());
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
if verify {
|
||||
bail!("`{}` is not up-to-date", path.display());
|
||||
}
|
||||
eprintln!("updating {}", path.display());
|
||||
fs::write(path, contents)?;
|
||||
pub fn generate(mode: Mode) -> Result<()> {
|
||||
let grammar = project_root().join(GRAMMAR);
|
||||
let syntax_kinds = project_root().join(SYNTAX_KINDS);
|
||||
let ast = project_root().join(AST);
|
||||
teraron::generate(
|
||||
&syntax_kinds,
|
||||
&grammar,
|
||||
mode,
|
||||
)?;
|
||||
teraron::generate(
|
||||
&ast,
|
||||
&grammar,
|
||||
mode,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
pub fn project_root() -> PathBuf {
|
||||
Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
|
||||
.parent()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue