Skip to content

Commit eaf8a08

Browse files
committed
Allow multiple buildtests to share the same source crate
1 parent 5c579a5 commit eaf8a08

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ windows-sys = {version = "0.36.1", features = ["Win32_Foundation", "Win32_System
4949

5050
[dev-dependencies]
5151
env_logger = "0.8"
52+
rand = "0.8.5"
5253
tiny_http = "0.8.0"

tests/buildtest/runner.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use failure::Error;
2+
use rand::{distributions::Alphanumeric, Rng};
23
use rustwide::{cmd::SandboxBuilder, Build, BuildBuilder, Crate, Toolchain, Workspace};
34
use std::path::Path;
45

@@ -40,7 +41,16 @@ impl Runner {
4041
sandbox: SandboxBuilder,
4142
f: impl FnOnce(BuildBuilder) -> Result<T, Error>,
4243
) -> Result<T, Error> {
43-
let mut dir = self.workspace.build_dir(&self.crate_name);
44+
// Use a random string at the end to avoid conflicts if multiple tests use the same source crate.
45+
let suffix: String = rand::thread_rng()
46+
.sample_iter(&Alphanumeric)
47+
.take(10)
48+
.map(char::from)
49+
.collect();
50+
51+
let mut dir = self
52+
.workspace
53+
.build_dir(&format!("{}-{suffix}", &self.crate_name));
4454
dir.purge()?;
4555
f(dir.build(&self.toolchain, &self.krate, sandbox))
4656
}

0 commit comments

Comments
 (0)