From 3d8728f52f220845fc4079d34b97458a122ac031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 3 Mar 2016 22:47:41 +0100 Subject: [PATCH] NOISSUE no issue. with unit tests. --- tests/CMakeLists.txt | 20 +++++++++----------- tests/copy_tests.cmake | 13 +++++++++++++ tests/data/1.json | 6 +++--- tests/data/2.json | 4 ++-- tests/data/channels.json | 4 ++-- tests/test_config.h.in | 2 +- tests/tst_UpdateChecker.cpp | 4 ++-- 7 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 tests/copy_tests.cmake diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0b5bfc907..1061f9111 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -100,20 +100,18 @@ 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") +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() + # clean and replace test data add_custom_command( TARGET test_data - COMMAND ${CMAKE_COMMAND} -E remove_directory ${MultiMC_TEST_DATA_PATH} - COMMAND ${CMAKE_COMMAND} -E copy_directory ${MultiMC_TEST_DATA_PATH_SOURCE} ${MultiMC_TEST_DATA_PATH} - COMMAND ${CMAKE_COMMAND} -E copy_directory ${MultiMC_TEST_DATA_PATH_SOURCE_RAW} ${MultiMC_TEST_DATA_PATH} + 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 ) -message("${CMAKE_CURRENT_BINARY_DIR}/data") -if(UNIX) - # on unix we get the third / from the filename - set(MultiMC_TEST_DATA_PATH "file://${MultiMC_TEST_DATA_PATH}") -else() - # we don't on windows, so we have to add it ourselves - set(MultiMC_TEST_DATA_PATH "file:///${MultiMC_TEST_DATA_PATH}") -endif() configure_file(test_config.h.in test_config.h @ONLY) diff --git a/tests/copy_tests.cmake b/tests/copy_tests.cmake new file mode 100644 index 000000000..0af7f7309 --- /dev/null +++ b/tests/copy_tests.cmake @@ -0,0 +1,13 @@ +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}/) diff --git a/tests/data/1.json b/tests/data/1.json index 0f2d6cede..7eda16185 100644 --- a/tests/data/1.json +++ b/tests/data/1.json @@ -8,7 +8,7 @@ "Sources": [ { "SourceType": "http", - "Url": "@MultiMC_TEST_DATA_PATH@/fileOneA" + "Url": "@MultiMC_TEST_DATA_URL@/fileOneA" } ], "Executable": true, @@ -20,7 +20,7 @@ "Sources": [ { "SourceType": "http", - "Url": "@MultiMC_TEST_DATA_PATH@/fileTwo" + "Url": "@MultiMC_TEST_DATA_URL@/fileTwo" } ], "Executable": false, @@ -32,7 +32,7 @@ "Sources": [ { "SourceType": "http", - "Url": "@MultiMC_TEST_DATA_PATH@/fileThree" + "Url": "@MultiMC_TEST_DATA_URL@/fileThree" } ], "Executable": false, diff --git a/tests/data/2.json b/tests/data/2.json index 6e2b0d3c5..de7d0e077 100644 --- a/tests/data/2.json +++ b/tests/data/2.json @@ -8,7 +8,7 @@ "Sources": [ { "SourceType": "http", - "Url": "@MultiMC_TEST_DATA_PATH@/fileOneB" + "Url": "@MultiMC_TEST_DATA_URL@/fileOneB" } ], "Executable": true, @@ -20,7 +20,7 @@ "Sources": [ { "SourceType": "http", - "Url": "@MultiMC_TEST_DATA_PATH@/fileTwo" + "Url": "@MultiMC_TEST_DATA_URL@/fileTwo" } ], "Executable": false, diff --git a/tests/data/channels.json b/tests/data/channels.json index 3ad504b05..10eede825 100644 --- a/tests/data/channels.json +++ b/tests/data/channels.json @@ -5,13 +5,13 @@ "id": "develop", "name": "Develop", "description": "The channel called \"develop\"", - "url": "@MultiMC_TEST_DATA_PATH@" + "url": "@MultiMC_TEST_DATA_URL@" }, { "id": "stable", "name": "Stable", "description": "It's stable at least", - "url": "@MultiMC_TEST_DATA_PATH@" + "url": "@MultiMC_TEST_DATA_URL@" }, { "id": "42", diff --git a/tests/test_config.h.in b/tests/test_config.h.in index 69dd38e7f..cf59f3e2c 100644 --- a/tests/test_config.h.in +++ b/tests/test_config.h.in @@ -1,3 +1,3 @@ #pragma once -#define MultiMC_TEST_DATA_PATH "@MultiMC_TEST_DATA_PATH@" +#define MultiMC_TEST_DATA_URL "@MultiMC_TEST_DATA_URL@" diff --git a/tests/tst_UpdateChecker.cpp b/tests/tst_UpdateChecker.cpp index 42d44e772..de1ad718c 100644 --- a/tests/tst_UpdateChecker.cpp +++ b/tests/tst_UpdateChecker.cpp @@ -76,8 +76,8 @@ slots: << true << true << (QList() - << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", MultiMC_TEST_DATA_PATH} - << UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", MultiMC_TEST_DATA_PATH} + << 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{"42", "The Channel", "This is the channel that is going to answer all of your questions", "https://dent.me/tea"}); } void tst_ChannelListParsing()