Skip to content

Commit

Permalink
tests: Generate test name from test path
Browse files Browse the repository at this point in the history
Simplifies registering tests in the build system and avoid errors.

To realize this, the test macro doesn't allow including multiple test
files any more, but this wasn't used anyway in the codebase.

Closes #123
  • Loading branch information
Makman2 committed Aug 5, 2017
1 parent cd9878c commit 7cc197e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 75 deletions.
66 changes: 33 additions & 33 deletions CE3D2/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
set(CE3D2_TEST_ROOT ${CMAKE_CURRENT_LIST_DIR})

# Adds a new test target
function(add_ce3d2_test target)
add_executable(${target}
# Adds a new test target. Only a single test file is supported.
# TestUtilities.h is automatically linked.
function(add_ce3d2_test test_file)
get_filename_component(test_name ${test_file} NAME_WE)

add_executable(${test_name}
# TestUtilities are embedded automatically into every test.
${CE3D2_TEST_ROOT}/TestUtilities
${ARGN})
${test_file})

target_link_libraries(${target}
target_link_libraries(${test_name}
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
CE3D2)

add_test(${target} ${target})
add_test(${test_name} ${test_name})

add_custom_command(
TARGET ${target}
TARGET ${test_name}
POST_BUILD
COMMAND ${target} --log_level=error --report_level=no
COMMAND ${test_name} --log_level=error --report_level=no
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running ${target}..."
COMMENT "Running ${test_name}..."
VERBATIM)

# Copy test files if existent.
foreach(file ${ARGN})
get_filename_component(test_file_directory ${file} DIRECTORY)
get_filename_component(test_data_directory ${file} NAME_WE)
set(test_data_directory "${test_data_directory}Files")
get_filename_component(test_file_directory ${test_file} DIRECTORY)
set(test_data_directory "${test_name}Files")

set(test_data_path "${test_file_directory}/${test_data_directory}")
if(EXISTS ${test_data_path})
file(GLOB test_files "${test_data_path}/*")
set(test_data_path "${test_file_directory}/${test_data_directory}")
if(EXISTS ${test_data_path})
file(GLOB test_files "${test_data_path}/*")

foreach(test_file ${test_files})
get_filename_component(name ${test_file} NAME)
foreach(test_data_file ${test_files})
get_filename_component(name ${test_data_file} NAME)

add_custom_command(OUTPUT ${test_data_directory}/${name}
COMMAND mkdir -p ${test_data_directory} && cp ${test_file} ${test_data_directory}/${name}
DEPENDS ${test_file}
COMMENT "Copying test file ${test_data_directory}/${name}..."
VERBATIM)
add_custom_command(OUTPUT ${test_data_directory}/${name}
COMMAND mkdir -p ${test_data_directory} && cp ${test_data_file} ${test_data_directory}/${name}
DEPENDS ${test_data_file}
COMMENT "Copying test file ${test_data_directory}/${name}..."
VERBATIM)

list(APPEND test_file_targets ${test_data_directory}/${name})
endforeach()
list(APPEND test_file_targets ${test_data_directory}/${name})
endforeach()

set(test_files_dependency_target "${target}Files")
set(test_files_dependency_target "${test_name}Files")

add_custom_target(${test_files_dependency_target}
DEPENDS ${test_file_targets})
add_custom_target(${test_files_dependency_target}
DEPENDS ${test_file_targets})

add_dependencies(${target} ${test_files_dependency_target})
endif()
endforeach()
add_dependencies(${test_name} ${test_files_dependency_target})
endif()
endfunction()

# Tests in this directory.
add_ce3d2_test(MatrixTest ${CMAKE_CURRENT_LIST_DIR}/MatrixTest)
add_ce3d2_test(VectorTest ${CMAKE_CURRENT_LIST_DIR}/VectorTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/MatrixTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/VectorTest)

add_subdirectory("math")
add_subdirectory("models")
Expand Down
9 changes: 3 additions & 6 deletions CE3D2/tests/math/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
add_ce3d2_test(BoxTest
${CMAKE_CURRENT_LIST_DIR}/BoxTest)
add_ce3d2_test(LinearAffineFunctionTest
${CMAKE_CURRENT_LIST_DIR}/LinearAffineFunctionTest)
add_ce3d2_test(mathTest
${CMAKE_CURRENT_LIST_DIR}/mathTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/BoxTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/LinearAffineFunctionTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/mathTest)

add_subdirectory("matrices")
3 changes: 1 addition & 2 deletions CE3D2/tests/math/matrices/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
add_ce3d2_test(matricesTest
${CMAKE_CURRENT_LIST_DIR}/matricesTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/matricesTest)
6 changes: 3 additions & 3 deletions CE3D2/tests/models/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_ce3d2_test(IndexPairTest ${CMAKE_CURRENT_LIST_DIR}/IndexPairTest)
add_ce3d2_test(LineModelTest ${CMAKE_CURRENT_LIST_DIR}/LineModelTest)
add_ce3d2_test(ModelTest ${CMAKE_CURRENT_LIST_DIR}/ModelTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/IndexPairTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/LineModelTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/ModelTest)

add_subdirectory("loaders")
8 changes: 4 additions & 4 deletions CE3D2/tests/models/loaders/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_ce3d2_test(AllTest ${CMAKE_CURRENT_LIST_DIR}/AllTest)
add_ce3d2_test(FileFormatExceptionTest ${CMAKE_CURRENT_LIST_DIR}/FileFormatExceptionTest.cpp)
add_ce3d2_test(InvalidFileExceptionTest ${CMAKE_CURRENT_LIST_DIR}/InvalidFileExceptionTest.cpp)
add_ce3d2_test(WavefrontObjTest ${CMAKE_CURRENT_LIST_DIR}/WavefrontObjTest.cpp)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/AllTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/FileFormatExceptionTest.cpp)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/InvalidFileExceptionTest.cpp)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/WavefrontObjTest.cpp)
4 changes: 2 additions & 2 deletions CE3D2/tests/render/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_ce3d2_test(TextRendererTest ${CMAKE_CURRENT_LIST_DIR}/TextRendererTest)
add_ce3d2_test(TextSurfaceTest ${CMAKE_CURRENT_LIST_DIR}/TextSurfaceTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/TextRendererTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/TextSurfaceTest)
2 changes: 1 addition & 1 deletion CE3D2/tests/strings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add_ce3d2_test(stringsTest ${CMAKE_CURRENT_LIST_DIR}/stringsTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/stringsTest)
36 changes: 12 additions & 24 deletions CE3D2/tests/transformation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
add_ce3d2_test(ITransformableTest
${CMAKE_CURRENT_LIST_DIR}/ITransformableTest)
add_ce3d2_test(LinearTransformationTest
${CMAKE_CURRENT_LIST_DIR}/LinearTransformationTest)
add_ce3d2_test(MatrixTransformationTest
${CMAKE_CURRENT_LIST_DIR}/MatrixTransformationTest)
add_ce3d2_test(MirrorTest
${CMAKE_CURRENT_LIST_DIR}/MirrorTest)
add_ce3d2_test(OrthogonalProjectionTest
${CMAKE_CURRENT_LIST_DIR}/OrthogonalProjectionTest)
add_ce3d2_test(PermutationTest
${CMAKE_CURRENT_LIST_DIR}/PermutationTest)
add_ce3d2_test(PermutationVectorTest
${CMAKE_CURRENT_LIST_DIR}/PermutationVectorTest)
add_ce3d2_test(RotationTest
${CMAKE_CURRENT_LIST_DIR}/RotationTest)
add_ce3d2_test(ScaleTest
${CMAKE_CURRENT_LIST_DIR}/ScaleTest)
add_ce3d2_test(TransformationTest
${CMAKE_CURRENT_LIST_DIR}/TransformationTest)
add_ce3d2_test(TransformationChainTest
${CMAKE_CURRENT_LIST_DIR}/TransformationChainTest)
add_ce3d2_test(TranslationTest
${CMAKE_CURRENT_LIST_DIR}/TranslationTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/ITransformableTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/LinearTransformationTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/MatrixTransformationTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/MirrorTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/OrthogonalProjectionTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/PermutationTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/PermutationVectorTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/RotationTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/ScaleTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/TransformationTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/TransformationChainTest)
add_ce3d2_test(${CMAKE_CURRENT_LIST_DIR}/TranslationTest)

0 comments on commit 7cc197e

Please sign in to comment.