2013-12-14 13:17:59 +00:00
|
|
|
# run the unit tests with `make test`
|
2016-01-06 07:47:31 +00:00
|
|
|
find_package(Qt5Test)
|
2013-12-02 10:09:56 +00:00
|
|
|
|
2016-03-03 00:40:12 +00:00
|
|
|
add_custom_target(test_data)
|
|
|
|
|
2013-12-02 10:09:56 +00:00
|
|
|
unset(MultiMC_TESTS)
|
|
|
|
macro(add_unit_test name)
|
|
|
|
unset(srcs)
|
|
|
|
foreach(arg ${testname} ${ARGN})
|
|
|
|
list(APPEND srcs ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
|
|
|
|
endforeach()
|
2016-03-03 00:40:12 +00:00
|
|
|
if(WIN32)
|
|
|
|
list(APPEND srcs ${CMAKE_CURRENT_SOURCE_DIR}/test.rc)
|
|
|
|
endif()
|
2013-12-02 10:09:56 +00:00
|
|
|
add_executable(tst_${name} ${srcs})
|
2016-03-03 00:40:12 +00:00
|
|
|
add_dependencies(tst_${name} test_data)
|
2015-02-09 00:51:14 +00:00
|
|
|
target_link_libraries(tst_${name} MultiMC_logic)
|
2015-09-28 19:53:46 +01:00
|
|
|
qt5_use_modules(tst_${name} Test Core Network)
|
2013-12-02 10:09:56 +00:00
|
|
|
list(APPEND MultiMC_TESTS tst_${name})
|
2013-12-14 13:17:59 +00:00
|
|
|
add_test(NAME ${name} COMMAND tst_${name})
|
2013-12-02 10:09:56 +00:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
# Tests START #
|
|
|
|
|
2014-07-16 01:03:52 +01:00
|
|
|
add_unit_test(gradlespecifier tst_gradlespecifier.cpp)
|
2013-12-14 13:17:59 +00:00
|
|
|
add_unit_test(userutils tst_userutils.cpp)
|
2014-09-06 17:16:56 +01:00
|
|
|
add_unit_test(modutils tst_modutils.cpp)
|
2014-03-29 20:16:54 +00:00
|
|
|
add_unit_test(inifile tst_inifile.cpp)
|
2015-12-26 01:44:33 +00:00
|
|
|
add_unit_test(FileSystem tst_FileSystem.cpp)
|
2013-12-14 13:53:18 +00:00
|
|
|
add_unit_test(UpdateChecker tst_UpdateChecker.cpp)
|
2015-02-08 16:56:14 +00:00
|
|
|
add_unit_test(DownloadTask tst_DownloadTask.cpp)
|
2015-08-18 01:25:24 +01:00
|
|
|
add_unit_test(filematchers tst_filematchers.cpp)
|
2015-12-26 02:13:31 +00:00
|
|
|
add_unit_test(ModList tst_ModList.cpp)
|
2015-06-06 11:30:49 +01:00
|
|
|
add_unit_test(Resource tst_Resource.cpp)
|
2015-09-14 01:25:47 +01:00
|
|
|
add_unit_test(GZip tst_GZip.cpp)
|
2016-01-01 23:35:54 +00:00
|
|
|
add_unit_test(JavaVersion tst_JavaVersion.cpp)
|
2016-03-02 02:03:44 +00:00
|
|
|
add_unit_test(ParseUtils tst_ParseUtils.cpp)
|
2016-03-03 00:40:12 +00:00
|
|
|
add_unit_test(MojangVersionFormat tst_MojangVersionFormat.cpp)
|
2013-12-02 10:09:56 +00:00
|
|
|
|
|
|
|
# Tests END #
|
2015-01-31 18:21:47 +00:00
|
|
|
|
2013-12-02 10:09:56 +00:00
|
|
|
set(COVERAGE_SOURCE_DIRS
|
2014-04-09 14:41:49 +01:00
|
|
|
${MMC_SRC}/logic/*
|
|
|
|
${MMC_SRC}/logic/auth/*
|
|
|
|
${MMC_SRC}/logic/auth/flows/*
|
|
|
|
${MMC_SRC}/logic/lists/*
|
|
|
|
${MMC_SRC}/logic/net/*
|
|
|
|
${MMC_SRC}/logic/tasks/*
|
2015-02-09 00:51:14 +00:00
|
|
|
${MMC_SRC}/application/*
|
|
|
|
${MMC_SRC}/application/dialogs/*
|
|
|
|
${MMC_SRC}/application/widgets/*
|
2014-04-09 14:41:49 +01:00
|
|
|
${MMC_SRC}/depends/settings/include/*
|
|
|
|
${MMC_SRC}/depends/settings/src/*
|
|
|
|
${MMC_SRC}/depends/util/include/*
|
|
|
|
${MMC_SRC}/depends/util/src/*
|
2013-12-02 10:09:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if(MultiMC_CODE_COVERAGE)
|
|
|
|
unset(MultiMC_RUN_TESTS)
|
|
|
|
unset(MultiMC_TEST_COVERAGE_FILES)
|
|
|
|
|
|
|
|
foreach(test ${MultiMC_TESTS})
|
|
|
|
add_custom_target(MultiMC_RUN_TEST_${test}
|
2014-04-09 14:41:49 +01:00
|
|
|
COMMAND lcov -d ${CMAKE_CURRENT_BINARY_DIR} -z -q # clean test
|
2013-12-02 10:09:56 +00:00
|
|
|
&& lcov -d ${MMC_BIN} -z -q # clean common
|
|
|
|
&& lcov -d ${MMC_BIN}/depends/settings/CMakeFiles/libSettings.dir -z -q # clean settings
|
|
|
|
&& lcov -d ${MMC_BIN}/depends/utils/CMakeFiles/libUtil.dir -z -q # clean utils
|
|
|
|
&& ${MMC_BIN}/${test} -o coverage_${test}.out,xml # run test
|
|
|
|
&& lcov -q --checksum -b ${MMC_SRC} -d ${CMAKE_CURRENT_BINARY_DIR} -c -o coverage_${test}.info # generate for test
|
|
|
|
&& lcov -q --checksum -b ${MMC_SRC} -d ${MMC_BIN} -c -o coverage_common.info # generate for common
|
|
|
|
&& lcov -q --checksum -b ${MMC_SRC} -d ${MMC_BIN}/depends/settings/CMakeFiles/libSettings.dir -c -o coverage_settings.info # generate for settings
|
|
|
|
&& lcov -q --checksum -b ${MMC_SRC} -d ${MMC_BIN}/depends/util/CMakeFiles/libUtil.dir -c -o coverage_utils.info # generate for utils
|
|
|
|
&& lcov -q --checksum -b ${MMC_SRC} -d .
|
|
|
|
-a coverage_${test}.info -a coverage_common.info -a coverage_settings.info -a coverage_utils.info
|
|
|
|
-o coverage_${test}-combined.info # combine test and common
|
|
|
|
&& lcov -q --checksum -b ${MMC_SRC} --list-full-path --extract coverage_${test}-combined.info ${COVERAGE_SOURCE_DIRS} -o coverage_${test}-stripped.info # strip
|
2014-04-09 14:41:49 +01:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
VERBATIM
|
|
|
|
DEPENDS ${test}
|
|
|
|
COMMENT "Running ${test}..."
|
2013-12-02 10:09:56 +00:00
|
|
|
)
|
|
|
|
list(APPEND MultiMC_TEST_COVERAGE_FILES coverage_${test}-stripped.info)
|
|
|
|
list(APPEND MultiMC_RUN_TESTS MultiMC_RUN_TEST_${test})
|
|
|
|
endforeach(test)
|
|
|
|
|
|
|
|
add_custom_target(MultiMC_GENERATE_COVERAGE
|
2014-04-09 14:41:49 +01:00
|
|
|
DEPENDS ${MultiMC_RUN_TESTS}
|
|
|
|
COMMENT "Generating coverage files..."
|
2013-12-02 10:09:56 +00:00
|
|
|
)
|
|
|
|
add_custom_target(MultiMC_GENERATE_COVERAGE_HTML
|
2014-04-09 14:41:49 +01:00
|
|
|
COMMAND genhtml -t "MultiMC 5 Test Coverage" --num-spaces 4 --demangle-cpp --legend -o ${MMC_SRC}/html/coverage ${MultiMC_TEST_COVERAGE_FILES}
|
|
|
|
DEPENDS MultiMC_GENERATE_COVERAGE
|
|
|
|
COMMENT "Generating test coverage html..."
|
2013-12-02 10:09:56 +00:00
|
|
|
)
|
|
|
|
add_custom_target(MultiMC_RUN_TESTS DEPENDS MultiMC_GENERATE_COVERAGE_HTML)
|
|
|
|
endif(MultiMC_CODE_COVERAGE)
|
|
|
|
|
2016-03-03 00:40:12 +00:00
|
|
|
|
2014-01-05 22:24:05 +00:00
|
|
|
set(MultiMC_TEST_DATA_PATH "${CMAKE_CURRENT_BINARY_DIR}/data")
|
2016-03-03 00:40:12 +00:00
|
|
|
set(MultiMC_TEST_DATA_PATH_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/data")
|
|
|
|
set(MultiMC_TEST_DATA_PATH_SOURCE_RAW "${CMAKE_CURRENT_SOURCE_DIR}/data_raw")
|
|
|
|
|
2014-01-05 22:24:05 +00:00
|
|
|
if(UNIX)
|
|
|
|
# on unix we get the third / from the filename
|
2016-03-03 21:47:41 +00:00
|
|
|
set(MultiMC_TEST_DATA_URL "file://${MultiMC_TEST_DATA_PATH}")
|
2014-01-05 22:24:05 +00:00
|
|
|
else()
|
|
|
|
# we don't on windows, so we have to add it ourselves
|
2016-03-03 21:47:41 +00:00
|
|
|
set(MultiMC_TEST_DATA_URL "file:///${MultiMC_TEST_DATA_PATH}")
|
2014-01-05 22:24:05 +00:00
|
|
|
endif()
|
2016-03-03 21:47:41 +00:00
|
|
|
|
|
|
|
# clean and replace test data
|
|
|
|
add_custom_command(
|
|
|
|
TARGET test_data
|
|
|
|
COMMAND ${CMAKE_COMMAND} -DMultiMC_TEST_DATA_URL=${MultiMC_TEST_DATA_URL} -DMultiMC_TEST_DATA_PATH=${MultiMC_TEST_DATA_PATH} -DMultiMC_TEST_DATA_PATH_SOURCE=${MultiMC_TEST_DATA_PATH_SOURCE} -DMultiMC_TEST_DATA_PATH_SOURCE_RAW=${MultiMC_TEST_DATA_PATH_SOURCE_RAW} -P ${CMAKE_CURRENT_SOURCE_DIR}/copy_tests.cmake
|
|
|
|
)
|
|
|
|
|
2014-01-05 22:24:05 +00:00
|
|
|
configure_file(test_config.h.in test_config.h @ONLY)
|