Skip to content

Commit

Permalink
Fix inaccurate coverage caused by LOG (#868)
Browse files Browse the repository at this point in the history
Fix #845
  • Loading branch information
cindyyan317 authored Sep 21, 2023
1 parent 0eaaa1f commit 4452714
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ if (tests)
# Generate `clio_tests-ccov` if coverage is enabled
# Note: use `make clio_tests-ccov` to generate report
if (coverage)
target_compile_definitions(${TEST_TARGET} PRIVATE COVERAGE_ENABLED)
include (CMake/Coverage.cmake)
add_coverage (${TEST_TARGET})
endif ()
Expand Down
4 changes: 4 additions & 0 deletions src/util/log/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,16 @@ using SourceLocationType = SourceLocation;
*
* Note: Currently this introduces potential shadowing (unlikely).
*/
#ifndef COVERAGE_ENABLED
#define LOG(x) \
if (auto clio_pump__ = x; not clio_pump__) \
{ \
} \
else \
clio_pump__
#else
#define LOG(x) x
#endif

/**
* @brief Custom severity levels for @ref util::Logger.
Expand Down
2 changes: 2 additions & 0 deletions unittests/LoggerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ TEST_F(LoggerTest, Filtering)
checkEqual("Trace:TRC Trace line logged for 'Trace' component");
}

#ifndef COVERAGE_ENABLED
TEST_F(LoggerTest, LOGMacro)
{
Logger log{"General"};
Expand All @@ -73,6 +74,7 @@ TEST_F(LoggerTest, LOGMacro)
log.trace() << compute();
EXPECT_TRUE(computeCalled);
}
#endif

TEST_F(NoLoggerTest, Basic)
{
Expand Down

0 comments on commit 4452714

Please sign in to comment.