Skip to content

Passing Environment Variables that with multiple values fails #29

@kairohmer

Description

@kairohmer

I tried to set the PATH variable for the execution of my tests and noticed that only the first value is getting through if add more than one path. Here is a simple repro case:

add_test(
  NAME test_run   
  COMMAND test_executable
)
set_property(
  TEST test_run
  PROPERTY ENVIRONMENT
    "FOO=A;B;C"
    "BAR=D;E"
)

when getting the value of the variable using:

std::string get_environment(const char* env_var)
{
    std::string value;
    char* buf = nullptr;
    size_t sz = 0;
    if (_dupenv_s(&buf, &sz, env_var) == 0 && buf != NULL) {
        value = buf;
        free(buf);
    }
    return value;
}
...
std::cout << "FOO=" << get_environment("FOO").c_str() << std::endl;
std::cout << "BAR=" << get_environment("BAR").c_str() << std::endl;

I only get the first value. I.e.:
FOO=A
BAR=D

when setting the variable in the visual studio project settings of 'test_executable' and run the executable directly (not from Test Explorer), everything works as expected:
FOO=A;B;C
BAR=D;E

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions