diff options
Diffstat (limited to 'crates/tools')
-rw-r--r-- | crates/tools/src/bin/pre-commit.rs | 13 | ||||
-rw-r--r-- | crates/tools/src/lib.rs | 38 | ||||
-rw-r--r-- | crates/tools/src/main.rs | 10 | ||||
-rw-r--r-- | crates/tools/tests/cli.rs | 10 |
4 files changed, 14 insertions, 57 deletions
diff --git a/crates/tools/src/bin/pre-commit.rs b/crates/tools/src/bin/pre-commit.rs index e00bd0d3d..ea18c0863 100644 --- a/crates/tools/src/bin/pre-commit.rs +++ b/crates/tools/src/bin/pre-commit.rs | |||
@@ -19,19 +19,10 @@ fn update_staged() -> Result<()> { | |||
19 | .current_dir(&root) | 19 | .current_dir(&root) |
20 | .output()?; | 20 | .output()?; |
21 | if !output.status.success() { | 21 | if !output.status.success() { |
22 | bail!( | 22 | bail!("`git diff --diff-filter=MAR --name-only --cached` exited with {}", output.status); |
23 | "`git diff --diff-filter=MAR --name-only --cached` exited with {}", | ||
24 | output.status | ||
25 | ); | ||
26 | } | 23 | } |
27 | for line in String::from_utf8(output.stdout)?.lines() { | 24 | for line in String::from_utf8(output.stdout)?.lines() { |
28 | run( | 25 | run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; |
29 | &format!( | ||
30 | "git update-index --add {}", | ||
31 | root.join(line).to_string_lossy() | ||
32 | ), | ||
33 | ".", | ||
34 | )?; | ||
35 | } | 26 | } |
36 | Ok(()) | 27 | Ok(()) |
37 | } | 28 | } |
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 311bcb4d8..ef9c613a7 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs | |||
@@ -58,10 +58,8 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> { | |||
58 | None => continue 'outer, | 58 | None => continue 'outer, |
59 | } | 59 | } |
60 | }; | 60 | }; |
61 | let text: String = itertools::join( | 61 | let text: String = |
62 | block.map(|(_, line)| line).chain(::std::iter::once("")), | 62 | itertools::join(block.map(|(_, line)| line).chain(::std::iter::once("")), "\n"); |
63 | "\n", | ||
64 | ); | ||
65 | assert!(!text.trim().is_empty() && text.ends_with('\n')); | 63 | assert!(!text.trim().is_empty() && text.ends_with('\n')); |
66 | res.push((start_line, Test { name, text, ok })) | 64 | res.push((start_line, Test { name, text, ok })) |
67 | } | 65 | } |
@@ -78,11 +76,7 @@ pub fn generate(mode: Mode) -> Result<()> { | |||
78 | } | 76 | } |
79 | 77 | ||
80 | pub fn project_root() -> PathBuf { | 78 | pub fn project_root() -> PathBuf { |
81 | Path::new(&env!("CARGO_MANIFEST_DIR")) | 79 | Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf() |
82 | .ancestors() | ||
83 | .nth(2) | ||
84 | .unwrap() | ||
85 | .to_path_buf() | ||
86 | } | 80 | } |
87 | 81 | ||
88 | pub fn run(cmdline: &str, dir: &str) -> Result<()> { | 82 | pub fn run(cmdline: &str, dir: &str) -> Result<()> { |
@@ -90,10 +84,7 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> { | |||
90 | let project_dir = project_root().join(dir); | 84 | let project_dir = project_root().join(dir); |
91 | let mut args = cmdline.split_whitespace(); | 85 | let mut args = cmdline.split_whitespace(); |
92 | let exec = args.next().unwrap(); | 86 | let exec = args.next().unwrap(); |
93 | let status = Command::new(exec) | 87 | let status = Command::new(exec).args(args).current_dir(project_dir).status()?; |
94 | .args(args) | ||
95 | .current_dir(project_dir) | ||
96 | .status()?; | ||
97 | if !status.success() { | 88 | if !status.success() { |
98 | bail!("`{}` exited with {}", cmdline, status); | 89 | bail!("`{}` exited with {}", cmdline, status); |
99 | } | 90 | } |
@@ -112,10 +103,7 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { | |||
112 | }; | 103 | }; |
113 | 104 | ||
114 | if mode == Verify { | 105 | if mode == Verify { |
115 | run( | 106 | run(&format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), ".")?; |
116 | &format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), | ||
117 | ".", | ||
118 | )?; | ||
119 | } else { | 107 | } else { |
120 | run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?; | 108 | run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?; |
121 | } | 109 | } |
@@ -124,10 +112,7 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { | |||
124 | 112 | ||
125 | pub fn install_rustfmt() -> Result<()> { | 113 | pub fn install_rustfmt() -> Result<()> { |
126 | run(&format!("rustup install {}", TOOLCHAIN), ".")?; | 114 | run(&format!("rustup install {}", TOOLCHAIN), ".")?; |
127 | run( | 115 | run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".") |
128 | &format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), | ||
129 | ".", | ||
130 | ) | ||
131 | } | 116 | } |
132 | 117 | ||
133 | pub fn install_format_hook() -> Result<()> { | 118 | pub fn install_format_hook() -> Result<()> { |
@@ -156,10 +141,7 @@ pub fn run_fuzzer() -> Result<()> { | |||
156 | _ => run("cargo install cargo-fuzz", ".")?, | 141 | _ => run("cargo install cargo-fuzz", ".")?, |
157 | }; | 142 | }; |
158 | 143 | ||
159 | run( | 144 | run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") |
160 | "rustup run nightly -- cargo fuzz run parser", | ||
161 | "./crates/ra_syntax", | ||
162 | ) | ||
163 | } | 145 | } |
164 | 146 | ||
165 | pub fn gen_tests(mode: Mode) -> Result<()> { | 147 | pub fn gen_tests(mode: Mode) -> Result<()> { |
@@ -245,11 +227,7 @@ fn existing_tests(dir: &Path, ok: bool) -> Result<HashMap<String, (PathBuf, Test | |||
245 | file_name[5..file_name.len() - 3].to_string() | 227 | file_name[5..file_name.len() - 3].to_string() |
246 | }; | 228 | }; |
247 | let text = fs::read_to_string(&path)?; | 229 | let text = fs::read_to_string(&path)?; |
248 | let test = Test { | 230 | let test = Test { name: name.clone(), text, ok }; |
249 | name: name.clone(), | ||
250 | text, | ||
251 | ok, | ||
252 | }; | ||
253 | if let Some(old) = res.insert(name, (path, test)) { | 231 | if let Some(old) = res.insert(name, (path, test)) { |
254 | println!("Duplicate test: {:?}", old); | 232 | println!("Duplicate test: {:?}", old); |
255 | } | 233 | } |
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index c3e293911..963ffbe98 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs | |||
@@ -15,10 +15,7 @@ fn main() -> Result<()> { | |||
15 | .subcommand(SubCommand::with_name("format-hook")) | 15 | .subcommand(SubCommand::with_name("format-hook")) |
16 | .subcommand(SubCommand::with_name("fuzz-tests")) | 16 | .subcommand(SubCommand::with_name("fuzz-tests")) |
17 | .get_matches(); | 17 | .get_matches(); |
18 | match matches | 18 | match matches.subcommand_name().expect("Subcommand must be specified") { |
19 | .subcommand_name() | ||
20 | .expect("Subcommand must be specified") | ||
21 | { | ||
22 | "install-code" => install_code_extension()?, | 19 | "install-code" => install_code_extension()?, |
23 | "gen-tests" => gen_tests(Overwrite)?, | 20 | "gen-tests" => gen_tests(Overwrite)?, |
24 | "gen-syntax" => generate(Overwrite)?, | 21 | "gen-syntax" => generate(Overwrite)?, |
@@ -45,10 +42,7 @@ fn install_code_extension() -> Result<()> { | |||
45 | "./editors/code", | 42 | "./editors/code", |
46 | )?; | 43 | )?; |
47 | } else { | 44 | } else { |
48 | run( | 45 | run(r"code --install-extension ./ra-lsp-0.0.1.vsix --force", "./editors/code")?; |
49 | r"code --install-extension ./ra-lsp-0.0.1.vsix --force", | ||
50 | "./editors/code", | ||
51 | )?; | ||
52 | } | 46 | } |
53 | Ok(()) | 47 | Ok(()) |
54 | } | 48 | } |
diff --git a/crates/tools/tests/cli.rs b/crates/tools/tests/cli.rs index 2ee4b5223..aab52a4aa 100644 --- a/crates/tools/tests/cli.rs +++ b/crates/tools/tests/cli.rs | |||
@@ -10,19 +10,13 @@ fn generated_grammar_is_fresh() { | |||
10 | #[test] | 10 | #[test] |
11 | fn generated_tests_are_fresh() { | 11 | fn generated_tests_are_fresh() { |
12 | if let Err(error) = gen_tests(Verify) { | 12 | if let Err(error) = gen_tests(Verify) { |
13 | panic!( | 13 | panic!("{}. Please update tests by running `cargo gen-tests`", error); |
14 | "{}. Please update tests by running `cargo gen-tests`", | ||
15 | error | ||
16 | ); | ||
17 | } | 14 | } |
18 | } | 15 | } |
19 | 16 | ||
20 | #[test] | 17 | #[test] |
21 | fn check_code_formatting() { | 18 | fn check_code_formatting() { |
22 | if let Err(error) = run_rustfmt(Verify) { | 19 | if let Err(error) = run_rustfmt(Verify) { |
23 | panic!( | 20 | panic!("{}. Please format the code by running `cargo format`", error); |
24 | "{}. Please format the code by running `cargo format`", | ||
25 | error | ||
26 | ); | ||
27 | } | 21 | } |
28 | } | 22 | } |