diff --git a/Cargo.toml b/Cargo.toml index e05df74..6f7fc60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,4 +49,5 @@ windows-sys = {version = "0.36.1", features = ["Win32_Foundation", "Win32_System [dev-dependencies] env_logger = "0.8" +rand = "0.8.5" tiny_http = "0.8.0" diff --git a/tests/buildtest/runner.rs b/tests/buildtest/runner.rs index 9750d9b..4beeb03 100644 --- a/tests/buildtest/runner.rs +++ b/tests/buildtest/runner.rs @@ -1,4 +1,5 @@ use failure::Error; +use rand::{distributions::Alphanumeric, Rng}; use rustwide::{cmd::SandboxBuilder, Build, BuildBuilder, Crate, Toolchain, Workspace}; use std::path::Path; @@ -40,7 +41,16 @@ impl Runner { sandbox: SandboxBuilder, f: impl FnOnce(BuildBuilder) -> Result, ) -> Result { - let mut dir = self.workspace.build_dir(&self.crate_name); + // Use a random string at the end to avoid conflicts if multiple tests use the same source crate. + let suffix: String = rand::thread_rng() + .sample_iter(&Alphanumeric) + .take(10) + .map(char::from) + .collect(); + + let mut dir = self + .workspace + .build_dir(&format!("{}-{suffix}", &self.crate_name)); dir.purge()?; f(dir.build(&self.toolchain, &self.krate, sandbox)) }