#include <folly/experimental/EnvUtil.h>
#include <boost/algorithm/string.hpp>
#include <folly/Memory.h>
#include <folly/Subprocess.h>
#include <folly/portability/Fcntl.h>
#include <folly/portability/GTest.h>
#include <folly/portability/Stdlib.h>
#include <glog/logging.h>
#include <spawn.h>
#include <system_error>
Go to the source code of this file.
|
| | DEFINE_string (env_util_subprocess_binary,"./env_util_subprocess","Location of the `env_util_subprocess` test helper program") |
| |
| | TEST (EnvVarSaverTest, ExampleNew) |
| |
| | TEST (EnvVarSaverTest, ExampleExisting) |
| |
| | TEST (EnvVarSaverTest, Movable) |
| |
| | TEST (EnvironmentStateTest, FailOnEmptyString) |
| |
| | TEST (EnvironmentStateTest, MovableAndCopyable) |
| |
| | TEST (EnvironmentStateTest, FailOnDuplicate) |
| |
| | TEST (EnvironmentStateTest, Separation) |
| |
| | TEST (EnvironmentStateTest, Update) |
| |
| | TEST (EnvironmentStateTest, forSubprocess) |
| |
| | TEST (EnvironmentStateTest, forC) |
| |
| | TEST (EnvVarSaverTest, ExampleDeleting) |
| |
| DEFINE_string |
( |
env_util_subprocess_binary |
, |
|
|
"./env_util_subprocess" |
, |
|
|
"Location of the `env_util_subprocess` test helper program" |
|
|
) |
| |
| TEST |
( |
EnvVarSaverTest |
, |
|
|
ExampleNew |
|
|
) |
| |
Definition at line 39 of file EnvUtilTest.cpp.
References EXPECT_EQ, and EXPECT_STREQ.
40 auto key =
"hahahahaha";
43 PCHECK(0 == setenv(key,
"",
true));
45 PCHECK(0 == unsetenv(key));
48 auto saver = std::make_unique<EnvVarSaver>();
49 PCHECK(0 == setenv(key,
"blah",
true));
#define EXPECT_EQ(val1, val2)
#define EXPECT_STREQ(s1, s2)
| TEST |
( |
EnvVarSaverTest |
, |
|
|
ExampleExisting |
|
|
) |
| |
Definition at line 67 of file EnvUtilTest.cpp.
References folly::Optional< Value >::clear(), folly::Optional< Value >::emplace(), EXPECT_EQ, EXPECT_NE, EXPECT_STREQ, folly::gen::move, string, and folly::value().
76 PCHECK(0 == setenv(key,
"blah",
true));
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
#define EXPECT_STREQ(s1, s2)
static const char *const value
Value & emplace(Args &&...args)
#define EXPECT_NE(val1, val2)
| TEST |
( |
EnvironmentStateTest |
, |
|
|
FailOnEmptyString |
|
|
) |
| |
Definition at line 82 of file EnvUtilTest.cpp.
References EXPECT_THROW.
85 PCHECK(0 == putenv(test));
86 auto okState = EnvironmentState::fromCurrentEnvironment();
#define EXPECT_THROW(statement, expected_exception)
| TEST |
( |
EnvironmentStateTest |
, |
|
|
MovableAndCopyable |
|
|
) |
| |
Definition at line 92 of file EnvUtilTest.cpp.
References folly::empty(), EXPECT_EQ, and folly::gen::move.
93 auto initialState = EnvironmentState::fromCurrentEnvironment();
95 copiedState1.operator=(initialState);
99 (*initialState)[
"foo"] =
"bar";
100 EXPECT_EQ(0, copiedState1->count(
"foo"));
101 EXPECT_EQ(0, copiedState2->count(
"foo"));
103 movedState1.operator=(
std::move(copiedState1));
107 initialState->erase(
"foo");
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
constexpr auto empty(C const &c) -> decltype(c.empty())
| TEST |
( |
EnvironmentStateTest |
, |
|
|
FailOnDuplicate |
|
|
) |
| |
Definition at line 112 of file EnvUtilTest.cpp.
References EXPECT_THROW.
114 char test[7] =
"PATG=B";
115 PCHECK(0 == putenv(test));
116 auto okState = EnvironmentState::fromCurrentEnvironment();
#define EXPECT_THROW(statement, expected_exception)
| TEST |
( |
EnvironmentStateTest |
, |
|
|
Separation |
|
|
) |
| |
Definition at line 122 of file EnvUtilTest.cpp.
References EXPECT_EQ, and EXPECT_STREQ.
124 auto initialState = EnvironmentState::fromCurrentEnvironment();
125 PCHECK(0 == setenv(
"spork",
"foon",
true));
126 auto updatedState = EnvironmentState::fromCurrentEnvironment();
127 EXPECT_EQ(0, initialState->count(
"spork"));
128 EXPECT_EQ(1, updatedState->count(
"spork"));
129 EXPECT_EQ(
"foon", (*updatedState)[
"spork"]);
130 updatedState->erase(
"spork");
131 EXPECT_EQ(0, updatedState->count(
"spork"));
#define EXPECT_EQ(val1, val2)
#define EXPECT_STREQ(s1, s2)
| TEST |
( |
EnvironmentStateTest |
, |
|
|
Update |
|
|
) |
| |
Definition at line 135 of file EnvUtilTest.cpp.
References EXPECT_EQ, and EXPECT_STREQ.
137 auto env = EnvironmentState::fromCurrentEnvironment();
139 (*env)[
"spork"] =
"foon";
141 env.setAsCurrentEnvironment();
#define EXPECT_EQ(val1, val2)
#define EXPECT_STREQ(s1, s2)
| TEST |
( |
EnvironmentStateTest |
, |
|
|
forSubprocess |
|
|
) |
| |
Definition at line 145 of file EnvUtilTest.cpp.
References folly::empty(), and EXPECT_EQ.
147 (*env)[
"spork"] =
"foon";
148 std::vector<std::string> expected = {
"spork=foon"};
149 auto vec = env.toVector();
151 Subprocess subProcess{{fLS::FLAGS_env_util_subprocess_binary},
153 fLS::FLAGS_env_util_subprocess_binary.c_str(),
155 EXPECT_EQ(0, subProcess.wait().exitStatus());
#define EXPECT_EQ(val1, val2)
constexpr auto empty(C const &c) -> decltype(c.empty())
| TEST |
( |
EnvironmentStateTest |
, |
|
|
forC |
|
|
) |
| |
Definition at line 158 of file EnvUtilTest.cpp.
References folly::empty(), EXPECT_EQ, and EXPECT_STREQ.
160 (*env)[
"spork"] =
"foon";
161 EXPECT_STREQ(
"spork=foon", env.toPointerArray().get()[0]);
162 EXPECT_EQ(
nullptr, env.toPointerArray().get()[1]);
163 char const* program = fLS::FLAGS_env_util_subprocess_binary.c_str();
173 env.toPointerArray().get()));
175 PCHECK(pid == waitpid(pid, &result, 0));
#define EXPECT_EQ(val1, val2)
#define EXPECT_STREQ(s1, s2)
constexpr auto empty(C const &c) -> decltype(c.empty())
| TEST |
( |
EnvVarSaverTest |
, |
|
|
ExampleDeleting |
|
|
) |
| |