aboutsummaryrefslogtreecommitdiff
path: root/crates/tools/src/lib.rs
diff options
context:
space:
mode:
authorCaio <[email protected]>2019-03-05 21:19:36 +0000
committerCaio <[email protected]>2019-03-05 21:19:36 +0000
commitcb60416cb59c87244a523bab464a265db7e58f04 (patch)
tree1a69e838817fcbdcd31b79d879e7a3c9f54226d9 /crates/tools/src/lib.rs
parentbbaf750b10810c21d42710a5d12181ca73099525 (diff)
Check installed extension
Diffstat (limited to 'crates/tools/src/lib.rs')
-rw-r--r--crates/tools/src/lib.rs36
1 files changed, 26 insertions, 10 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs
index 3c23ed76e..1e29c63d4 100644
--- a/crates/tools/src/lib.rs
+++ b/crates/tools/src/lib.rs
@@ -2,7 +2,7 @@ use std::{
2 fs, 2 fs,
3 collections::HashMap, 3 collections::HashMap,
4 path::{Path, PathBuf}, 4 path::{Path, PathBuf},
5 process::{Command, Stdio}, 5 process::{Command, Output, Stdio},
6 io::{Error, ErrorKind} 6 io::{Error, ErrorKind}
7}; 7};
8 8
@@ -80,15 +80,14 @@ pub fn project_root() -> PathBuf {
80} 80}
81 81
82pub fn run(cmdline: &str, dir: &str) -> Result<()> { 82pub fn run(cmdline: &str, dir: &str) -> Result<()> {
83 eprintln!("\nwill run: {}", cmdline); 83 do_run(cmdline, dir, |c| {
84 let project_dir = project_root().join(dir); 84 c.stdout(Stdio::inherit());
85 let mut args = cmdline.split_whitespace(); 85 })
86 let exec = args.next().unwrap(); 86 .map(|_| ())
87 let status = Command::new(exec).args(args).current_dir(project_dir).status()?; 87}
88 if !status.success() { 88
89 bail!("`{}` exited with {}", cmdline, status); 89pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> {
90 } 90 do_run(cmdline, dir, |_| {})
91 Ok(())
92} 91}
93 92
94pub fn run_rustfmt(mode: Mode) -> Result<()> { 93pub fn run_rustfmt(mode: Mode) -> Result<()> {
@@ -175,6 +174,23 @@ pub fn gen_tests(mode: Mode) -> Result<()> {
175 install_tests(&tests.err, ERR_INLINE_TESTS_DIR, mode) 174 install_tests(&tests.err, ERR_INLINE_TESTS_DIR, mode)
176} 175}
177 176
177fn do_run<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output>
178where
179 F: FnMut(&mut Command),
180{
181 eprintln!("\nwill run: {}", cmdline);
182 let proj_dir = project_root().join(dir);
183 let mut args = cmdline.split_whitespace();
184 let exec = args.next().unwrap();
185 let mut cmd = Command::new(exec);
186 f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit()));
187 let output = cmd.output()?;
188 if !output.status.success() {
189 bail!("`{}` exited with {}", cmdline, output.status);
190 }
191 Ok(output)
192}
193
178#[derive(Default, Debug)] 194#[derive(Default, Debug)]
179struct Tests { 195struct Tests {
180 pub ok: HashMap<String, Test>, 196 pub ok: HashMap<String, Test>,