|
1 | 1 | use std::fs::remove_file;
|
2 |
| -use std::process::{Command, Output}; |
| 2 | +use std::process::{self, Command, Output}; |
3 | 3 |
|
4 | 4 | const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"];
|
5 | 5 |
|
| 6 | +fn temp_file() -> String { |
| 7 | + format!("./temp_{}", process::id()) |
| 8 | +} |
| 9 | + |
6 | 10 | pub fn compile_test_cmd(filename: &str) -> Output {
|
7 | 11 | Command::new("rustc")
|
8 |
| - .args(&["--test", filename, "-o", "temp"]) |
| 12 | + .args(&["--test", filename, "-o", &temp_file()]) |
9 | 13 | .args(RUSTC_COLOR_ARGS)
|
10 | 14 | .output()
|
11 | 15 | .expect("failed to compile exercise")
|
12 | 16 | }
|
13 | 17 |
|
14 | 18 | pub fn compile_cmd(filename: &str) -> Output {
|
15 | 19 | Command::new("rustc")
|
16 |
| - .args(&[filename, "-o", "temp"]) |
| 20 | + .args(&[filename, "-o", &temp_file()]) |
17 | 21 | .args(RUSTC_COLOR_ARGS)
|
18 | 22 | .output()
|
19 | 23 | .expect("failed to compile exercise")
|
20 | 24 | }
|
21 | 25 |
|
22 | 26 | pub fn run_cmd() -> Output {
|
23 |
| - Command::new("./temp") |
| 27 | + Command::new(&temp_file()) |
24 | 28 | .output()
|
25 | 29 | .expect("failed to run exercise")
|
26 | 30 | }
|
27 | 31 |
|
28 | 32 | pub fn clean() {
|
29 |
| - let _ignored = remove_file("temp"); |
| 33 | + let _ignored = remove_file(&temp_file()); |
30 | 34 | }
|
31 | 35 |
|
32 | 36 | #[test]
|
33 | 37 | fn test_clean() {
|
34 |
| - std::fs::File::create("temp").unwrap(); |
| 38 | + std::fs::File::create(&temp_file()).unwrap(); |
35 | 39 | clean();
|
36 |
| - assert!(!std::path::Path::new("temp").exists()); |
| 40 | + assert!(!std::path::Path::new(&temp_file()).exists()); |
37 | 41 | }
|
0 commit comments