diff options
author | Aleksey Kladov <[email protected]> | 2018-07-31 13:40:40 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-07-31 13:40:40 +0100 |
commit | 9ce7e8110254e8db476c96bce2eecb2d16983159 (patch) | |
tree | abaddbafc4593948849394b430e3bde5c624fa22 /tools | |
parent | 2a2815266b35de12bd3c48cc405e8b3e8fcf8885 (diff) |
cleanups
Diffstat (limited to 'tools')
-rw-r--r-- | tools/src/lib.rs | 11 | ||||
-rw-r--r-- | tools/src/main.rs | 34 |
2 files changed, 29 insertions, 16 deletions
diff --git a/tools/src/lib.rs b/tools/src/lib.rs index 21a9468bc..5a7d846ff 100644 --- a/tools/src/lib.rs +++ b/tools/src/lib.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | extern crate itertools; | 1 | extern crate itertools; |
2 | 2 | ||
3 | use std::hash; | ||
4 | use itertools::Itertools; | 3 | use itertools::Itertools; |
4 | use std::hash; | ||
5 | 5 | ||
6 | #[derive(Debug)] | 6 | #[derive(Debug)] |
7 | pub struct Test { | 7 | pub struct Test { |
@@ -28,18 +28,17 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> { | |||
28 | match block.next() { | 28 | match block.next() { |
29 | Some((idx, line)) if line.starts_with("test ") => { | 29 | Some((idx, line)) if line.starts_with("test ") => { |
30 | break (idx, line["test ".len()..].to_string()) | 30 | break (idx, line["test ".len()..].to_string()) |
31 | }, | 31 | } |
32 | Some(_) => (), | 32 | Some(_) => (), |
33 | None => continue 'outer, | 33 | None => continue 'outer, |
34 | } | 34 | } |
35 | }; | 35 | }; |
36 | let text: String = itertools::join( | 36 | let text: String = itertools::join( |
37 | block.map(|(_, line)| line) | 37 | block.map(|(_, line)| line).chain(::std::iter::once("")), |
38 | .chain(::std::iter::once("")), | 38 | "\n", |
39 | "\n" | ||
40 | ); | 39 | ); |
41 | assert!(!text.trim().is_empty() && text.ends_with("\n")); | 40 | assert!(!text.trim().is_empty() && text.ends_with("\n")); |
42 | res.push((start_line, Test {name, text })) | 41 | res.push((start_line, Test { name, text })) |
43 | } | 42 | } |
44 | res | 43 | res |
45 | } | 44 | } |
diff --git a/tools/src/main.rs b/tools/src/main.rs index 3acb6e7ed..7c6c7a1aa 100644 --- a/tools/src/main.rs +++ b/tools/src/main.rs | |||
@@ -3,13 +3,17 @@ extern crate clap; | |||
3 | extern crate failure; | 3 | extern crate failure; |
4 | extern crate ron; | 4 | extern crate ron; |
5 | extern crate tera; | 5 | extern crate tera; |
6 | extern crate walkdir; | ||
7 | extern crate tools; | 6 | extern crate tools; |
7 | extern crate walkdir; | ||
8 | #[macro_use] | 8 | #[macro_use] |
9 | extern crate commandspec; | 9 | extern crate commandspec; |
10 | 10 | ||
11 | use std::{collections::{HashMap}, fs, path::{Path, PathBuf}}; | ||
12 | use clap::{App, Arg, SubCommand}; | 11 | use clap::{App, Arg, SubCommand}; |
12 | use std::{ | ||
13 | collections::HashMap, | ||
14 | fs, | ||
15 | path::{Path, PathBuf}, | ||
16 | }; | ||
13 | use tools::{collect_tests, Test}; | 17 | use tools::{collect_tests, Test}; |
14 | 18 | ||
15 | type Result<T> = ::std::result::Result<T, failure::Error>; | 19 | type Result<T> = ::std::result::Result<T, failure::Error>; |
@@ -71,7 +75,8 @@ fn get_kinds() -> Result<String> { | |||
71 | tera.add_raw_template("grammar", &template) | 75 | tera.add_raw_template("grammar", &template) |
72 | .map_err(|e| format_err!("template error: {:?}", e))?; | 76 | .map_err(|e| format_err!("template error: {:?}", e))?; |
73 | tera.register_global_function("concat", Box::new(concat)); | 77 | tera.register_global_function("concat", Box::new(concat)); |
74 | let ret = tera.render("grammar", &grammar) | 78 | let ret = tera |
79 | .render("grammar", &grammar) | ||
75 | .map_err(|e| format_err!("template error: {:?}", e))?; | 80 | .map_err(|e| format_err!("template error: {:?}", e))?; |
76 | return Ok(ret); | 81 | return Ok(ret); |
77 | 82 | ||
@@ -157,7 +162,10 @@ fn existing_tests(dir: &Path) -> Result<HashMap<String, (PathBuf, Test)>> { | |||
157 | file_name[5..file_name.len() - 3].to_string() | 162 | file_name[5..file_name.len() - 3].to_string() |
158 | }; | 163 | }; |
159 | let text = fs::read_to_string(&path)?; | 164 | let text = fs::read_to_string(&path)?; |
160 | let test = Test { name: name.clone(), text }; | 165 | let test = Test { |
166 | name: name.clone(), | ||
167 | text, | ||
168 | }; | ||
161 | match res.insert(name, (path, test)) { | 169 | match res.insert(name, (path, test)) { |
162 | Some(old) => println!("Duplicate test: {:?}", old), | 170 | Some(old) => println!("Duplicate test: {:?}", old), |
163 | None => (), | 171 | None => (), |
@@ -167,17 +175,23 @@ fn existing_tests(dir: &Path) -> Result<HashMap<String, (PathBuf, Test)>> { | |||
167 | } | 175 | } |
168 | 176 | ||
169 | fn install_code_extension() -> Result<()> { | 177 | fn install_code_extension() -> Result<()> { |
170 | execute!(r" | 178 | execute!( |
179 | r" | ||
171 | cd code | 180 | cd code |
172 | npm install | 181 | npm install |
173 | ")?; | 182 | " |
174 | execute!(r" | 183 | )?; |
184 | execute!( | ||
185 | r" | ||
175 | cd code | 186 | cd code |
176 | ./node_modules/vsce/out/vsce package | 187 | ./node_modules/vsce/out/vsce package |
177 | ")?; | 188 | " |
178 | execute!(r" | 189 | )?; |
190 | execute!( | ||
191 | r" | ||
179 | cd code | 192 | cd code |
180 | code --install-extension ./libsyntax-rust-0.0.1.vsix | 193 | code --install-extension ./libsyntax-rust-0.0.1.vsix |
181 | ")?; | 194 | " |
195 | )?; | ||
182 | Ok(()) | 196 | Ok(()) |
183 | } | 197 | } |