forked from rust-lang/rustlings
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,41 @@ | ||
use std::fs::remove_file; | ||
use std::process::{Command, Output}; | ||
use std::process::{self, Command, Output}; | ||
|
||
const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"]; | ||
|
||
fn temp_file() -> String { | ||
format!("./temp_{}", process::id()) | ||
} | ||
|
||
pub fn compile_test_cmd(filename: &str) -> Output { | ||
Command::new("rustc") | ||
.args(&["--test", filename, "-o", "temp"]) | ||
.args(&["--test", filename, "-o", &temp_file()]) | ||
.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(&[filename, "-o", &temp_file()]) | ||
.args(RUSTC_COLOR_ARGS) | ||
.output() | ||
.expect("failed to compile exercise") | ||
} | ||
|
||
pub fn run_cmd() -> Output { | ||
Command::new("./temp") | ||
Command::new(&temp_file()) | ||
.output() | ||
.expect("failed to run exercise") | ||
} | ||
|
||
pub fn clean() { | ||
let _ignored = remove_file("temp"); | ||
let _ignored = remove_file(&temp_file()); | ||
} | ||
|
||
#[test] | ||
fn test_clean() { | ||
std::fs::File::create("temp").unwrap(); | ||
std::fs::File::create(&temp_file()).unwrap(); | ||
clean(); | ||
assert!(!std::path::Path::new("temp").exists()); | ||
assert!(!std::path::Path::new(&temp_file()).exists()); | ||
} |