test_macros.cpp 1.46 KB
Newer Older
1 2 3 4 5 6 7 8
/*
* This content is released under the MIT License as specified in https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE
*/

#include "includes.h"

TEST_CASE("debug and trace w/o format string", "[macros]]")
{
gabime's avatar
gabime committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22
    prepare_logdir();
    std::string filename = "logs/simple_log";

    auto logger = spdlog::create<spdlog::sinks::simple_file_sink_mt>("logger", filename);
    logger->set_pattern("%v");
    logger->set_level(spdlog::level::trace);

    SPDLOG_TRACE(logger, "Test message 1");
    //SPDLOG_DEBUG(logger, "Test message 2");
    SPDLOG_DEBUG(logger, "Test message 2");
    logger->flush();

    REQUIRE(ends_with(file_contents(filename), "Test message 2\n"));
    REQUIRE(count_lines(filename) == 2);
23 24 25 26 27
}


TEST_CASE("debug and trace with format strings", "[macros]]")
{
gabime's avatar
gabime committed
28 29
    prepare_logdir();
    std::string filename = "logs/simple_log";
30

gabime's avatar
gabime committed
31 32 33
    auto logger = spdlog::create<spdlog::sinks::simple_file_sink_mt>("logger", filename);
    logger->set_pattern("%v");
    logger->set_level(spdlog::level::trace);
34

gabime's avatar
gabime committed
35
#if !defined(SPDLOG_FMT_PRINTF)
gabime's avatar
gabime committed
36 37 38
    SPDLOG_TRACE(logger, "Test message {}", 1);
    //SPDLOG_DEBUG(logger, "Test message 2");
    SPDLOG_DEBUG(logger, "Test message {}", 222);
gabime's avatar
gabime committed
39
#else
gabime's avatar
gabime committed
40 41 42
    SPDLOG_TRACE(logger, "Test message %d", 1);
    //SPDLOG_DEBUG(logger, "Test message 2");
    SPDLOG_DEBUG(logger, "Test message %d", 222);
gabime's avatar
gabime committed
43 44
#endif

gabime's avatar
gabime committed
45
    logger->flush();
46

gabime's avatar
gabime committed
47 48
    REQUIRE(ends_with(file_contents(filename), "Test message 222\n"));
    REQUIRE(count_lines(filename) == 2);
49 50
}