diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0b5bfc90..1061f911 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 00000000..0af7f730 --- /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 0f2d6ced..7eda1618 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 6e2b0d3c..de7d0e07 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 3ad504b0..10eede82 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 69dd38e7..cf59f3e2 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 42d44e77..de1ad718 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()