mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 09:31:34 +08:00
Tests: Fixed some clang-tidy warnings
This commit is contained in:
parent
887a104dd0
commit
dea6a7c217
@ -83,7 +83,9 @@ TEST_CASE("async_error_handler", "[errors]]")
|
||||
logger->set_error_handler([=](const std::string &) {
|
||||
std::ofstream ofs("logs/custom_err.txt");
|
||||
if (!ofs)
|
||||
{
|
||||
throw std::runtime_error("Failed open logs/custom_err.txt");
|
||||
}
|
||||
ofs << err_msg;
|
||||
});
|
||||
logger->info("Good message #1");
|
||||
|
@ -62,7 +62,9 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
|
||||
std::string basename = "logs/rotating_log";
|
||||
auto logger = spdlog::rotating_logger_mt("logger", basename, max_size, 1);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
|
||||
logger->flush();
|
||||
auto filename = basename;
|
||||
|
@ -20,9 +20,6 @@ TEST_CASE("custom eol", "[pattern_formatter]")
|
||||
{
|
||||
std::string msg = "Hello custom eol test";
|
||||
std::string eol = ";)";
|
||||
// auto formatter = std::make_shared<spdlog::pattern_formatter>("%v", spdlog::pattern_time_type::local, ";)");
|
||||
std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter("%v", spdlog::pattern_time_type::local, ";)"));
|
||||
|
||||
REQUIRE(log_to_str(msg, "%v", spdlog::pattern_time_type::local, ";)") == msg + eol);
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,15 @@ void prepare_logdir()
|
||||
system("del /F /Q logs\\*");
|
||||
#else
|
||||
auto rv = system("mkdir -p logs");
|
||||
if(rv != 0)
|
||||
{
|
||||
throw std::runtime_error("Failed to mkdir -p logs");
|
||||
}
|
||||
rv = system("rm -f logs/*");
|
||||
(void)rv;
|
||||
if(rv != 0)
|
||||
{
|
||||
throw std::runtime_error("Failed to rm -f logs/*");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -17,7 +24,9 @@ std::string file_contents(const std::string &filename)
|
||||
{
|
||||
std::ifstream ifs(filename);
|
||||
if (!ifs)
|
||||
{
|
||||
throw std::runtime_error("Failed open file ");
|
||||
}
|
||||
return std::string((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
|
||||
}
|
||||
|
||||
@ -25,7 +34,9 @@ std::size_t count_lines(const std::string &filename)
|
||||
{
|
||||
std::ifstream ifs(filename);
|
||||
if (!ifs)
|
||||
{
|
||||
throw std::runtime_error("Failed open file ");
|
||||
}
|
||||
|
||||
std::string line;
|
||||
size_t counter = 0;
|
||||
@ -38,7 +49,9 @@ std::size_t get_filesize(const std::string &filename)
|
||||
{
|
||||
std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary);
|
||||
if (!ifs)
|
||||
{
|
||||
throw std::runtime_error("Failed open file ");
|
||||
}
|
||||
|
||||
return static_cast<std::size_t>(ifs.tellg());
|
||||
}
|
||||
@ -47,6 +60,9 @@ std::size_t get_filesize(const std::string &filename)
|
||||
bool ends_with(std::string const &value, std::string const &ending)
|
||||
{
|
||||
if (ending.size() > value.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user