@@ -7,7 +7,6 @@ use std::fs;
77use std:: io:: { self , ErrorKind } ;
88use std:: path:: { Path , PathBuf } ;
99use std:: process:: Command ;
10- use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
1110use std:: sync:: Mutex ;
1211
1312static CARGO_INTEGRATION_TEST_DIR : & str = "cit" ;
@@ -60,19 +59,15 @@ pub fn global_root() -> PathBuf {
6059// [*] It does set the thread name, but only when running concurrently. If not
6160// running concurrently, all tests are run on the main thread.
6261thread_local ! {
63- static TEST_ID : RefCell <Option <usize >> = RefCell :: new( None ) ;
62+ static TEST_NAME : RefCell <Option <String >> = RefCell :: new( None ) ;
6463}
6564
6665pub struct TestIdGuard {
6766 _private : ( ) ,
6867}
6968
70- pub fn init_root ( tmp_dir : Option < & ' static str > ) -> TestIdGuard {
71- static NEXT_ID : AtomicUsize = AtomicUsize :: new ( 0 ) ;
72-
73- let id = NEXT_ID . fetch_add ( 1 , Ordering :: SeqCst ) ;
74- TEST_ID . with ( |n| * n. borrow_mut ( ) = Some ( id) ) ;
75-
69+ pub fn init_root ( tmp_dir : Option < & ' static str > , test_name : String ) -> TestIdGuard {
70+ TEST_NAME . with ( |n| * n. borrow_mut ( ) = Some ( test_name) ) ;
7671 let guard = TestIdGuard { _private : ( ) } ;
7772
7873 set_global_root ( tmp_dir) ;
@@ -85,20 +80,20 @@ pub fn init_root(tmp_dir: Option<&'static str>) -> TestIdGuard {
8580
8681impl Drop for TestIdGuard {
8782 fn drop ( & mut self ) {
88- TEST_ID . with ( |n| * n. borrow_mut ( ) = None ) ;
83+ TEST_NAME . with ( |n| * n. borrow_mut ( ) = None ) ;
8984 }
9085}
9186
9287pub fn root ( ) -> PathBuf {
93- let id = TEST_ID . with ( |n| {
94- n. borrow ( ) . expect (
88+ let test_name = TEST_NAME . with ( |n| {
89+ n. borrow ( ) . clone ( ) . expect (
9590 "Tests must use the `#[cargo_test]` attribute in \
9691 order to be able to use the crate root.",
9792 )
9893 } ) ;
9994
10095 let mut root = global_root ( ) ;
101- root. push ( & format ! ( "t{}" , id ) ) ;
96+ root. push ( test_name ) ;
10297 root
10398}
10499
0 commit comments