NOISSUE remove dead unit tests and reorganize CMake code related to unit tests

This commit is contained in:
Petr Mrázek 2016-04-13 01:24:55 +02:00
parent ed3884fd38
commit e8ba5dafc6
15 changed files with 159 additions and 127 deletions

49
cmake/UnitTest.cmake Normal file
View File

@ -0,0 +1,49 @@
find_package(Qt5Test REQUIRED)
set(TEST_RESOURCE_PATH ${CMAKE_CURRENT_LIST_DIR})
message(${TEST_RESOURCE_PATH})
function(add_unit_test name)
set(options "")
set(oneValueArgs DATA)
set(multiValueArgs SOURCES LIBS QT)
cmake_parse_arguments(OPT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
if(WIN32)
add_executable(tst_${name} ${OPT_SOURCES} ${TEST_RESOURCE_PATH}/UnitTest/test.rc)
else()
add_executable(tst_${name} ${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()
# 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(tst_${name} ${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()
target_link_libraries(tst_${name} ${OPT_LIBS})
qt5_use_modules(tst_${name} Test ${OPT_QT})
target_include_directories(tst_${name} PRIVATE "${TEST_RESOURCE_PATH}/UnitTest/")
add_test(NAME ${name} COMMAND tst_${name})
endfunction()

View File

@ -5,7 +5,8 @@
#include <QTest>
#include <QDir>
#include "test_config.h"
#define expandstr(s) expandstr2(s)
#define expandstr2(s) #s
class TestsInternal
{

View File

@ -0,0 +1,26 @@
# Copy files from source directory to destination directory, substituting any
# variables. Create destination directory if it does not exist.
function(configure_files srcDir destDir)
message(STATUS "Configuring directory ${destDir} from ${srcDir}")
make_directory(${destDir})
file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*)
foreach(templateFile ${templateFiles})
set(srcTemplatePath ${srcDir}/${templateFile})
if(NOT IS_DIRECTORY ${srcTemplatePath})
message(STATUS "Configuring file ${templateFile}")
configure_file(
${srcTemplatePath}
${destDir}/${templateFile}
@ONLY
NEWLINE_STYLE LF
)
else()
message(STATUS "Recursing? ${srcTemplatePath}")
configure_files("${srcTemplatePath}" "${destDir}/${templateFile}")
endif()
endforeach()
endfunction()
configure_files(${SOURCE} ${DESTINATION})

View File

@ -1,66 +1,82 @@
# run the unit tests with `make test`
find_package(Qt5Test)
include(UnitTest)
add_custom_target(test_data)
add_unit_test(gradlespecifier
SOURCES tst_gradlespecifier.cpp
LIBS MultiMC_logic
)
unset(MultiMC_TESTS)
macro(add_unit_test name)
unset(srcs)
foreach(arg ${testname} ${ARGN})
list(APPEND srcs ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
endforeach()
if(WIN32)
list(APPEND srcs ${CMAKE_CURRENT_SOURCE_DIR}/test.rc)
endif()
add_executable(tst_${name} ${srcs})
add_dependencies(tst_${name} test_data)
target_link_libraries(tst_${name} MultiMC_logic)
qt5_use_modules(tst_${name} Test Core Network)
list(APPEND MultiMC_TESTS tst_${name})
add_test(NAME ${name} COMMAND tst_${name})
endmacro()
add_unit_test(userutils
SOURCES tst_userutils.cpp
LIBS MultiMC_logic
)
# Tests BEGIN #
add_unit_test(modutils
SOURCES tst_modutils.cpp
LIBS MultiMC_logic
)
add_unit_test(gradlespecifier tst_gradlespecifier.cpp)
add_unit_test(userutils tst_userutils.cpp)
add_unit_test(modutils tst_modutils.cpp)
add_unit_test(inifile tst_inifile.cpp)
add_unit_test(FileSystem tst_FileSystem.cpp)
add_unit_test(Library tst_Library.cpp)
add_unit_test(UpdateChecker tst_UpdateChecker.cpp)
add_unit_test(DownloadTask tst_DownloadTask.cpp)
add_unit_test(filematchers tst_filematchers.cpp)
add_unit_test(ModList tst_ModList.cpp)
# add_unit_test(Resource tst_Resource.cpp)
add_unit_test(GZip tst_GZip.cpp)
add_unit_test(JavaVersion tst_JavaVersion.cpp)
add_unit_test(ParseUtils tst_ParseUtils.cpp)
add_unit_test(MojangVersionFormat tst_MojangVersionFormat.cpp)
add_unit_test(BaseWonkoEntityLocalLoadTask tst_BaseWonkoEntityLocalLoadTask.cpp)
add_unit_test(BaseWonkoEntityRemoteLoadTask tst_BaseWonkoEntityRemoteLoadTask.cpp)
add_unit_test(WonkoVersionList tst_WonkoVersionList.cpp)
add_unit_test(WonkoIndex tst_WonkoIndex.cpp)
add_unit_test(inifile
SOURCES tst_inifile.cpp
LIBS MultiMC_logic
)
# Tests END #
add_unit_test(FileSystem
SOURCES tst_FileSystem.cpp
LIBS MultiMC_logic
)
add_unit_test(Library
SOURCES tst_Library.cpp
LIBS MultiMC_logic
)
set(MultiMC_TEST_DATA_PATH "${CMAKE_CURRENT_BINARY_DIR}/data")
set(MultiMC_TEST_DATA_PATH_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/data")
set(MultiMC_TEST_DATA_PATH_SOURCE_RAW "${CMAKE_CURRENT_SOURCE_DIR}/data_raw")
add_unit_test(UpdateChecker
SOURCES tst_UpdateChecker.cpp
LIBS MultiMC_logic
DATA data
)
if(UNIX)
# on unix we get the third / from the filename
set(MultiMC_TEST_DATA_URL "file://${MultiMC_TEST_DATA_PATH}")
else()
# we don't on windows, so we have to add it ourselves
set(MultiMC_TEST_DATA_URL "file:///${MultiMC_TEST_DATA_PATH}")
endif()
add_unit_test(DownloadTask
SOURCES tst_DownloadTask.cpp
LIBS MultiMC_logic
DATA data_raw
)
# 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
)
add_unit_test(filematchers
SOURCES tst_filematchers.cpp
LIBS MultiMC_logic
)
configure_file(test_config.h.in test_config.h @ONLY)
add_unit_test(ModList
SOURCES tst_ModList.cpp
LIBS MultiMC_logic
)
# add_unit_test(Resource
# SOURCES tst_Resource.cpp
# )
add_unit_test(GZip
SOURCES tst_GZip.cpp
LIBS MultiMC_logic
)
add_unit_test(JavaVersion
SOURCES tst_JavaVersion.cpp
LIBS MultiMC_logic
)
add_unit_test(ParseUtils
SOURCES tst_ParseUtils.cpp
LIBS MultiMC_logic
)
add_unit_test(MojangVersionFormat
SOURCES tst_MojangVersionFormat.cpp
LIBS MultiMC_logic
)
add_unit_test(WonkoIndex
SOURCES tst_WonkoIndex.cpp
LIBS MultiMC_logic
)

View File

@ -1,13 +0,0 @@
file(GLOB data_files "${MultiMC_TEST_DATA_PATH_SOURCE}/*")
foreach(data_file ${data_files})
get_filename_component(filename ${data_file} NAME)
configure_file(
${data_file}
${MultiMC_TEST_DATA_PATH}/${filename}
@ONLY
NEWLINE_STYLE LF
)
endforeach()
file(GLOB raw_data_files "${MultiMC_TEST_DATA_PATH_SOURCE_RAW}/*")
file(COPY ${raw_data_files} DESTINATION ${MultiMC_TEST_DATA_PATH}/)

View File

@ -8,7 +8,7 @@
"Sources": [
{
"SourceType": "http",
"Url": "@MultiMC_TEST_DATA_URL@/fileOneA"
"Url": "@TEST_DATA_URL@/fileOneA"
}
],
"Executable": true,
@ -20,7 +20,7 @@
"Sources": [
{
"SourceType": "http",
"Url": "@MultiMC_TEST_DATA_URL@/fileTwo"
"Url": "@TEST_DATA_URL@/fileTwo"
}
],
"Executable": false,
@ -32,7 +32,7 @@
"Sources": [
{
"SourceType": "http",
"Url": "@MultiMC_TEST_DATA_URL@/fileThree"
"Url": "@TEST_DATA_URL@/fileThree"
}
],
"Executable": false,

View File

@ -8,7 +8,7 @@
"Sources": [
{
"SourceType": "http",
"Url": "@MultiMC_TEST_DATA_URL@/fileOneB"
"Url": "@TEST_DATA_URL@/fileOneB"
}
],
"Executable": true,
@ -20,7 +20,7 @@
"Sources": [
{
"SourceType": "http",
"Url": "@MultiMC_TEST_DATA_URL@/fileTwo"
"Url": "@TEST_DATA_URL@/fileTwo"
}
],
"Executable": false,

View File

@ -5,13 +5,13 @@
"id": "develop",
"name": "Develop",
"description": "The channel called \"develop\"",
"url": "@MultiMC_TEST_DATA_URL@"
"url": "@TEST_DATA_URL@"
},
{
"id": "stable",
"name": "Stable",
"description": "It's stable at least",
"url": "@MultiMC_TEST_DATA_URL@"
"url": "@TEST_DATA_URL@"
},
{
"id": "42",

View File

@ -1,3 +0,0 @@
#pragma once
#define MultiMC_TEST_DATA_URL "@MultiMC_TEST_DATA_URL@"

View File

@ -1,15 +0,0 @@
#include <QTest>
#include "TestUtil.h"
#include "wonko/tasks/BaseWonkoEntityLocalLoadTask.h"
class BaseWonkoEntityLocalLoadTaskTest : public QObject
{
Q_OBJECT
private
slots:
};
QTEST_GUILESS_MAIN(BaseWonkoEntityLocalLoadTaskTest)
#include "tst_BaseWonkoEntityLocalLoadTask.moc"

View File

@ -1,15 +0,0 @@
#include <QTest>
#include "TestUtil.h"
#include "wonko/tasks/BaseWonkoEntityRemoteLoadTask.h"
class BaseWonkoEntityRemoteLoadTaskTest : public QObject
{
Q_OBJECT
private
slots:
};
QTEST_GUILESS_MAIN(BaseWonkoEntityRemoteLoadTaskTest)
#include "tst_BaseWonkoEntityRemoteLoadTask.moc"

View File

@ -8,6 +8,7 @@ Q_DECLARE_METATYPE(UpdateChecker::ChannelListEntry)
bool operator==(const UpdateChecker::ChannelListEntry &e1, const UpdateChecker::ChannelListEntry &e2)
{
qDebug() << e1.url << "vs" << e2.url;
return e1.id == e2.id &&
e1.name == e2.name &&
e1.description == e2.description &&
@ -76,8 +77,8 @@ slots:
<< true
<< true
<< (QList<UpdateChecker::ChannelListEntry>()
<< UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", MultiMC_TEST_DATA_URL}
<< UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", MultiMC_TEST_DATA_URL}
<< UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", findTestDataUrl("tests/data")}
<< UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", findTestDataUrl("tests/data")}
<< UpdateChecker::ChannelListEntry{"42", "The Channel", "This is the channel that is going to answer all of your questions", "https://dent.me/tea"});
}
void tst_ChannelListParsing()

View File

@ -1,15 +0,0 @@
#include <QTest>
#include "TestUtil.h"
#include "wonko/WonkoVersionList.h"
class WonkoVersionListTest : public QObject
{
Q_OBJECT
private
slots:
};
QTEST_GUILESS_MAIN(WonkoVersionListTest)
#include "tst_WonkoVersionList.moc"