Skip to content

Commit df73ffa

Browse files
committed
test: guard rotation test for C++11
1 parent e39efd7 commit df73ffa

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tests/file_logger_rotation_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@
22
#include <LogIt.hpp>
33
#include <fstream>
44
#include <string>
5+
#if __cplusplus >= 201703L
56
#include <filesystem>
7+
#endif
68

79
int main() {
810
LOGIT_ADD_FILE_LOGGER_WITH_ROTATION(".", true, 30, "%v", 20, 10);
911
const std::string msg = "0123456789"; // 10 bytes
1012
LOGIT_INFO(msg);
1113
LOGIT_INFO(msg);
1214
LOGIT_WAIT();
15+
#if __cplusplus >= 201703L
1316
std::filesystem::path current = LOGIT_GET_LAST_FILE_PATH(0);
1417
std::filesystem::path rotated = current;
1518
rotated.replace_filename(current.stem().string() + ".001.log");
1619
return std::filesystem::exists(rotated) ? 0 : 1;
20+
#else
21+
std::string current = LOGIT_GET_LAST_FILE_PATH(0);
22+
std::string rotated = current;
23+
size_t pos = rotated.rfind(".log");
24+
if (pos == std::string::npos) return 1;
25+
rotated.insert(pos, ".001");
26+
std::ifstream f(rotated.c_str());
27+
return f.good() ? 0 : 1;
28+
#endif
1729
}

0 commit comments

Comments
 (0)