Getting the relative path to a Dir? (feat. std.testing.tmpDir)

If I do this

test "File Stuff" {
    var tmpdir = std.testing.tmpDir(.{});
    defer tmpdir.cleanup();
    const root_dir = tmpdir.dir;
    try root_dir.makeDir("hello");
}

hello exists in $ZIG_LOCAL_CACHE_DIR/{tmpdir.sub_path}/hello

… or well, that’s where I expected it would go.

I tried doing process.getEnvVarOwned in the test block, and found out that tmpDir doesn’t respect the local cache location and instead hardcodes the path to $CWD/.zig-cache/tmp/...

I know the official advice is not to rely on realpath for various good reasons, but is there any other way I can get the path that won’t break when tmpDir gets fixed?

I’m not entirely sure what you are trying to accomplish here. Can you clarify what your end result is?

If you are wanting to “fix” it to do the expected behavior, you may want to copy the implementation of std.testing.tmpDir and update it to respect the variable. I think most other options will basically lead to this point.

Can you clarify what your end result is?

Write my tests such that they don’t break when tmpDir starts respecting the local cache directory and someone moves the cache.

you may want to copy the implementation of std.testing.tmpDir and update it to respect the variable. I think most other options will basically lead to this point

This is what I ended up doing