experimental/DynamicParser-inl.h \
experimental/ExecutionObserver.h \
experimental/EliasFanoCoding.h \
+ experimental/EnvUtil.h \
experimental/EventCount.h \
experimental/Instructions.h \
experimental/bser/Bser.h \
experimental/bser/Dump.cpp \
experimental/bser/Load.cpp \
experimental/DynamicParser.cpp \
+ experimental/EnvUtil.cpp
experimental/FunctionScheduler.cpp \
experimental/io/FsUtil.cpp \
experimental/JemallocNodumpAllocator.cpp \
--- /dev/null
+/*
+ * Copyright 2017 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <folly/experimental/EnvUtil.h>
+
+#include <folly/String.h>
+#include <folly/portability/Stdlib.h>
+#include <folly/portability/Unistd.h>
+
+namespace folly {
+namespace test {
+
+static std::map<std::string, std::string> getEnvVarMap() {
+ std::map<std::string, std::string> data;
+ for (auto it = environ; *it != nullptr; ++it) {
+ std::string key, value;
+ split("=", *it, key, value);
+ if (key.empty()) {
+ continue;
+ }
+ CHECK(!data.count(key)) << "already contains: " << key;
+ data.emplace(move(key), move(value));
+ }
+ return data;
+}
+
+EnvVarSaver::EnvVarSaver() {
+ saved_ = getEnvVarMap();
+}
+
+EnvVarSaver::~EnvVarSaver() {
+ for (const auto& kvp : getEnvVarMap()) {
+ if (saved_.count(kvp.first)) {
+ continue;
+ }
+ PCHECK(0 == unsetenv(kvp.first.c_str()));
+ }
+ for (const auto& kvp : saved_) {
+ PCHECK(0 == setenv(kvp.first.c_str(), kvp.second.c_str(), (int)true));
+ }
+}
+}
+}
--- /dev/null
+/*
+ * Copyright 2017 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <map>
+#include <string>
+
+namespace folly {
+namespace test {
+
+class EnvVarSaver {
+ public:
+ EnvVarSaver();
+ ~EnvVarSaver();
+
+ private:
+ std::map<std::string, std::string> saved_;
+};
+}
+}
#include <sys/stat.h>
#include <boost/regex.hpp>
-#include <folly/Conv.h>
#include <folly/Exception.h>
#include <folly/File.h>
#include <folly/FileUtil.h>
#include <folly/Memory.h>
#include <folly/String.h>
#include <folly/portability/Fcntl.h>
-#include <folly/portability/Stdlib.h>
-#include <folly/portability/Unistd.h>
#ifdef _WIN32
#include <crtdbg.h>
return std::string(buf.get(), size);
}
-static std::map<std::string, std::string> getEnvVarMap() {
- std::map<std::string, std::string> data;
- for (auto it = environ; *it != nullptr; ++it) {
- std::string key, value;
- split("=", *it, key, value);
- if (key.empty()) {
- continue;
- }
- CHECK(!data.count(key)) << "already contains: " << key;
- data.emplace(move(key), move(value));
- }
- return data;
-}
-
-EnvVarSaver::EnvVarSaver() {
- saved_ = getEnvVarMap();
-}
-
-EnvVarSaver::~EnvVarSaver() {
- for (const auto& kvp : getEnvVarMap()) {
- if (saved_.count(kvp.first)) {
- continue;
- }
- PCHECK(0 == unsetenv(kvp.first.c_str()));
- }
- for (const auto& kvp : saved_) {
- PCHECK(0 == setenv(kvp.first.c_str(), kvp.second.c_str(), (int)true));
- }
-}
-
} // namespace test
} // namespace folly
off_t readOffset_; // for incremental reading
};
-class EnvVarSaver {
-public:
- EnvVarSaver();
- ~EnvVarSaver();
-private:
- std::map<std::string, std::string> saved_;
-};
-
} // namespace test
} // namespace folly
--- /dev/null
+/*
+ * Copyright 2017 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <folly/experimental/EnvUtil.h>
+
+#include <system_error>
+
+#include <boost/algorithm/string.hpp>
+#include <glog/logging.h>
+
+#include <folly/Memory.h>
+#include <folly/portability/Fcntl.h>
+#include <folly/portability/GTest.h>
+#include <folly/portability/Stdlib.h>
+
+using namespace folly;
+using namespace folly::test;
+
+class EnvVarSaverTest : public testing::Test {};
+
+TEST_F(EnvVarSaverTest, ExampleNew) {
+ auto key = "hahahahaha";
+ EXPECT_EQ(nullptr, getenv(key));
+
+ PCHECK(0 == setenv(key, "", true));
+ EXPECT_STREQ("", getenv(key));
+ PCHECK(0 == unsetenv(key));
+ EXPECT_EQ(nullptr, getenv(key));
+
+ auto saver = make_unique<EnvVarSaver>();
+ PCHECK(0 == setenv(key, "blah", true));
+ EXPECT_EQ("blah", std::string{getenv(key)});
+ saver = nullptr;
+ EXPECT_EQ(nullptr, getenv(key));
+}
+
+TEST_F(EnvVarSaverTest, ExampleExisting) {
+ auto key = "PATH";
+ EXPECT_NE(nullptr, getenv(key));
+ auto value = std::string{getenv(key)};
+
+ auto saver = make_unique<EnvVarSaver>();
+ PCHECK(0 == setenv(key, "blah", true));
+ EXPECT_EQ("blah", std::string{getenv(key)});
+ saver = nullptr;
+ EXPECT_TRUE(value == getenv(key));
+}
+
+TEST_F(EnvVarSaverTest, ExampleDeleting) {
+ auto key = "PATH";
+ EXPECT_NE(nullptr, getenv(key));
+ auto value = std::string{getenv(key)};
+
+ auto saver = make_unique<EnvVarSaver>();
+ PCHECK(0 == unsetenv(key));
+ EXPECT_EQ(nullptr, getenv(key));
+ saver = nullptr;
+ EXPECT_TRUE(value == getenv(key));
+}
}
EXPECT_EQ(2, chunks.size());
}
-
-
-class EnvVarSaverTest : public testing::Test {};
-
-TEST_F(EnvVarSaverTest, ExampleNew) {
- auto key = "hahahahaha";
- EXPECT_EQ(nullptr, getenv(key));
-
- PCHECK(0 == setenv(key, "", true));
- EXPECT_STREQ("", getenv(key));
- PCHECK(0 == unsetenv(key));
- EXPECT_EQ(nullptr, getenv(key));
-
- auto saver = make_unique<EnvVarSaver>();
- PCHECK(0 == setenv(key, "blah", true));
- EXPECT_EQ("blah", std::string{getenv(key)});
- saver = nullptr;
- EXPECT_EQ(nullptr, getenv(key));
-}
-
-TEST_F(EnvVarSaverTest, ExampleExisting) {
- auto key = "PATH";
- EXPECT_NE(nullptr, getenv(key));
- auto value = std::string{getenv(key)};
-
- auto saver = make_unique<EnvVarSaver>();
- PCHECK(0 == setenv(key, "blah", true));
- EXPECT_EQ("blah", std::string{getenv(key)});
- saver = nullptr;
- EXPECT_TRUE(value == getenv(key));
-}
-
-TEST_F(EnvVarSaverTest, ExampleDeleting) {
- auto key = "PATH";
- EXPECT_NE(nullptr, getenv(key));
- auto value = std::string{getenv(key)};
-
- auto saver = make_unique<EnvVarSaver>();
- PCHECK(0 == unsetenv(key));
- EXPECT_EQ(nullptr, getenv(key));
- saver = nullptr;
- EXPECT_TRUE(value == getenv(key));
-}
-
-int main(int argc, char *argv[]) {
- testing::InitGoogleTest(&argc, argv);
- gflags::ParseCommandLineFlags(&argc, &argv, true);
- return RUN_ALL_TESTS();
-}