diff --git a/folly/io/FsUtil.cpp b/folly/io/FsUtil.cpp index 734d6c0ac4b..b252a537dbf 100644 --- a/folly/io/FsUtil.cpp +++ b/folly/io/FsUtil.cpp @@ -24,6 +24,10 @@ #include // @manual #endif +#if defined(_WIN32) +#include +#endif + namespace bsys = ::boost::system; namespace folly { @@ -83,6 +87,10 @@ path executable_path() { auto data = const_cast(&*buf.data()); _NSGetExecutablePath(data, &size); return path(std::move(buf)); +#elif defined(_WIN32) + WCHAR buf[MAX_PATH]; + GetModuleFileNameW(NULL, buf, MAX_PATH); + return path(std::move(buf)); #else return read_symlink("/proc/self/exe"); #endif diff --git a/folly/io/test/FsUtilTest.cpp b/folly/io/test/FsUtilTest.cpp index f192eac5b2c..fb89528a827 100644 --- a/folly/io/test/FsUtilTest.cpp +++ b/folly/io/test/FsUtilTest.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using namespace folly; using namespace folly::fs; @@ -100,11 +101,11 @@ TEST(Simple, UniquePath) { constexpr auto tags = std::array{"foo", "bar", "baz", "cat", "dog", "bat", "rat", "tar", "bar"}; auto const model = join("-%%-", tags); - auto const match = testing::MatchesRegex(join("-[0-9a-f]{2}-", tags)); + auto const pattern = join("-[0-9a-f]{2}-", tags); std::unordered_set paths; for (size_t i = 0; i < size; ++i) { auto res = std_fs_unique_path(std_fs::path(model)).string(); - EXPECT_THAT(res, match); + EXPECT_PCRE_MATCH(pattern, res); paths.insert(std::move(res)); } EXPECT_EQ(size, paths.size()); @@ -112,11 +113,11 @@ TEST(Simple, UniquePath) { TEST(Simple, UniquePathDefaultModel) { constexpr auto size = size_t(1) << 10; - auto const match = testing::MatchesRegex("([0-9a-f]{4}-){3}[0-9a-f]{4}"); + auto const pattern = "([0-9a-f]{4}-){3}[0-9a-f]{4}"; std::unordered_set paths; for (size_t i = 0; i < size; ++i) { auto res = std_fs_unique_path().string(); - EXPECT_THAT(res, match); + EXPECT_PCRE_MATCH(pattern, res); paths.insert(std::move(res)); } EXPECT_EQ(size, paths.size()); diff --git a/folly/lang/test/ExceptionTest.cpp b/folly/lang/test/ExceptionTest.cpp index 266fe0f3498..aa4ec28f980 100644 --- a/folly/lang/test/ExceptionTest.cpp +++ b/folly/lang/test/ExceptionTest.cpp @@ -235,7 +235,14 @@ TEST_F(ExceptionTest, current_exception) { throw std::exception(); } catch (...) { // primary exception? +#if defined(_CPPLIB_VER) + // As per https://learn.microsoft.com/en-us/cpp/standard-library/exception-functions?view=msvc-170 + // current_exception() returns a new value each time, so its not directly comparable on MSVC + EXPECT_NE(nullptr, std::current_exception()); + EXPECT_NE(nullptr, folly::current_exception()); +#else EXPECT_EQ(std::current_exception(), folly::current_exception()); +#endif } try { throw std::exception(); @@ -244,7 +251,12 @@ TEST_F(ExceptionTest, current_exception) { throw; } catch (...) { // dependent exception? +#if defined(_CPPLIB_VER) + EXPECT_NE(nullptr, std::current_exception()); + EXPECT_NE(nullptr, folly::current_exception()); +#else EXPECT_EQ(std::current_exception(), folly::current_exception()); +#endif } } }