#How to get a path from `std.testing.tmpDir()`?

1 messages · Page 1 of 1 (latest)

rich matrix
#

When testing an application that uses libgit2, the path string is required to initialize a repository in the unit tests. Using CWD is fragile because it could be inside a nix derivation sandbox. I was hoping to the the path created by the function, or reference tempfs but am having difficulties achieving that with zig 0.16 🙂
Any help?

shy ridge
#

Getting a path from a Dir is actually a bit tricky because platforms can handle it very differently (and some platforms such as WASM don't really allow it AFAIK). You can use the realPath functions on the dir field of the TmpDir, although those only work on certain platforms so are a bit discouraged depending on how portable you're trying to be. Not sure how it would interact with Nix since I don't use that personally.