Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix github CI tests on windows #2256

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 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 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
12 changes: 12 additions & 0 deletions folly/lang/test/ExceptionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
}
}
}
Expand Down
Loading