mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
Fixed multiple clang-tidy warnings
This commit is contained in:
parent
c16eb80d7f
commit
b2017f5653
@ -20,7 +20,10 @@ clang-analyzer-*,
|
||||
-cppcoreguidelines-avoid-c-arrays,
|
||||
-modernize-avoid-c-arrays,
|
||||
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||
-readability-named-parameter'
|
||||
-readability-named-parameter,
|
||||
-cert-env33-c
|
||||
'
|
||||
|
||||
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: '*spdlog/[^f].*'
|
||||
|
@ -5,14 +5,13 @@
|
||||
|
||||
TEST_CASE("basic async test ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
size_t overrun_counter = 0;
|
||||
size_t queue_size = 128;
|
||||
size_t messages = 256;
|
||||
{
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
{
|
||||
logger->info("Hello message #{}", i);
|
||||
@ -27,14 +26,13 @@ TEST_CASE("basic async test ", "[async]")
|
||||
|
||||
TEST_CASE("discard policy ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
test_sink->set_delay(std::chrono::milliseconds(1));
|
||||
size_t queue_size = 4;
|
||||
size_t messages = 1024;
|
||||
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::overrun_oldest);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::overrun_oldest);
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
{
|
||||
logger->info("Hello message");
|
||||
@ -45,13 +43,12 @@ TEST_CASE("discard policy ", "[async]")
|
||||
|
||||
TEST_CASE("discard policy using factory ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
size_t queue_size = 4;
|
||||
size_t messages = 1024;
|
||||
spdlog::init_thread_pool(queue_size, 1);
|
||||
|
||||
auto logger = spdlog::create_async_nb<sinks::test_sink_mt>("as2");
|
||||
auto test_sink = std::static_pointer_cast<sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
auto logger = spdlog::create_async_nb<spdlog::sinks::test_sink_mt>("as2");
|
||||
auto test_sink = std::static_pointer_cast<spdlog::sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
test_sink->set_delay(std::chrono::milliseconds(1));
|
||||
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
@ -65,13 +62,12 @@ TEST_CASE("discard policy using factory ", "[async]")
|
||||
|
||||
TEST_CASE("flush", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
size_t queue_size = 256;
|
||||
size_t messages = 256;
|
||||
{
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
{
|
||||
logger->info("Hello message #{}", i);
|
||||
@ -86,11 +82,9 @@ TEST_CASE("flush", "[async]")
|
||||
|
||||
TEST_CASE("async periodic flush", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
|
||||
auto logger = spdlog::create_async<sinks::test_sink_mt>("as");
|
||||
|
||||
auto test_sink = std::static_pointer_cast<sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
auto logger = spdlog::create_async<spdlog::sinks::test_sink_mt>("as");
|
||||
auto test_sink = std::static_pointer_cast<spdlog::sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
|
||||
spdlog::flush_every(std::chrono::seconds(1));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1100));
|
||||
@ -101,13 +95,12 @@ TEST_CASE("async periodic flush", "[async]")
|
||||
|
||||
TEST_CASE("tp->wait_empty() ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
test_sink->set_delay(std::chrono::milliseconds(5));
|
||||
size_t messages = 100;
|
||||
|
||||
auto tp = std::make_shared<details::thread_pool>(messages, 2);
|
||||
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(messages, 2);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
{
|
||||
logger->info("Hello message #{}", i);
|
||||
@ -121,14 +114,13 @@ TEST_CASE("tp->wait_empty() ", "[async]")
|
||||
|
||||
TEST_CASE("multi threads", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
size_t queue_size = 128;
|
||||
size_t messages = 256;
|
||||
size_t n_threads = 10;
|
||||
{
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
for (size_t i = 0; i < n_threads; i++)
|
||||
|
@ -113,8 +113,7 @@ static void test_rotate(int days_to_run, uint16_t max_days, uint16_t expected_n_
|
||||
using spdlog::log_clock;
|
||||
using spdlog::details::log_msg;
|
||||
using spdlog::sinks::daily_file_sink_st;
|
||||
using namespace spdlog::details;
|
||||
|
||||
|
||||
prepare_logdir();
|
||||
|
||||
std::string basename = "test_logs/daily_rotate.txt";
|
||||
|
@ -2,11 +2,11 @@
|
||||
#include "spdlog/sinks/dup_filter_sink.h"
|
||||
#include "test_sink.h"
|
||||
|
||||
using namespace spdlog;
|
||||
using namespace spdlog::sinks;
|
||||
|
||||
TEST_CASE("dup_filter_test1", "[dup_filter_sink]")
|
||||
{
|
||||
using spdlog::sinks::dup_filter_sink_st;
|
||||
using spdlog::sinks::test_sink_mt;
|
||||
|
||||
dup_filter_sink_st dup_sink{std::chrono::seconds{5}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
@ -21,6 +21,9 @@ TEST_CASE("dup_filter_test1", "[dup_filter_sink]")
|
||||
|
||||
TEST_CASE("dup_filter_test2", "[dup_filter_sink]")
|
||||
{
|
||||
using spdlog::sinks::dup_filter_sink_st;
|
||||
using spdlog::sinks::test_sink_mt;
|
||||
|
||||
dup_filter_sink_st dup_sink{std::chrono::seconds{0}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
@ -36,6 +39,9 @@ TEST_CASE("dup_filter_test2", "[dup_filter_sink]")
|
||||
|
||||
TEST_CASE("dup_filter_test3", "[dup_filter_sink]")
|
||||
{
|
||||
using spdlog::sinks::dup_filter_sink_st;
|
||||
using spdlog::sinks::test_sink_mt;
|
||||
|
||||
dup_filter_sink_st dup_sink{std::chrono::seconds{1}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
@ -51,6 +57,9 @@ TEST_CASE("dup_filter_test3", "[dup_filter_sink]")
|
||||
|
||||
TEST_CASE("dup_filter_test4", "[dup_filter_sink]")
|
||||
{
|
||||
using spdlog::sinks::dup_filter_sink_mt;
|
||||
using spdlog::sinks::test_sink_mt;
|
||||
|
||||
dup_filter_sink_mt dup_sink{std::chrono::milliseconds{10}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
@ -63,6 +72,9 @@ TEST_CASE("dup_filter_test4", "[dup_filter_sink]")
|
||||
|
||||
TEST_CASE("dup_filter_test5", "[dup_filter_sink]")
|
||||
{
|
||||
using spdlog::sinks::dup_filter_sink_mt;
|
||||
using spdlog::sinks::test_sink_mt;
|
||||
|
||||
dup_filter_sink_mt dup_sink{std::chrono::seconds{5}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
@ -7,10 +7,6 @@
|
||||
|
||||
class failing_sink : public spdlog::sinks::base_sink<std::mutex>
|
||||
{
|
||||
public:
|
||||
failing_sink() = default;
|
||||
~failing_sink() = default;
|
||||
|
||||
protected:
|
||||
void sink_it_(const spdlog::details::log_msg &) final
|
||||
{
|
||||
|
@ -4,9 +4,6 @@
|
||||
#include "includes.h"
|
||||
|
||||
using spdlog::details::file_helper;
|
||||
using spdlog::details::log_msg;
|
||||
|
||||
static const std::string target_filename = "test_logs/file_helper_test.txt";
|
||||
|
||||
static void write_with_helper(file_helper &helper, size_t howmany)
|
||||
{
|
||||
@ -21,6 +18,7 @@ TEST_CASE("file_helper_filename", "[file_helper::filename()]]")
|
||||
prepare_logdir();
|
||||
|
||||
file_helper helper;
|
||||
std::string target_filename = "test_logs/file_helper_test.txt";
|
||||
helper.open(target_filename);
|
||||
REQUIRE(helper.filename() == target_filename);
|
||||
}
|
||||
@ -28,6 +26,7 @@ TEST_CASE("file_helper_filename", "[file_helper::filename()]]")
|
||||
TEST_CASE("file_helper_size", "[file_helper::size()]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string target_filename = "test_logs/file_helper_test.txt";
|
||||
size_t expected_size = 123;
|
||||
{
|
||||
file_helper helper;
|
||||
@ -41,6 +40,7 @@ TEST_CASE("file_helper_size", "[file_helper::size()]]")
|
||||
TEST_CASE("file_helper_reopen", "[file_helper::reopen()]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string target_filename = "test_logs/file_helper_test.txt";
|
||||
file_helper helper;
|
||||
helper.open(target_filename);
|
||||
write_with_helper(helper, 12);
|
||||
@ -52,6 +52,7 @@ TEST_CASE("file_helper_reopen", "[file_helper::reopen()]]")
|
||||
TEST_CASE("file_helper_reopen2", "[file_helper::reopen(false)]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string target_filename = "test_logs/file_helper_test.txt";
|
||||
size_t expected_size = 14;
|
||||
file_helper helper;
|
||||
helper.open(target_filename);
|
||||
@ -71,7 +72,8 @@ static void test_split_ext(const char *fname, const char *expect_base, const cha
|
||||
std::replace(filename.begin(), filename.end(), '/', '\\');
|
||||
std::replace(expected_base.begin(), expected_base.end(), '/', '\\');
|
||||
#endif
|
||||
spdlog::filename_t basename, ext;
|
||||
spdlog::filename_t basename;
|
||||
spdlog::filename_t ext;
|
||||
std::tie(basename, ext) = file_helper::split_by_extension(filename);
|
||||
REQUIRE(basename == expected_base);
|
||||
REQUIRE(ext == expected_ext);
|
||||
|
@ -54,8 +54,7 @@ TEST_CASE("rotating_file_logger1", "[rotating_logger]]")
|
||||
}
|
||||
|
||||
logger->flush();
|
||||
auto filename = basename;
|
||||
require_message_count(filename, 10);
|
||||
require_message_count(basename, 10);
|
||||
}
|
||||
|
||||
TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
|
||||
@ -83,8 +82,8 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
|
||||
}
|
||||
|
||||
logger->flush();
|
||||
auto filename = basename;
|
||||
require_message_count(filename, 10);
|
||||
|
||||
require_message_count(basename, 10);
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
@ -93,7 +92,7 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
|
||||
}
|
||||
|
||||
logger->flush();
|
||||
REQUIRE(get_filesize(filename) <= max_size);
|
||||
REQUIRE(get_filesize(basename) <= max_size);
|
||||
auto filename1 = basename + ".1";
|
||||
REQUIRE(get_filesize(filename1) <= max_size);
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ TEST_CASE("basic_logging ", "[basic_logging]")
|
||||
{
|
||||
// const char
|
||||
REQUIRE(log_info("Hello") == "Hello");
|
||||
REQUIRE(log_info("") == "");
|
||||
REQUIRE(log_info("").empty());
|
||||
|
||||
// std::string
|
||||
REQUIRE(log_info(std::string("Hello")) == "Hello");
|
||||
REQUIRE(log_info(std::string()) == std::string());
|
||||
REQUIRE(log_info(std::string()).empty());
|
||||
|
||||
// Numbers
|
||||
REQUIRE(log_info(5) == "5");
|
||||
@ -37,8 +37,8 @@ TEST_CASE("basic_logging ", "[basic_logging]")
|
||||
|
||||
TEST_CASE("log_levels", "[log_levels]")
|
||||
{
|
||||
REQUIRE(log_info("Hello", spdlog::level::err) == "");
|
||||
REQUIRE(log_info("Hello", spdlog::level::critical) == "");
|
||||
REQUIRE(log_info("Hello", spdlog::level::err).empty());
|
||||
REQUIRE(log_info("Hello", spdlog::level::critical).empty());
|
||||
REQUIRE(log_info("Hello", spdlog::level::info) == "Hello");
|
||||
REQUIRE(log_info("Hello", spdlog::level::debug) == "Hello");
|
||||
REQUIRE(log_info("Hello", spdlog::level::trace) == "Hello");
|
||||
@ -81,11 +81,9 @@ TEST_CASE("to_level_enum", "[convert_to_level_enum]")
|
||||
|
||||
TEST_CASE("periodic flush", "[periodic_flush]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
|
||||
auto logger = spdlog::create<sinks::test_sink_mt>("periodic_flush");
|
||||
|
||||
auto test_sink = std::static_pointer_cast<sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
using spdlog::sinks::test_sink_mt;
|
||||
auto logger = spdlog::create<test_sink_mt>("periodic_flush");
|
||||
auto test_sink = std::static_pointer_cast<test_sink_mt>(logger->sinks()[0]);
|
||||
|
||||
spdlog::flush_every(std::chrono::seconds(1));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1250));
|
||||
@ -96,8 +94,8 @@ TEST_CASE("periodic flush", "[periodic_flush]")
|
||||
|
||||
TEST_CASE("clone-logger", "[clone]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
using spdlog::sinks::test_sink_mt;
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
auto logger = std::make_shared<spdlog::logger>("orig", test_sink);
|
||||
logger->set_pattern("%v");
|
||||
auto cloned = logger->clone("clone");
|
||||
@ -118,10 +116,9 @@ TEST_CASE("clone-logger", "[clone]")
|
||||
|
||||
TEST_CASE("clone async", "[clone]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
|
||||
using spdlog::sinks::test_sink_st;
|
||||
spdlog::init_thread_pool(4, 1);
|
||||
auto test_sink = std::make_shared<sinks::test_sink_st>();
|
||||
auto test_sink = std::make_shared<test_sink_st>();
|
||||
auto logger = std::make_shared<spdlog::async_logger>("orig", test_sink, spdlog::thread_pool());
|
||||
logger->set_pattern("%v");
|
||||
auto cloned = logger->clone("clone");
|
||||
|
@ -86,7 +86,7 @@ TEST_CASE("full_queue", "[mpmc_blocking_q]")
|
||||
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||
for (int i = 0; i < static_cast<int>(q_size); i++)
|
||||
{
|
||||
q.enqueue(i+0); // i+0 to force rvalue and avoid tidy warnings on the same time
|
||||
q.enqueue(i+0); // i+0 to force rvalue and avoid tidy warnings on the same time if we std::move(i) instead
|
||||
}
|
||||
|
||||
q.enqueue_nowait(123456);
|
||||
|
@ -27,7 +27,7 @@ TEST_CASE("custom eol", "[pattern_formatter]")
|
||||
|
||||
TEST_CASE("empty format", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "", spdlog::pattern_time_type::local, "") == "");
|
||||
REQUIRE(log_to_str("Some message", "", spdlog::pattern_time_type::local, "").empty());
|
||||
}
|
||||
|
||||
TEST_CASE("empty format2", "[pattern_formatter]")
|
||||
@ -308,7 +308,7 @@ TEST_CASE("clone-formatter-2", "[pattern_formatter]")
|
||||
class custom_test_flag : public spdlog::custom_flag_formatter
|
||||
{
|
||||
public:
|
||||
custom_test_flag(std::string txt)
|
||||
explicit custom_test_flag(std::string txt)
|
||||
: some_txt{std::move(txt)}
|
||||
{}
|
||||
|
||||
@ -358,9 +358,9 @@ TEST_CASE("clone-custom_formatter", "[pattern_formatter]")
|
||||
//
|
||||
|
||||
#ifdef _WIN32
|
||||
static const char *test_path = "\\a\\b\\myfile.cpp";
|
||||
static const char *const test_path = "\\a\\b\\myfile.cpp";
|
||||
#else
|
||||
static const char *test_path = "/a/b//myfile.cpp";
|
||||
static const char * const test_path = "/a/b//myfile.cpp";
|
||||
#endif
|
||||
|
||||
TEST_CASE("short filename formatter-1", "[pattern_formatter]")
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "includes.h"
|
||||
|
||||
static const char *tested_logger_name = "null_logger";
|
||||
static const char *tested_logger_name2 = "null_logger2";
|
||||
static const char * const tested_logger_name = "null_logger";
|
||||
static const char * const tested_logger_name2 = "null_logger2";
|
||||
|
||||
#ifndef SPDLOG_NO_EXCEPTIONS
|
||||
TEST_CASE("register_drop", "[registry]")
|
||||
|
@ -113,7 +113,7 @@ std::size_t count_files(const std::string &folder)
|
||||
throw std::runtime_error("Failed open folder " + folder);
|
||||
}
|
||||
|
||||
struct dirent *ep;
|
||||
struct dirent *ep = nullptr;
|
||||
while ((ep = readdir(dp)) != nullptr)
|
||||
{
|
||||
if (ep->d_name[0] != '.')
|
||||
|
Loading…
Reference in New Issue
Block a user