Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mock log test #724

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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