From 95c562138e52b645db2f2817bb12bc8448cd8894 Mon Sep 17 00:00:00 2001 From: Alex Hornby Date: Mon, 15 Jul 2024 11:29:24 -0700 Subject: [PATCH] fix github CI tests on windows Summary: These were [failing on github](https://github.com/facebook/folly/actions/runs/9923539772/job/27413784313#step:43:30071) * Fix use of regex in test in FsUtilTest.cpp * MSVC std::current_exception() exception_ptr return values are not comparable, was breaking ExceptionTest * Fix lookup of executable path on windows, which was breaking SSL test X-link: https://github.com/facebook/folly/pull/2256 Reviewed By: ndmitchell Differential Revision: D59751594 Pulled By: ahornby fbshipit-source-id: 6822abeb3ab73abd4643c2c680855f8f7ba61dbb --- third-party/folly/src/folly/io/FsUtil.cpp | 8 ++++++++ third-party/folly/src/folly/io/test/FsUtilTest.cpp | 9 +++++---- .../folly/src/folly/lang/test/ExceptionTest.cpp | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/third-party/folly/src/folly/io/FsUtil.cpp b/third-party/folly/src/folly/io/FsUtil.cpp index 734d6c0ac4ba5f..b252a537dbf95b 100644 --- a/third-party/folly/src/folly/io/FsUtil.cpp +++ b/third-party/folly/src/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/third-party/folly/src/folly/io/test/FsUtilTest.cpp b/third-party/folly/src/folly/io/test/FsUtilTest.cpp index f192eac5b2c6b5..fb89528a827e6c 100644 --- a/third-party/folly/src/folly/io/test/FsUtilTest.cpp +++ b/third-party/folly/src/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/third-party/folly/src/folly/lang/test/ExceptionTest.cpp b/third-party/folly/src/folly/lang/test/ExceptionTest.cpp index 266fe0f3498968..2cc67c984b764f 100644 --- a/third-party/folly/src/folly/lang/test/ExceptionTest.cpp +++ b/third-party/folly/src/folly/lang/test/ExceptionTest.cpp @@ -235,7 +235,16 @@ 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 +253,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 } } }