aboutsummaryrefslogtreecommitdiff
path: root/tools/src
diff options
context:
space:
mode:
Diffstat (limited to 'tools/src')
-rw-r--r--tools/src/lib.rs11
-rw-r--r--tools/src/main.rs34
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 @@
1extern crate itertools; 1extern crate itertools;
2 2
3use std::hash;
4use itertools::Itertools; 3use itertools::Itertools;
4use std::hash;
5 5
6#[derive(Debug)] 6#[derive(Debug)]
7pub struct Test { 7pub 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;
3extern crate failure; 3extern crate failure;
4extern crate ron; 4extern crate ron;
5extern crate tera; 5extern crate tera;
6extern crate walkdir;
7extern crate tools; 6extern crate tools;
7extern crate walkdir;
8#[macro_use] 8#[macro_use]
9extern crate commandspec; 9extern crate commandspec;
10 10
11use std::{collections::{HashMap}, fs, path::{Path, PathBuf}};
12use clap::{App, Arg, SubCommand}; 11use clap::{App, Arg, SubCommand};
12use std::{
13 collections::HashMap,
14 fs,
15 path::{Path, PathBuf},
16};
13use tools::{collect_tests, Test}; 17use tools::{collect_tests, Test};
14 18
15type Result<T> = ::std::result::Result<T, failure::Error>; 19type 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
169fn install_code_extension() -> Result<()> { 177fn install_code_extension() -> Result<()> {
170 execute!(r" 178 execute!(
179 r"
171cd code 180cd code
172npm install 181npm install
173 ")?; 182 "
174 execute!(r" 183 )?;
184 execute!(
185 r"
175cd code 186cd 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"
179cd code 192cd code
180code --install-extension ./libsyntax-rust-0.0.1.vsix 193code --install-extension ./libsyntax-rust-0.0.1.vsix
181 ")?; 194 "
195 )?;
182 Ok(()) 196 Ok(())
183} 197}