Merge pull request #344 from oynqr/build/allow-disabling-tests
This commit is contained in:
commit
e22d54abd3
@ -6,7 +6,7 @@ if(WIN32)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
project(Launcher)
|
project(Launcher)
|
||||||
enable_testing()
|
include(CTest)
|
||||||
|
|
||||||
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BUILD_DIR}" IS_IN_SOURCE_BUILD)
|
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BUILD_DIR}" IS_IN_SOURCE_BUILD)
|
||||||
if(IS_IN_SOURCE_BUILD)
|
if(IS_IN_SOURCE_BUILD)
|
||||||
|
@ -5,44 +5,46 @@ set(TEST_RESOURCE_PATH ${CMAKE_CURRENT_LIST_DIR})
|
|||||||
message(${TEST_RESOURCE_PATH})
|
message(${TEST_RESOURCE_PATH})
|
||||||
|
|
||||||
function(add_unit_test name)
|
function(add_unit_test name)
|
||||||
set(options "")
|
if(BUILD_TESTING)
|
||||||
set(oneValueArgs DATA)
|
set(options "")
|
||||||
set(multiValueArgs SOURCES LIBS)
|
set(oneValueArgs DATA)
|
||||||
|
set(multiValueArgs SOURCES LIBS)
|
||||||
|
|
||||||
cmake_parse_arguments(OPT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
|
cmake_parse_arguments(OPT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
add_executable(${name}_test ${OPT_SOURCES} ${TEST_RESOURCE_PATH}/UnitTest/test.rc)
|
add_executable(${name}_test ${OPT_SOURCES} ${TEST_RESOURCE_PATH}/UnitTest/test.rc)
|
||||||
else()
|
|
||||||
add_executable(${name}_test ${OPT_SOURCES})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT "${OPT_DATA}" STREQUAL "")
|
|
||||||
set(TEST_DATA_PATH "${CMAKE_CURRENT_BINARY_DIR}/data")
|
|
||||||
set(TEST_DATA_PATH_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${OPT_DATA}")
|
|
||||||
message("From ${TEST_DATA_PATH_SRC} to ${TEST_DATA_PATH}")
|
|
||||||
string(REGEX REPLACE "[/\\:]" "_" DATA_TARGET_NAME "${TEST_DATA_PATH_SRC}")
|
|
||||||
if(UNIX)
|
|
||||||
# on unix we get the third / from the filename
|
|
||||||
set(TEST_DATA_URL "file://${TEST_DATA_PATH}")
|
|
||||||
else()
|
else()
|
||||||
# we don't on windows, so we have to add it ourselves
|
add_executable(${name}_test ${OPT_SOURCES})
|
||||||
set(TEST_DATA_URL "file:///${TEST_DATA_PATH}")
|
|
||||||
endif()
|
endif()
|
||||||
if(NOT TARGET "${DATA_TARGET_NAME}")
|
|
||||||
add_custom_target(${DATA_TARGET_NAME})
|
if(NOT "${OPT_DATA}" STREQUAL "")
|
||||||
add_dependencies(${name}_test ${DATA_TARGET_NAME})
|
set(TEST_DATA_PATH "${CMAKE_CURRENT_BINARY_DIR}/data")
|
||||||
add_custom_command(
|
set(TEST_DATA_PATH_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${OPT_DATA}")
|
||||||
TARGET ${DATA_TARGET_NAME}
|
message("From ${TEST_DATA_PATH_SRC} to ${TEST_DATA_PATH}")
|
||||||
COMMAND ${CMAKE_COMMAND} "-DTEST_DATA_URL=${TEST_DATA_URL}" -DSOURCE=${TEST_DATA_PATH_SRC} -DDESTINATION=${TEST_DATA_PATH} -P ${TEST_RESOURCE_PATH}/UnitTest/generate_test_data.cmake
|
string(REGEX REPLACE "[/\\:]" "_" DATA_TARGET_NAME "${TEST_DATA_PATH_SRC}")
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
if(UNIX)
|
||||||
)
|
# on unix we get the third / from the filename
|
||||||
|
set(TEST_DATA_URL "file://${TEST_DATA_PATH}")
|
||||||
|
else()
|
||||||
|
# we don't on windows, so we have to add it ourselves
|
||||||
|
set(TEST_DATA_URL "file:///${TEST_DATA_PATH}")
|
||||||
|
endif()
|
||||||
|
if(NOT TARGET "${DATA_TARGET_NAME}")
|
||||||
|
add_custom_target(${DATA_TARGET_NAME})
|
||||||
|
add_dependencies(${name}_test ${DATA_TARGET_NAME})
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${DATA_TARGET_NAME}
|
||||||
|
COMMAND ${CMAKE_COMMAND} "-DTEST_DATA_URL=${TEST_DATA_URL}" -DSOURCE=${TEST_DATA_PATH_SRC} -DDESTINATION=${TEST_DATA_PATH} -P ${TEST_RESOURCE_PATH}/UnitTest/generate_test_data.cmake
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(${name}_test Qt5::Test ${OPT_LIBS})
|
||||||
|
|
||||||
|
target_include_directories(${name}_test PRIVATE "${TEST_RESOURCE_PATH}/UnitTest/")
|
||||||
|
|
||||||
|
add_test(NAME ${name} COMMAND ${name}_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${name}_test Qt5::Test ${OPT_LIBS})
|
|
||||||
|
|
||||||
target_include_directories(${name}_test PRIVATE "${TEST_RESOURCE_PATH}/UnitTest/")
|
|
||||||
|
|
||||||
add_test(NAME ${name} COMMAND ${name}_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@ -355,21 +355,23 @@ add_unit_test(GradleSpecifier
|
|||||||
LIBS Launcher_logic
|
LIBS Launcher_logic
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(PackageManifest
|
if(BUILD_TESTING)
|
||||||
mojang/PackageManifest_test.cpp
|
add_executable(PackageManifest
|
||||||
)
|
mojang/PackageManifest_test.cpp
|
||||||
target_link_libraries(PackageManifest
|
)
|
||||||
Launcher_logic
|
target_link_libraries(PackageManifest
|
||||||
Qt5::Test
|
Launcher_logic
|
||||||
)
|
Qt5::Test
|
||||||
target_include_directories(PackageManifest
|
)
|
||||||
PRIVATE ../cmake/UnitTest/
|
target_include_directories(PackageManifest
|
||||||
)
|
PRIVATE ../cmake/UnitTest/
|
||||||
add_test(
|
)
|
||||||
NAME PackageManifest
|
add_test(
|
||||||
COMMAND PackageManifest
|
NAME PackageManifest
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
COMMAND PackageManifest
|
||||||
)
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_unit_test(MojangVersionFormat
|
add_unit_test(MojangVersionFormat
|
||||||
SOURCES minecraft/MojangVersionFormat_test.cpp
|
SOURCES minecraft/MojangVersionFormat_test.cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user