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;
|
extern crate itertools;
|
||||||
#[macro_use]
|
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
|
extern crate teraron;
|
||||||
|
|
||||||
use itertools::Itertools;
|
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
|
pub use teraron::{Mode, Verify, Overwrite};
|
||||||
|
|
||||||
pub type Result<T> = ::std::result::Result<T, failure::Error>;
|
pub type Result<T> = ::std::result::Result<T, failure::Error>;
|
||||||
|
|
||||||
pub const GRAMMAR: &str = "ra_syntax/src/grammar.ron";
|
pub const GRAMMAR: &str = "ra_syntax/src/grammar.ron";
|
||||||
|
@ -54,22 +56,23 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> {
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> {
|
pub fn generate(mode: Mode) -> Result<()> {
|
||||||
match fs::read_to_string(path) {
|
let grammar = project_root().join(GRAMMAR);
|
||||||
Ok(ref old_contents) if old_contents == contents => {
|
let syntax_kinds = project_root().join(SYNTAX_KINDS);
|
||||||
return Ok(());
|
let ast = project_root().join(AST);
|
||||||
}
|
teraron::generate(
|
||||||
_ => (),
|
&syntax_kinds,
|
||||||
}
|
&grammar,
|
||||||
if verify {
|
mode,
|
||||||
bail!("`{}` is not up-to-date", path.display());
|
)?;
|
||||||
}
|
teraron::generate(
|
||||||
eprintln!("updating {}", path.display());
|
&ast,
|
||||||
fs::write(path, contents)?;
|
&grammar,
|
||||||
|
mode,
|
||||||
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn project_root() -> PathBuf {
|
pub fn project_root() -> PathBuf {
|
||||||
Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
|
Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
|
||||||
.parent()
|
.parent()
|
||||||
|
|
|
@ -13,9 +13,8 @@ use std::{
|
||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
use tools::{
|
use tools::{
|
||||||
collect_tests, project_root, Result, Test, AST, SYNTAX_KINDS, GRAMMAR,
|
collect_tests, Result, Test, generate, Mode, Overwrite, Verify,
|
||||||
};
|
};
|
||||||
use teraron::{Mode, Verify, Overwrite};
|
|
||||||
|
|
||||||
const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar";
|
const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar";
|
||||||
const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline";
|
const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline";
|
||||||
|
@ -41,21 +40,7 @@ fn main() -> Result<()> {
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
("install-code", _) => install_code_extension()?,
|
("install-code", _) => install_code_extension()?,
|
||||||
("gen-tests", _) => gen_tests(mode)?,
|
("gen-tests", _) => gen_tests(mode)?,
|
||||||
("gen-kinds", _) => {
|
("gen-kinds", _) => generate(Overwrite)?,
|
||||||
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,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,23 +1,12 @@
|
||||||
extern crate tools;
|
extern crate tools;
|
||||||
|
|
||||||
use tools::{
|
use tools::{
|
||||||
project_root, render_template, update, AST, AST_TEMPLATE, SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE,
|
generate, Verify
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn verify_template_generation() {
|
fn verify_template_generation() {
|
||||||
if let Err(error) = update(
|
if let Err(error) = generate(Verify) {
|
||||||
&project_root().join(SYNTAX_KINDS),
|
|
||||||
&render_template(&project_root().join(SYNTAX_KINDS_TEMPLATE)).unwrap(),
|
|
||||||
true,
|
|
||||||
) {
|
|
||||||
panic!("{}. Please update it by running `cargo gen-kinds`", error);
|
|
||||||
}
|
|
||||||
if let Err(error) = update(
|
|
||||||
&project_root().join(AST),
|
|
||||||
&render_template(&project_root().join(AST_TEMPLATE)).unwrap(),
|
|
||||||
true,
|
|
||||||
) {
|
|
||||||
panic!("{}. Please update it by running `cargo gen-kinds`", error);
|
panic!("{}. Please update it by running `cargo gen-kinds`", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue