Tests: Fixed some clang-tidy warnings

This commit is contained in:
gabime 2018-10-05 15:20:14 +03:00
parent 887a104dd0
commit dea6a7c217
4 changed files with 21 additions and 4 deletions

View File

@ -83,7 +83,9 @@ TEST_CASE("async_error_handler", "[errors]]")
logger->set_error_handler([=](const std::string &) { logger->set_error_handler([=](const std::string &) {
std::ofstream ofs("logs/custom_err.txt"); std::ofstream ofs("logs/custom_err.txt");
if (!ofs) if (!ofs)
{
throw std::runtime_error("Failed open logs/custom_err.txt"); throw std::runtime_error("Failed open logs/custom_err.txt");
}
ofs << err_msg; ofs << err_msg;
}); });
logger->info("Good message #1"); logger->info("Good message #1");

View File

@ -62,7 +62,9 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
std::string basename = "logs/rotating_log"; std::string basename = "logs/rotating_log";
auto logger = spdlog::rotating_logger_mt("logger", basename, max_size, 1); auto logger = spdlog::rotating_logger_mt("logger", basename, max_size, 1);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{
logger->info("Test message {}", i); logger->info("Test message {}", i);
}
logger->flush(); logger->flush();
auto filename = basename; auto filename = basename;

View File

@ -20,9 +20,6 @@ TEST_CASE("custom eol", "[pattern_formatter]")
{ {
std::string msg = "Hello custom eol test"; std::string msg = "Hello custom eol test";
std::string eol = ";)"; 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); REQUIRE(log_to_str(msg, "%v", spdlog::pattern_time_type::local, ";)") == msg + eol);
} }

View File

@ -8,8 +8,15 @@ void prepare_logdir()
system("del /F /Q logs\\*"); system("del /F /Q logs\\*");
#else #else
auto rv = system("mkdir -p logs"); auto rv = system("mkdir -p logs");
if(rv != 0)
{
throw std::runtime_error("Failed to mkdir -p logs");
}
rv = system("rm -f logs/*"); rv = system("rm -f logs/*");
(void)rv; if(rv != 0)
{
throw std::runtime_error("Failed to rm -f logs/*");
}
#endif #endif
} }
@ -17,7 +24,9 @@ std::string file_contents(const std::string &filename)
{ {
std::ifstream ifs(filename); std::ifstream ifs(filename);
if (!ifs) if (!ifs)
{
throw std::runtime_error("Failed open file "); throw std::runtime_error("Failed open file ");
}
return std::string((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); 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); std::ifstream ifs(filename);
if (!ifs) if (!ifs)
{
throw std::runtime_error("Failed open file "); throw std::runtime_error("Failed open file ");
}
std::string line; std::string line;
size_t counter = 0; 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); std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary);
if (!ifs) if (!ifs)
{
throw std::runtime_error("Failed open file "); throw std::runtime_error("Failed open file ");
}
return static_cast<std::size_t>(ifs.tellg()); 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) bool ends_with(std::string const &value, std::string const &ending)
{ {
if (ending.size() > value.size()) if (ending.size() > value.size())
{
return false; return false;
}
return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
} }