Skip to content

Commit

Permalink
Fix mock linking
Browse files Browse the repository at this point in the history
- Fix compile issues.

Signed-off-by: Tin Švagelj <[email protected]>
  • Loading branch information
Caellian committed Dec 9, 2024
1 parent a0c1502 commit 2b47530
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
43 changes: 21 additions & 22 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
include(CTest)

file(GLOB test_sources test-*.cc)
file(GLOB mock_sources mock/*.cc)

list(APPEND test_sources ${CMAKE_BINARY_DIR}/config.h)

if(NOT OS_LINUX)
list(FILTER test_sources EXCLUDE REGEX ".*linux.*\.cc?")
endif()

if(NOT OS_DARWIN)
list(FILTER test_sources EXCLUDE REGEX ".*darwin.*\.cc?")
endif()
macro(EXCLUDING_ANY excluded)
set(__condition "${ARGN}")
string(REGEX MATCH "^IF\s+" __starts_with_if "${__condition}")
if(NOT __starts_with_if)
message(FATAL_ERROR "EXCLUDING_ANY call missing IF keyword")
endif()
unset(__starts_with_if)
string(REGEX REPLACE "^IF\s+" "" __condition "${__condition}")
if(${__condition})
list(FILTER test_sources EXCLUDE REGEX ".*${excluded}.*\.(cc|hh)")
list(FILTER mock_sources EXCLUDE REGEX ".*${excluded}.*\.(cc|hh)")
endif()
unset(__condition)
endmacro()

if(NOT BUILD_X11)
list(FILTER test_sources EXCLUDE REGEX ".*x11.*\.cc?")
endif()

if(NOT BUILD_WAYLAND)
list(FILTER test_sources EXCLUDE REGEX ".*wayland.*\.cc?")
endif()
excluding_any("linux" IF NOT OS_LINUX)
excluding_any("darwin" IF NOT OS_DARWIN)
excluding_any("x11" IF (NOT BUILD_X11) OR OS_DARWIN)
excluding_any("wayland" IF NOT BUILD_WAYLAND)

# Mocking works because it's linked before conky_core, so the linker uses mock
# implementations instead of those that are linked later.
file(GLOB mock_sources mock/*.cc)

add_library(conky-mock OBJECT ${mock_sources})
add_library(Catch2 STATIC catch2/catch_amalgamated.cpp)

add_executable(test-conky test-common.cc ${test_sources})
Expand All @@ -33,10 +35,7 @@ target_include_directories(test-conky
${CMAKE_BINARY_DIR}
${conky_includes}
)
target_link_libraries(test-conky
PRIVATE Catch2 ${mock_sources}
PUBLIC conky_core
)
target_link_libraries(test-conky Catch2 conky-mock conky_core)
catch_discover_tests(test-conky)

if(CODE_COVERAGE)
Expand Down
1 change: 1 addition & 0 deletions tests/mock/mock.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <type_traits>

namespace mock {
Expand Down

0 comments on commit 2b47530

Please sign in to comment.