forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

testutil.rs35 lines, 871 bytesHistoryRawDownload
1//! Helpers shared by the crate's tests.
2
3use std::path::{Path, PathBuf};
4
5/// A fresh scratch folder under the temp dir, removed when dropped, so a test that
6/// panics does not leave it behind either.
7pub struct TestDir(PathBuf);
8
9impl TestDir {
10 /// `<temp>/edith_mcp-test-<name>-<pid>`, emptied first.
11 pub fn new(name: &str) -> Self {
12 let path = std::env::temp_dir().join(format!("edith_mcp-test-{name}-{}", std::process::id()));
13 let _ = std::fs::remove_dir_all(&path);
14 std::fs::create_dir_all(&path).expect("create test dir");
15 Self(path)
16 }
17
18 pub fn path(&self) -> &Path {
19 &self.0
20 }
21}
22
23impl Drop for TestDir {
24 fn drop(&mut self) {
25 let _ = std::fs::remove_dir_all(&self.0);
26 }
27}
28
29impl std::ops::Deref for TestDir {
30 type Target = Path;
31
32 fn deref(&self) -> &Path {
33 &self.0
34 }
35}