franco pfp
franco
@francos.eth
Working on a CLI tool for Noir development that works with Nargo projects. Some of my tests create Nargo projects (e.i. `nargo new test`), move some files in them and create new ones, so I can test stuff. I'm getting race conditions because the tests are run in parallel. Is there an easy solution like "use this crate"?
1 reply
1 recast
3 reactions

agusti pfp
agusti
@bleu.eth
chatgpt says temple or assert_fs https://chatgpt.com/share/68643b12-6f3c-800c-b071-dc9e1cc61a7b
2 replies
0 recast
0 reaction

agusti pfp
agusti
@bleu.eth
tempfile* damn autocorrect
0 reply
0 recast
0 reaction

agusti pfp
agusti
@bleu.eth
Yes. The most straightforward solution is to isolate test environments using a crate that handles temporary directories safely and uniquely per test. ✅ Recommended Crate: tempfile tempfile creates temporary directories/files that are guaranteed to be unique and automatically cleaned up. It solves your race condition problem by ensuring each test runs in its own isolated nargo project directory. ⸻ 🧪 Usage Pattern use tempfile::TempDir; use std::process::Command; use std::fs; #[test] fn test_nargo_project_setup() { let temp_dir = TempDir::new().unwrap(); let project_path = temp_dir.path(); // create a new Nargo project inside the temp dir let status = Command::new("nargo") .arg("new") .arg("test_project") .current_dir(&project_path) .status() .expect("failed to run nargo new"); assert!(status.success()); let test_proj_dir = project_path.join("test_project"); // now you can move files or modify them safely in this isolated dir fs::write(test_proj_dir.join("src/main.nr"), "fn main() {}").unwrap(); } Each test uses a fresh unique directory under /tmp (or OS equivalent). Running them in parallel no longer causes collisions. ⸻ 🧩 Alternative: assert_fs If you want test assertion helpers + file creation API, use assert_fs. It’s higher-level and often more ergonomic for file-system test scaffolding: use assert_fs::prelude::*; use std::process::Command; #[test] fn test_nargo_in_fs() { let temp = assert_fs::TempDir::new().unwrap(); let status = Command::new("nargo") .arg("new") .arg("test_proj") .current_dir(&temp) .status() .unwrap(); assert!(status.success()); temp.child("test_proj").child("Nargo.toml").assert(predicates::path::exists()); } ⸻ 🧷 Summary Crate Purpose Use case tempfile Low-level unique temp file/dir General isolation, raw control over file layout assert_fs High-level FS testing API + isolation Tests that assert file presence, contents, structure Both are well-suited for your situation. Pick based on ergonomics. assert_fs also integrates well with predicates. Let me know if you want a macro-based helper or wrapper layer for test project creation.
1 reply
0 recast
0 reaction