Skip to content

Commit

Permalink
Merge pull request #724 from google/mock-log
Browse files Browse the repository at this point in the history
add mock log test
  • Loading branch information
sergiud committed Oct 12, 2021
2 parents ce35336 + 1398762 commit 9cf0eb7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ int main(void)
}
" HAVE___SYNC_VAL_COMPARE_AND_SWAP)

cmake_push_check_state (RESET)
set (CMAKE_REQUIRED_LIBRARIES Threads::Threads)
check_cxx_source_compiles ("
#define _XOPEN_SOURCE 500
#include <pthread.h>
Expand All @@ -199,6 +201,7 @@ int main(void)
return 0;
}
" HAVE_RWLOCK)
cmake_pop_check_state ()

check_cxx_source_compiles ("
__declspec(selectany) int a;
Expand Down Expand Up @@ -830,7 +833,7 @@ if (BUILD_TESTING)

set_tests_properties (logging PROPERTIES TIMEOUT 30)

# FIXME: Skip flaky test
# FIXME: Skip flaky test
set_tests_properties (logging PROPERTIES SKIP_REGULAR_EXPRESSION
"Check failed: time_ns within LogTimes::LOG_PERIOD_TOL_NS of LogTimes::LOG_PERIOD_NS")

Expand All @@ -855,6 +858,17 @@ if (BUILD_TESTING)
add_test (NAME symbolize COMMAND symbolize_unittest)
endif (TARGET symbolize_unittest)

if (HAVE_LIB_GMOCK)
add_executable (mock-log_unittest
src/mock-log_unittest.cc
src/mock-log.h
)

target_link_libraries (mock-log_unittest PRIVATE ${_GLOG_TEST_LIBS})

add_test (NAME mock-log COMMAND mock-log_unittest)
endif (HAVE_LIB_GMOCK)

# Generate an initial cache

get_cache_variables (_CACHEVARS)
Expand Down
2 changes: 1 addition & 1 deletion src/mock-log.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ScopedMockLog : public GOOGLE_NAMESPACE::LogSink {
ScopedMockLog() { AddLogSink(this); }

// When the object is destructed, it stops intercepting logs.
virtual ~ScopedMockLog() { RemoveLogSink(this); }
~ScopedMockLog() { RemoveLogSink(this); }

// Implements the mock method:
//
Expand Down
2 changes: 1 addition & 1 deletion src/mock-log_test.cc → src/mock-log_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TEST(ScopedMockLogTest, InterceptsLog) {
ScopedMockLog log;

InSequence s;
EXPECT_CALL(log, Log(WARNING, HasSubstr("/mock-log_test.cc"), "Fishy."));
EXPECT_CALL(log, Log(WARNING, HasSubstr("/mock-log_unittest.cc"), "Fishy."));
EXPECT_CALL(log, Log(INFO, _, "Working..."))
.Times(2);
EXPECT_CALL(log, Log(ERROR, _, "Bad!!"));
Expand Down

0 comments on commit 9cf0eb7

Please sign in to comment.