From 114e9a2d74f1fa43c3418f8cd978fd4186fcb78b Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Sun, 14 Oct 2018 20:32:57 +0600 Subject: create cli.rs and make the tests passing --- crates/tools/tests/cli.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 crates/tools/tests/cli.rs (limited to 'crates/tools/tests') diff --git a/crates/tools/tests/cli.rs b/crates/tools/tests/cli.rs new file mode 100644 index 000000000..26d9a991c --- /dev/null +++ b/crates/tools/tests/cli.rs @@ -0,0 +1,16 @@ +extern crate tools; + +use std::path::Path; +use tools::{render_template, update}; + +const GRAMMAR: &str = "../ra_syntax/src/grammar.ron"; +const SYNTAX_KINDS: &str = "../ra_syntax/src/syntax_kinds/generated.rs"; +const SYNTAX_KINDS_TEMPLATE: &str = "../ra_syntax/src/syntax_kinds/generated.rs.tera"; +const AST: &str = "../ra_syntax/src/ast/generated.rs"; +const AST_TEMPLATE: &str = "../ra_syntax/src/ast/generated.rs.tera"; + +#[test] +fn verify_template_generation() { + update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE, GRAMMAR).unwrap(), true).unwrap(); + update(Path::new(AST), &render_template(AST_TEMPLATE, GRAMMAR).unwrap(), true).unwrap(); +} \ No newline at end of file -- cgit v1.2.3 From 33b378797c33bf29af4104e0b11c31252451df0c Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Sun, 14 Oct 2018 20:58:53 +0600 Subject: Show how to generate code with error message --- crates/tools/tests/cli.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'crates/tools/tests') diff --git a/crates/tools/tests/cli.rs b/crates/tools/tests/cli.rs index 26d9a991c..4d5b03b65 100644 --- a/crates/tools/tests/cli.rs +++ b/crates/tools/tests/cli.rs @@ -11,6 +11,10 @@ const AST_TEMPLATE: &str = "../ra_syntax/src/ast/generated.rs.tera"; #[test] fn verify_template_generation() { - update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE, GRAMMAR).unwrap(), true).unwrap(); - update(Path::new(AST), &render_template(AST_TEMPLATE, GRAMMAR).unwrap(), true).unwrap(); + if let Err(error) = update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE, GRAMMAR).unwrap(), true) { + panic!("{}. Please update it by running `cargo gen-kinds`", error); + } + if let Err(error) = update(Path::new(AST), &render_template(AST_TEMPLATE, GRAMMAR).unwrap(), true) { + panic!("{}. Please update it by running `cargo gen-kinds`", error); + } } \ No newline at end of file -- cgit v1.2.3 From ce73df065f89bb5aa17517de16c10f9e4d3abaeb Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Mon, 15 Oct 2018 23:52:11 +0600 Subject: Use CARGO_MANIFEST_DIR for locating the grammar.ron file --- crates/tools/tests/cli.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/tools/tests') diff --git a/crates/tools/tests/cli.rs b/crates/tools/tests/cli.rs index 4d5b03b65..9ff1eecd9 100644 --- a/crates/tools/tests/cli.rs +++ b/crates/tools/tests/cli.rs @@ -3,7 +3,6 @@ extern crate tools; use std::path::Path; use tools::{render_template, update}; -const GRAMMAR: &str = "../ra_syntax/src/grammar.ron"; const SYNTAX_KINDS: &str = "../ra_syntax/src/syntax_kinds/generated.rs"; const SYNTAX_KINDS_TEMPLATE: &str = "../ra_syntax/src/syntax_kinds/generated.rs.tera"; const AST: &str = "../ra_syntax/src/ast/generated.rs"; @@ -11,10 +10,10 @@ const AST_TEMPLATE: &str = "../ra_syntax/src/ast/generated.rs.tera"; #[test] fn verify_template_generation() { - if let Err(error) = update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE, GRAMMAR).unwrap(), true) { + if let Err(error) = update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE).unwrap(), true) { panic!("{}. Please update it by running `cargo gen-kinds`", error); } - if let Err(error) = update(Path::new(AST), &render_template(AST_TEMPLATE, GRAMMAR).unwrap(), true) { + if let Err(error) = update(Path::new(AST), &render_template(AST_TEMPLATE).unwrap(), true) { panic!("{}. Please update it by running `cargo gen-kinds`", error); } -} \ No newline at end of file +} -- cgit v1.2.3 From 9d9e637ef39cbc00eaebad93294a60ccfd3405eb Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Tue, 16 Oct 2018 00:54:27 +0600 Subject: Refactor the constants --- crates/tools/tests/cli.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'crates/tools/tests') diff --git a/crates/tools/tests/cli.rs b/crates/tools/tests/cli.rs index 9ff1eecd9..d0ed60f7a 100644 --- a/crates/tools/tests/cli.rs +++ b/crates/tools/tests/cli.rs @@ -1,19 +1,13 @@ extern crate tools; -use std::path::Path; -use tools::{render_template, update}; - -const SYNTAX_KINDS: &str = "../ra_syntax/src/syntax_kinds/generated.rs"; -const SYNTAX_KINDS_TEMPLATE: &str = "../ra_syntax/src/syntax_kinds/generated.rs.tera"; -const AST: &str = "../ra_syntax/src/ast/generated.rs"; -const AST_TEMPLATE: &str = "../ra_syntax/src/ast/generated.rs.tera"; +use tools::{AST, AST_TEMPLATE, SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE, render_template, update, project_root}; #[test] fn verify_template_generation() { - if let Err(error) = update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE).unwrap(), true) { + if let Err(error) = update(&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(Path::new(AST), &render_template(AST_TEMPLATE).unwrap(), true) { + 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); } } -- cgit v1.2.3 From 2c4cfb297ec59625310023796b65e3dd48f1e76a Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Tue, 16 Oct 2018 15:36:53 +0600 Subject: take `&Path` instead of `PathBuf` --- crates/tools/tests/cli.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/tools/tests') diff --git a/crates/tools/tests/cli.rs b/crates/tools/tests/cli.rs index d0ed60f7a..f507d80a2 100644 --- a/crates/tools/tests/cli.rs +++ b/crates/tools/tests/cli.rs @@ -4,10 +4,10 @@ use tools::{AST, AST_TEMPLATE, SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE, render_templ #[test] fn verify_template_generation() { - if let Err(error) = update(&project_root().join(SYNTAX_KINDS), &render_template(project_root().join(SYNTAX_KINDS_TEMPLATE)).unwrap(), true) { + if let Err(error) = update(&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) { + 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); } } -- cgit v1.2.3