Skip to content

Commit

Permalink
Allow multiple buildtests to share the same source crate
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Apr 14, 2023
1 parent 5c579a5 commit eaf8a08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 11 additions & 1 deletion tests/buildtest/runner.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -40,7 +41,16 @@ impl Runner {
sandbox: SandboxBuilder,
f: impl FnOnce(BuildBuilder) -> Result<T, Error>,
) -> Result<T, Error> {
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))
}
Expand Down

0 comments on commit eaf8a08

Please sign in to comment.