Skip to content

Commit

Permalink
fix github CI tests on windows
Browse files Browse the repository at this point in the history
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: facebook/folly#2256

Reviewed By: ndmitchell

Differential Revision: D59751594

Pulled By: ahornby

fbshipit-source-id: 6822abeb3ab73abd4643c2c680855f8f7ba61dbb
  • Loading branch information
ahornby authored and facebook-github-bot committed Jul 15, 2024
1 parent a1863c5 commit 95c5621
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions third-party/folly/src/folly/io/FsUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include <mach-o/dyld.h> // @manual
#endif

#if defined(_WIN32)
#include <folly/portability/Windows.h>
#endif

namespace bsys = ::boost::system;

namespace folly {
Expand Down Expand Up @@ -83,6 +87,10 @@ path executable_path() {
auto data = const_cast<char*>(&*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
Expand Down
9 changes: 5 additions & 4 deletions third-party/folly/src/folly/io/test/FsUtilTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <folly/String.h>
#include <folly/portability/GMock.h>
#include <folly/portability/GTest.h>
#include <folly/testing/TestUtil.h>

using namespace folly;
using namespace folly::fs;
Expand Down Expand Up @@ -100,23 +101,23 @@ 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<std::string> 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());
}

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<std::string> 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());
Expand Down
14 changes: 14 additions & 0 deletions third-party/folly/src/folly/lang/test/ExceptionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit 95c5621

Please sign in to comment.