V0.16 - How to read environment variables from a test

So, I can read the environment variables using main in 0.16.

I want to read the environment variables in a test. How do I do that?

I have tests that check if the correct environment variables are loaded.

Reference PR: https://codeberg.org/ziglang/zig/pulls/30644

here is a tracking issue

9 Likes

If environment variable access is via values passed from main only, does this now imply that things such as a library specific log level env vars will need some sort of library init API that users of the lib need to call from the application main in order for the library to gain access to env vars?

Yes, isn’t that great? One less piece of global, hidden state to worry about.

21 Likes