Skip to content

Commit 592ae6b

Browse files
committed
Add process id to temp file name
1 parent 4fa79ee commit 592ae6b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/util.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
use std::fs::remove_file;
2-
use std::process::{Command, Output};
2+
use std::process::{self, Command, Output};
33

44
const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"];
55

6+
fn temp_file() -> String {
7+
format!("./temp_{}", process::id())
8+
}
9+
610
pub fn compile_test_cmd(filename: &str) -> Output {
711
Command::new("rustc")
8-
.args(&["--test", filename, "-o", "temp"])
12+
.args(&["--test", filename, "-o", &temp_file()])
913
.args(RUSTC_COLOR_ARGS)
1014
.output()
1115
.expect("failed to compile exercise")
1216
}
1317

1418
pub fn compile_cmd(filename: &str) -> Output {
1519
Command::new("rustc")
16-
.args(&[filename, "-o", "temp"])
20+
.args(&[filename, "-o", &temp_file()])
1721
.args(RUSTC_COLOR_ARGS)
1822
.output()
1923
.expect("failed to compile exercise")
2024
}
2125

2226
pub fn run_cmd() -> Output {
23-
Command::new("./temp")
27+
Command::new(&temp_file())
2428
.output()
2529
.expect("failed to run exercise")
2630
}
2731

2832
pub fn clean() {
29-
let _ignored = remove_file("temp");
33+
let _ignored = remove_file(&temp_file());
3034
}
3135

3236
#[test]
3337
fn test_clean() {
34-
std::fs::File::create("temp").unwrap();
38+
std::fs::File::create(&temp_file()).unwrap();
3539
clean();
36-
assert!(!std::path::Path::new("temp").exists());
40+
assert!(!std::path::Path::new(&temp_file()).exists());
3741
}

0 commit comments

Comments
 (0)