Extract command builders into util

This commit is contained in:
Chris Pearce
2019-04-07 17:12:03 +01:00
parent fbd0ccbd5b
commit 4fa79ee02f
3 changed files with 41 additions and 26 deletions

View File

@@ -1,4 +1,29 @@
use std::fs::remove_file;
use std::process::{Command, Output};
const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"];
pub fn compile_test_cmd(filename: &str) -> Output {
Command::new("rustc")
.args(&["--test", filename, "-o", "temp"])
.args(RUSTC_COLOR_ARGS)
.output()
.expect("failed to compile exercise")
}
pub fn compile_cmd(filename: &str) -> Output {
Command::new("rustc")
.args(&[filename, "-o", "temp"])
.args(RUSTC_COLOR_ARGS)
.output()
.expect("failed to compile exercise")
}
pub fn run_cmd() -> Output {
Command::new("./temp")
.output()
.expect("failed to run exercise")
}
pub fn clean() {
let _ignored = remove_file("temp");