Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use random string for crate dir again #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ description = "Test harness for macro expansion"

[dependencies]
diff = "0.1"
fastrand = "2"
glob = "0.3"
prettyplease = "0.2"
serde = "1.0.105"
Expand Down
9 changes: 4 additions & 5 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::env;
use std::ffi::OsStr;
use std::fs;
use std::io::Write;
use std::iter;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};

use crate::cargo;
use crate::dependencies::{self, Dependency};
Expand Down Expand Up @@ -194,11 +194,10 @@ fn prepare(tests: &[ExpandedTest]) -> Result<Project> {
None => false,
};

static COUNT: AtomicUsize = AtomicUsize::new(0);
// Use unique string for the crate dir to
// Use random string for the crate dir to
// prevent conflicts when running parallel tests.
let unique_string: String = format!("macrotest{:03}", COUNT.fetch_add(1, Ordering::SeqCst));
let dir = path!(target_dir / "tests" / crate_name / unique_string);
let random_string: String = iter::repeat_with(fastrand::alphanumeric).take(42).collect();
let dir = path!(target_dir / "tests" / crate_name / random_string);
if dir.exists() {
// Remove remaining artifacts from previous runs if exist.
// For example, if the user stops the test with Ctrl-C during a previous
Expand Down