Skip to content

Commit

Permalink
automatically select internal/external tests
Browse files Browse the repository at this point in the history
- having this as an option is a pain, because even if you haven't set it
  the value is remembered, so if you e.g. change BUILD_SHARED_LIBS you
  would have to explicitly set EAR_UNIT_TESTS

- not all tests depend on the internals, and we should still run the
  external ones if we can. this is not just a good idea from an
  integrity point of view, it also allows us to check that we've added
  exports to the external API

- either way, it should always be possible to run 'make test'
  successfully (unless explicitly disabled), so that if we add more
  tests in any configuration they will get picked up in CI

- cmake generator expressions don't actually work here, because they are
  evaluated when the build system is generated, not while the
  CMakeLists.txt files are being ran
  • Loading branch information
tomjnixon committed Jul 31, 2019
1 parent 231daac commit f3bd248
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
17 changes: 9 additions & 8 deletions CMakeLists.txt
Expand Up @@ -33,7 +33,7 @@ SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --cov
include(FeatureSummary)
option(BUILD_SHARED_LIBS "Build shared libraries rather than static" FALSE)
option(EAR_HIDE_INTERNAL_SYMBOLS "Hide symbols by default" TRUE)
option(EAR_UNIT_TESTS "Build units tests" $<AND:${IS_ROOT_PROJECT},$<NOT:${BUILD_SHARED_LIBS}>>)
option(EAR_UNIT_TESTS "Build units tests" ${IS_ROOT_PROJECT})
option(EAR_EXAMPLES "Build examples" ${IS_ROOT_PROJECT})
option(EAR_PACKAGE_AND_INSTALL "Package and install libear" ${IS_ROOT_PROJECT})
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
Expand All @@ -45,11 +45,10 @@ else()
set(INSTALL_CMAKE_DIR share/cmake/ear CACHE PATH "Installation directory for CMake files")
endif()

if(${BUILD_SHARED_LIBS} AND ${EAR_UNIT_TESTS} AND ${EAR_HIDE_INTERNAL_SYMBOLS})
message(FATAL_ERROR "\
Unit tests need access to internal functions which are not exported by \
default for a shared library. Consider disabling EAR_HIDE_INTERNAL_SYMBOLS \
to run the unit tests with the shared library of libear.")
if((NOT BUILD_SHARED_LIBS) OR (NOT EAR_HIDE_INTERNAL_SYMBOLS))
SET(EAR_INTERNAL_TESTS TRUE)
else()
SET(EAR_INTERNAL_TESTS FALSE)
endif()

############################################################
Expand Down Expand Up @@ -77,8 +76,8 @@ if(EAR_EXAMPLES)
endif()

if(EAR_UNIT_TESTS)
include(CTest)
add_subdirectory(tests)
include(CTest)
add_subdirectory(tests)
endif()

############################################################
Expand All @@ -87,6 +86,8 @@ endif()
add_feature_info(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} "Build shared libraries rather than static")
add_feature_info(EAR_HIDE_INTERNAL_SYMBOLS ${EAR_HIDE_INTERNAL_SYMBOLS} "Hide symbols by default")
add_feature_info(EAR_UNIT_TESTS ${EAR_UNIT_TESTS} "Build units tests")
add_feature_info("Internal Tests" ${EAR_INTERNAL_TESTS}
"Build internal tests; requires BUILD_SHARED_LIBS or EAR_HIDE_INTERNAL_SYMBOLS to be FALSE")
add_feature_info(EAR_EXAMPLES ${EAR_EXAMPLES} "Build examples")
add_feature_info(EAR_PACKAGE_AND_INSTALL ${EAR_PACKAGE_AND_INSTALL} "Package and install libear")
feature_summary(WHAT ALL)
Expand Down
23 changes: 13 additions & 10 deletions tests/CMakeLists.txt
Expand Up @@ -23,18 +23,21 @@ endfunction()
# when executed as "test" target
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/test_data" DESTINATION ${PROJECT_BINARY_DIR})

add_ear_test("bs2051_tests")
add_ear_test("decorrelate_tests")
add_ear_test("extent_tests")
add_ear_test("eigen_helpers_tests")
add_ear_test("gain_calculator_objects_tests")
add_ear_test("gain_calculator_direct_speakers_tests")
add_ear_test("gain_calculator_hoa_tests")
add_ear_test("geom_tests")
add_ear_test("point_source_panner_tests")
add_ear_test("hoa_tests")
if(EAR_INTERNAL_TESTS)
add_ear_test("decorrelate_tests")
add_ear_test("extent_tests")
add_ear_test("gain_calculator_direct_speakers_tests")
add_ear_test("geom_tests")
add_ear_test("hoa_tests")
add_ear_test("point_source_panner_tests")
endif()

add_ear_test("block_convolver_tests")
target_sources("block_convolver_tests" PRIVATE "block_convolver_test_utils.cpp")
add_ear_test("bs2051_tests")
add_ear_test("delay_buffer_tests")
add_ear_test("eigen_helpers_tests")
add_ear_test("gain_calculator_hoa_tests")
add_ear_test("gain_calculator_objects_tests")
add_ear_test("gain_interpolator_tests")
add_ear_test("variable_block_size_tests")

0 comments on commit f3bd248

Please sign in to comment.