1 #![warn(rust_2018_idioms)] 2 #![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations 3 4 use tempfile::tempdir; 5 use tokio::fs; 6 7 #[tokio::test] rename_file()8async fn rename_file() { 9 let temp_dir = tempdir().unwrap(); 10 11 let file_path = temp_dir.path().join("a.txt"); 12 13 fs::write(&file_path, b"Hello File!").await.unwrap(); 14 15 assert!(fs::try_exists(&file_path).await.unwrap()); 16 17 let new_file_path = temp_dir.path().join("b.txt"); 18 19 fs::rename(&file_path, &new_file_path).await.unwrap(); 20 21 assert!(fs::try_exists(new_file_path).await.unwrap()); 22 23 // original file should no longer exist 24 match fs::try_exists(file_path).await { 25 Ok(exists) => assert!(!exists), 26 Err(_) => println!("ignored try_exists error after rename"), 27 }; 28 } 29