88
99#include " DAPLog.h"
1010#include " llvm/Support/raw_ostream.h"
11+ #include " gmock/gmock.h"
1112#include " gtest/gtest.h"
1213
1314using namespace lldb_dap ;
1415using namespace llvm ;
16+ using namespace testing ;
1517
1618static llvm::StringRef last_line (llvm::StringRef str) {
1719 size_t index = str.find_last_of (' \n ' , str.size () - 1 );
@@ -20,27 +22,32 @@ static llvm::StringRef last_line(llvm::StringRef str) {
2022 return str.substr (index + 1 );
2123}
2224
25+ #define TIMESTAMP_PATTERN " [0-9]+\\ .[0-9]+ "
26+
2327TEST (DAPLog, Emit) {
2428 Log::Mutex mux;
2529 std::string outs;
2630 raw_string_ostream os (outs);
2731 Log log (os, mux);
2832 Log inner_log = log.WithPrefix (" my_prefix:" );
2933
30- // Line includes a timestamp, only check the suffix.
3134 log.Emit (" Hi" );
32- EXPECT_TRUE (last_line (outs). ends_with ( " Hi\n " )) << outs ;
35+ EXPECT_THAT (last_line (outs), MatchesRegex (TIMESTAMP_PATTERN " Hi\n " ));
3336
3437 inner_log.Emit (" foobar" );
35- EXPECT_TRUE (last_line (outs).ends_with (" my_prefix: foobar\n " )) << outs;
38+ EXPECT_THAT (last_line (outs),
39+ MatchesRegex (TIMESTAMP_PATTERN " my_prefix: foobar\n " ));
3640
3741 log.Emit (" file.cpp" , 42 , " Hello from a file/line." );
38- EXPECT_TRUE (
39- last_line (outs). ends_with ( " file.cpp:42 Hello from a file/line. \n " ))
40- << outs ;
42+ EXPECT_THAT (
43+ last_line (outs),
44+ MatchesRegex (TIMESTAMP_PATTERN " file.cpp:42 Hello from a file/line. \n " )) ;
4145
4246 inner_log.Emit (" file.cpp" , 42 , " Hello from a file/line." );
43- EXPECT_TRUE (last_line (outs).ends_with (
44- " file.cpp:42 my_prefix: Hello from a file/line.\n " ))
45- << outs;
46- }
47+ EXPECT_THAT (last_line (outs),
48+ MatchesRegex (TIMESTAMP_PATTERN
49+ " file.cpp:42 my_prefix: Hello from a file/line.\n " ));
50+
51+ log.WithPrefix (" a" ).WithPrefix (" b" ).WithPrefix (" c" ).Emit (" msg" );
52+ EXPECT_THAT (last_line (outs), MatchesRegex (TIMESTAMP_PATTERN " a b c msg\n " ));
53+ }
0 commit comments