mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-25 00:00:05 +03:00
Add process id to temp file name
This commit is contained in:
parent
4fa79ee02f
commit
592ae6b4d2
18
src/util.rs
18
src/util.rs
|
@ -1,11 +1,15 @@
|
||||||
use std::fs::remove_file;
|
use std::fs::remove_file;
|
||||||
use std::process::{Command, Output};
|
use std::process::{self, Command, Output};
|
||||||
|
|
||||||
const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"];
|
const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"];
|
||||||
|
|
||||||
|
fn temp_file() -> String {
|
||||||
|
format!("./temp_{}", process::id())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn compile_test_cmd(filename: &str) -> Output {
|
pub fn compile_test_cmd(filename: &str) -> Output {
|
||||||
Command::new("rustc")
|
Command::new("rustc")
|
||||||
.args(&["--test", filename, "-o", "temp"])
|
.args(&["--test", filename, "-o", &temp_file()])
|
||||||
.args(RUSTC_COLOR_ARGS)
|
.args(RUSTC_COLOR_ARGS)
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to compile exercise")
|
.expect("failed to compile exercise")
|
||||||
|
@ -13,25 +17,25 @@ pub fn compile_test_cmd(filename: &str) -> Output {
|
||||||
|
|
||||||
pub fn compile_cmd(filename: &str) -> Output {
|
pub fn compile_cmd(filename: &str) -> Output {
|
||||||
Command::new("rustc")
|
Command::new("rustc")
|
||||||
.args(&[filename, "-o", "temp"])
|
.args(&[filename, "-o", &temp_file()])
|
||||||
.args(RUSTC_COLOR_ARGS)
|
.args(RUSTC_COLOR_ARGS)
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to compile exercise")
|
.expect("failed to compile exercise")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_cmd() -> Output {
|
pub fn run_cmd() -> Output {
|
||||||
Command::new("./temp")
|
Command::new(&temp_file())
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to run exercise")
|
.expect("failed to run exercise")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clean() {
|
pub fn clean() {
|
||||||
let _ignored = remove_file("temp");
|
let _ignored = remove_file(&temp_file());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clean() {
|
fn test_clean() {
|
||||||
std::fs::File::create("temp").unwrap();
|
std::fs::File::create(&temp_file()).unwrap();
|
||||||
clean();
|
clean();
|
||||||
assert!(!std::path::Path::new("temp").exists());
|
assert!(!std::path::Path::new(&temp_file()).exists());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue