Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove setEnvironmentVariable from the tests and use env::update(VAR, value) instead. #3037

Open
CAHEK7 opened this issue Jun 10, 2024 · 3 comments

Comments

@CAHEK7
Copy link
Contributor

CAHEK7 commented Jun 10, 2024

Based on #2837 (review)
setEnvironmentVariable should not be used in the tests, since it's an overkill and we don't need to update OS environment to get our internal state updated. setEnvironmentVariable was misused on early stage of gtest transition, it was before we've got special functions for proper internal state updating.
Now env::update(VAR, value) does exactly what we need.

@apwojcik
Copy link
Collaborator

My first attempt in #2837 was with env::update(), but that broke one definition rule, and I got clang-tidy errors. To make it work, we need to define all environment variables in a single source file and create an interface to import names into units where we need to work with values (DEFINE and DECLARE macros).

@apwojcik
Copy link
Collaborator

apwojcik commented Jun 12, 2024

Furthermore, the call to the setEnvironemntVariable function does not alter the OS environment variables. Environment variables set with it will only exist for the lifetime of a process. After the program terminates, all variables are removed from the caller's environment. That is because the setenv()/putenv() function on Linux and the SetEnvironmentVariable() function on Windows work only in the local environment.
To update the environment variables on Windows globally (OS level), one must update the Windows registry. On Linux, on the other hand, one needs to run a new shell instance with an updated variables list.

@CAHEK7
Copy link
Contributor Author

CAHEK7 commented Jun 12, 2024

In any case, it goes to OS for no reasons - with all those string names, reparsing and stuff, while we have to update just one global variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants