From 613f33999c284ef85bcaec75ae981972566c9e9e Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 1 Feb 2025 15:39:15 +0900 Subject: [PATCH] Use random string for crate dir again --- Cargo.toml | 1 + src/expand.rs | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b961eb..c40584a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/expand.rs b/src/expand.rs index 0800e94..8b22425 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -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}; @@ -194,11 +194,10 @@ fn prepare(tests: &[ExpandedTest]) -> Result { 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