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

#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
    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");
gabime's avatar
gabime committed
17
    // SPDLOG_DEBUG(logger, "Test message 2");
gabime's avatar
gabime committed
18 19 20 21 22
    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
}

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

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

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

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

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