-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added no source location tests and fixed source location tests
- Loading branch information
Showing
4 changed files
with
41 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef SPDLOG_NO_SOURCE_LOC | ||
#define SPDLOG_NO_SOURCE_LOC | ||
#endif | ||
|
||
#include "includes.h" | ||
#include "test_sink.h" | ||
|
||
// no source location should appear in the log message | ||
TEST_CASE("test_no_source_location", "[source_location]") { | ||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>(); | ||
auto logger = std::make_shared<spdlog::logger>("test", test_sink); | ||
logger->set_pattern("%s:%#:%! %v"); | ||
|
||
// test with no source location with parameters | ||
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, "Hello {}", "no source location"); | ||
REQUIRE(test_sink->lines().size() == 1); | ||
REQUIRE(test_sink->lines()[0] == ":: Hello no source location"); | ||
// test with no source location without parameters | ||
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, "Hello"); | ||
REQUIRE(test_sink->lines().size() == 2); | ||
REQUIRE(test_sink->lines()[1] == ":: Hello"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
#ifndef SPDLOG_NO_SOURCE_LOC | ||
#ifdef SPDLOG_NO_SOURCE_LOC | ||
#undef SPDLOG_NO_SOURCE_LOC | ||
#endif | ||
|
||
#include "includes.h" | ||
#include "spdlog/sinks/ostream_sink.h" | ||
#include "test_sink.h" | ||
|
||
|
||
using spdlog::details::os::default_eol; | ||
|
||
// test with source location | ||
TEST_CASE("test_source_location", "[source_location]") { | ||
std::ostringstream oss; | ||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_st>(oss); | ||
auto oss_logger = std::make_shared<spdlog::logger>("oss", oss_sink); | ||
//spdlog::logger oss_logger("oss", oss_sink); | ||
oss_logger->set_pattern("%s:%# %v"); | ||
|
||
SPDLOG_LOGGER_CALL(oss_logger, spdlog::level::info, "Hello {}", "source location"); | ||
REQUIRE(oss.str() == std::string("test_source_location.cpp:17 Hello source location") + default_eol); | ||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>(); | ||
auto logger = std::make_shared<spdlog::logger>("test", test_sink); | ||
logger->set_pattern("%s:%# %v"); | ||
// test with source location with parameters | ||
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, "Hello {}", "source location"); | ||
REQUIRE(test_sink->lines().size() == 1); | ||
REQUIRE(test_sink->lines()[0] == "test_source_location.cpp:14 Hello source location"); | ||
// test with source location without parameters | ||
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, "Hello"); | ||
REQUIRE(test_sink->lines().size() == 2); | ||
REQUIRE(test_sink->lines()[1] == "test_source_location.cpp:18 Hello"); | ||
} | ||
|
||
#endif | ||
|
||
//REQUIRE(oss.str() == std::string("test_source_location.cpp:20 Hello source location") + default_eol); |