| Crates.io | littertray |
| lib.rs | littertray |
| version | 0.2.1 |
| created_at | 2025-05-24 05:22:23.477491+00 |
| updated_at | 2025-08-23 10:05:47.111831+00 |
| description | Lightweight sandboxing for tests that write to the filesystem |
| homepage | |
| repository | https://github.com/crazyscot/littertray/ |
| max_upload_size | |
| id | 1687036 |
| size | 60,778 |
Lightweight sandboxing for tests that write to the filesystem
This is little more than a convenience wrapper to
tempdir::TempDir.
You provide a closure that runs in the sandbox; there are convenience methods to create files, directories and so forth.
Crucially, the crate changes working directory into the sandbox while it is active. This allows the unit under test to read and write files into the sandbox, provided they are expressed as relative paths.
When the struct is dropped, the tempdir is cleaned up.
This crate is inspired by and is a derivative work of figment::Jail.
Differences:
use littertray::LitterTray;
let result = LitterTray::try_with(|tray| {
let _ = tray.create_text("test.txt", "Hello, world!")?;
assert_eq!(std::fs::read_to_string("test.txt")?, "Hello, world!");
Ok(())
}).unwrap();
This is how you'd do something similar with an async closure:
use littertray::LitterTray;
let result = LitterTray::try_with_async(async |tray| {
let _ = tray.create_text("test.txt", "Hello, world!")?;
assert_eq!(
tokio::fs::read_to_string("test.txt").await.unwrap(),
"Hello, world!"
);
Ok(())
})
.await
.unwrap();
rusty-fork or similar.