19 #include <boost/algorithm/string.hpp> 25 #include <glog/logging.h> 27 #include <system_error> 29 using namespace folly;
35 env_util_subprocess_binary,
36 "./env_util_subprocess",
37 "Location of the `env_util_subprocess` test helper program");
39 TEST(EnvVarSaverTest, ExampleNew) {
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));
55 TEST(EnvVarSaverTest, ExampleExisting) {
60 auto saver = std::make_unique<EnvVarSaver>();
61 PCHECK(0 == setenv(key,
"blah",
true));
76 PCHECK(0 == setenv(key,
"blah",
true));
82 TEST(EnvironmentStateTest, FailOnEmptyString) {
85 PCHECK(0 == putenv(test));
86 auto okState = EnvironmentState::fromCurrentEnvironment();
92 TEST(EnvironmentStateTest, MovableAndCopyable) {
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");
112 TEST(EnvironmentStateTest, FailOnDuplicate) {
114 char test[7] =
"PATG=B";
115 PCHECK(0 == putenv(test));
116 auto okState = EnvironmentState::fromCurrentEnvironment();
122 TEST(EnvironmentStateTest, Separation) {
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"));
135 TEST(EnvironmentStateTest, Update) {
137 auto env = EnvironmentState::fromCurrentEnvironment();
139 (*env)[
"spork"] =
"foon";
141 env.setAsCurrentEnvironment();
145 TEST(EnvironmentStateTest, forSubprocess) {
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());
158 TEST(EnvironmentStateTest, forC) {
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));
179 TEST(EnvVarSaverTest, ExampleDeleting) {
184 auto saver = std::make_unique<EnvVarSaver>();
185 PCHECK(0 == unsetenv(key));
#define EXPECT_THROW(statement, expected_exception)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
#define EXPECT_STREQ(s1, s2)
constexpr auto empty(C const &c) -> decltype(c.empty())
Value & emplace(Args &&...args)
DEFINE_string(env_util_subprocess_binary,"./env_util_subprocess","Location of the `env_util_subprocess` test helper program")
#define EXPECT_TRUE(condition)
#define EXPECT_NE(val1, val2)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
TEST(SequencedExecutor, CPUThreadPoolExecutor)