mirror of
https://github.com/gabime/spdlog.git
synced 2025-04-29 03:53:54 +00:00
Added some tests for create_dir
This commit is contained in:
parent
bd92c23add
commit
c19e325b83
@ -34,10 +34,8 @@ SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
|
|||||||
|
|
||||||
for (int tries = 0; tries < open_tries_; ++tries)
|
for (int tries = 0; tries < open_tries_; ++tries)
|
||||||
{
|
{
|
||||||
if (!folder_name.empty())
|
// will not created if already exists or empty.
|
||||||
{
|
os::create_dir(folder_name);
|
||||||
os::create_dir(folder_name); // will not created if already exists
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!os::fopen_s(&fd_, fname, mode))
|
if (!os::fopen_s(&fd_, fname, mode))
|
||||||
{
|
{
|
||||||
|
@ -478,7 +478,7 @@ SPDLOG_INLINE bool mkdir_(const filename_t &path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the given directory - and all directories leading to it
|
// create the given directory - and all directories leading to it
|
||||||
// return true on success
|
// return true on success or if the directory already exists
|
||||||
SPDLOG_INLINE bool create_dir(filename_t path)
|
SPDLOG_INLINE bool create_dir(filename_t path)
|
||||||
{
|
{
|
||||||
if (path_exists(path))
|
if (path_exists(path))
|
||||||
@ -486,6 +486,11 @@ SPDLOG_INLINE bool create_dir(filename_t path)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(path.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// support forward slash in windows
|
// support forward slash in windows
|
||||||
std::replace(path.begin(), path.end(), '/', folder_sep);
|
std::replace(path.begin(), path.end(), '/', folder_sep);
|
||||||
|
@ -32,6 +32,14 @@ TEST_CASE("create_dir", "[create_dir]")
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("create_invalid_dir", "[create_dir]")
|
||||||
|
{
|
||||||
|
REQUIRE(create_dir("") == false);
|
||||||
|
#ifdef __linux__
|
||||||
|
REQUIRE(create_dir("/proc/spdlog-utest") == false);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("dir_name", "[create_dir]")
|
TEST_CASE("dir_name", "[create_dir]")
|
||||||
{
|
{
|
||||||
using spdlog::details::os::dir_name;
|
using spdlog::details::os::dir_name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user