11// Copyright - 2016-2020 - Jan Christoph Uhde <[email protected] >22// Please see LICENSE.md for license or visit https://github.com/extcpp/basics
33#include < cstring>
4- #include < fstream>
54#include < filesystem>
5+ #include < sstream>
66
77#include < gtest/gtest.h>
88
1717using namespace std ::literals;
1818
1919struct LoggingTest : public ::testing::Test {
20- LoggingTest () : _log{" test.log " , std::ios::trunc } {
20+ LoggingTest () : _log{} {
2121 using namespace ext ::logging;
2222 configuration::stream = &_log;
23+ #ifdef EXT_LOGGING_ENABLE_VIM_GDB
2324 configuration::gdb = false ;
2425 configuration::vim = false ;
26+ #endif
2527 configuration::prefix_newline = false ;
2628 configuration::append_newline = true ;
2729 set_level_all (level::EXT_LOGGING_DEFAULT_LEVEL);
2830 };
2931
30-
3132 void compare (std::string const & expected = " " ){
32- _log.close ();
33- std::ifstream file{" test.log" };
34- std::istreambuf_iterator<char > eos;
35- std::string logged{std::istreambuf_iterator<char >(file), eos};
36- ASSERT_EQ (expected, logged);
33+ ASSERT_EQ (expected, _log.str ());
3734 }
3835
3936 std::string path () {
@@ -48,24 +45,28 @@ struct LoggingTest : public ::testing::Test {
4845 return std::to_string (_line);
4946 }
5047
51- std::ofstream _log;
48+ std::stringstream _log;
5249 std::size_t _line;
5350
5451};
5552using LoggingDeathTest = LoggingTest;
5653
5754TEST_F (LoggingTest, logging_no_crash_gdb_vim) {
5855 using namespace ext ::logging;
56+ #ifdef EXT_LOGGING_ENABLE_VIM_GDB
5957 configuration::gdb = true ;
6058 configuration::vim = true ;
59+ #endif
6160
6261 _line = __LINE__ + 1 ;
6362 ASSERT_NO_THROW (EXT_LOG (" babe" ) << " cafe?" );
6463
6564 compare (
65+ #ifdef EXT_LOGGING_ENABLE_VIM_GDB
6666 " # vim " s + path () + " +" + line () +" \n "
6767 " # break logging.cpp:" + line () + " \n "
68- " [babe] warning in TestBody(): 'cafe?'\n "
68+ #endif
69+ " [babe] warning logging.cpp:" s + line () + " in TestBody(): 'cafe?'\n "
6970 );
7071}
7172
0 commit comments