| 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 ] |
| 8 | async fn remove_dir_all() { |
| 9 | let temp_dir = tempdir().unwrap(); |
| 10 | |
| 11 | let test_dir = temp_dir.path().join("test" ); |
| 12 | fs::create_dir(&test_dir).await.unwrap(); |
| 13 | |
| 14 | let file_path = test_dir.as_path().join("a.txt" ); |
| 15 | |
| 16 | fs::write(&file_path, b"Hello File!" ).await.unwrap(); |
| 17 | |
| 18 | fs::remove_dir_all(test_dir.as_path()).await.unwrap(); |
| 19 | |
| 20 | // test dir should no longer exist |
| 21 | match fs::try_exists(test_dir).await { |
| 22 | Ok(exists) => assert!(!exists), |
| 23 | Err(_) => println!("ignored try_exists error after remove_dir_all" ), |
| 24 | }; |
| 25 | |
| 26 | // contents should no longer exist |
| 27 | match fs::try_exists(file_path).await { |
| 28 | Ok(exists) => assert!(!exists), |
| 29 | Err(_) => println!("ignored try_exists error after remove_dir_all" ), |
| 30 | }; |
| 31 | } |
| 32 | |