diff --git a/3rdparty/cucumber-cpp/src/main.cpp b/3rdparty/cucumber-cpp/src/main.cpp --- a/3rdparty/cucumber-cpp/src/main.cpp +++ b/3rdparty/cucumber-cpp/src/main.cpp @@ -12,7 +12,8 @@ WireProtocolHandler protocolHandler(&wireCodec, &cukeEngine); SocketServer server(&protocolHandler); server.listen(port); - server.acceptOnce(); + while (true) + server.acceptOnce(); } } diff --git a/tests/features/CMakeLists.txt b/tests/features/CMakeLists.txt --- a/tests/features/CMakeLists.txt +++ b/tests/features/CMakeLists.txt @@ -4,7 +4,4 @@ add_subdirectory(zanshin) add_subdirectory(renku) - include(CucumberTests.cmake) - cucumber_tests(zanshin renku) - endif() diff --git a/tests/features/CucumberTests.cmake b/tests/features/CucumberTests.cmake deleted file mode 100644 --- a/tests/features/CucumberTests.cmake +++ /dev/null @@ -1,49 +0,0 @@ -macro(cucumber_tests) - foreach(_testsuite ${ARGN}) - set(CUCUMBER_CWD ${CMAKE_CURRENT_SOURCE_DIR}/${_testsuite}) - set(cuke-steps "${CMAKE_CURRENT_BINARY_DIR}/${_testsuite}/features/step_definitions/${_testsuite}-cuke-steps 2>&1") - - - # cucumber with akonadi fake rules - configure_file(cucumber-run.sh.in ${_testsuite}/cucumber-run.sh) - set(cucumber-run-cmd sh ${CMAKE_CURRENT_BINARY_DIR}/${_testsuite}/cucumber-run.sh ${CMAKE_CURRENT_SOURCE_DIR}/testenv/data/testdata.xml) - - add_custom_target(cucumber-run-${_testsuite} - COMMAND ${cucumber-run-cmd} - WORKING_DIRECTORY ${CUCUMBER_CWD} - USES_TERMINAL - ) - - add_custom_target(cucumber-run-${_testsuite}-done - COMMAND ${cucumber-run-cmd} --tags ~@wip - WORKING_DIRECTORY ${CUCUMBER_CWD} - USES_TERMINAL - ) - - - # Default test target - add_test(${_testsuite}-features-done ${CMAKE_MAKE_PROGRAM} cucumber-run-${_testsuite}-done) - - - - # cucumber within akonaditest rules - configure_file(cucumber-akonadi-run.sh.in ${_testsuite}/cucumber-akonadi-run.sh) - find_program(_akonaditest akonaditest) - set(cucumber-akonadi-run-cmd ${_akonaditest} -c ${CMAKE_CURRENT_SOURCE_DIR}/testenv/config.xml sh ${CMAKE_CURRENT_BINARY_DIR}/${_testsuite}/cucumber-akonadi-run.sh 2> ${CMAKE_CURRENT_BINARY_DIR}/${_testsuite}/akonaditest.log) - - add_custom_target(cucumber-akonadi-run-${_testsuite} - COMMAND ${cucumber-akonadi-run-cmd} - WORKING_DIRECTORY ${CUCUMBER_CWD} - USES_TERMINAL - ) - - add_custom_target(cucumber-akonadi-run-${_testsuite}-done - COMMAND ${cucumber-akonadi-run-cmd} --tags ~@wip - WORKING_DIRECTORY ${CUCUMBER_CWD} - USES_TERMINAL - ) - - # Default test target - add_test(${_testsuite}-features-done ${CMAKE_MAKE_PROGRAM} -C ${CMAKE_BINARY_DIR} cucumber-run-${_testsuite}-done) - endforeach() -endmacro() diff --git a/tests/features/cucumber-akonadi-run.sh.in b/tests/features/cucumber-akonadi-run.sh.in deleted file mode 100644 --- a/tests/features/cucumber-akonadi-run.sh.in +++ /dev/null @@ -1,26 +0,0 @@ -#! /bin/sh - -_pwd=$PWD - -restorepwd() { - cd $_pwd -} - -trap "restorepwd" EXIT - -echo -echo "======================" -echo - -# Make sure the resource is fully synchronized -# It wasn't necessary until the big code style change in akonadiserver -# Not so innocuous heh ;-) -KNUT_RESOURCE="org.freedesktop.Akonadi.Resource.akonadi_knut_resource_0.$AKONADI_INSTANCE" -qdbus $KNUT_RESOURCE / org.freedesktop.Akonadi.Resource.synchronize - -cd @CUCUMBER_CWD@ -@cuke-steps@ & -sleep 2.0 - -cucumber $* -exit $? diff --git a/tests/features/cucumber-run.sh.in b/tests/features/cucumber-run.sh.in deleted file mode 100644 --- a/tests/features/cucumber-run.sh.in +++ /dev/null @@ -1,19 +0,0 @@ -#! /bin/sh - -_pwd=$PWD - -restorepwd() { - cd $_pwd -} - -trap "restorepwd" EXIT - -export ZANSHIN_USER_XMLDATA=$1 -shift - -cd @CUCUMBER_CWD@ -@cuke-steps@ & -sleep 2.0 - -cucumber $* -exit $? diff --git a/tests/features/features-run.cpp b/tests/features/features-run.cpp new file mode 100644 --- /dev/null +++ b/tests/features/features-run.cpp @@ -0,0 +1,87 @@ +/* This file is part of Zanshin + + Copyright 2016 Kevin Ottens + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include +#include +#include +#include +#include +#include + +class ProcessKiller +{ +public: + explicit ProcessKiller(QProcess *process) + : m_process(process) + { + } + + ~ProcessKiller() + { + m_process->kill(); + m_process->waitForFinished(); + } + +private: + QProcess *m_process; +}; + +bool waitForCukeSteps(qint64 timeout) +{ + QElapsedTimer timer; + timer.start(); + QTcpSocket socket; + + socket.connectToHost("localhost", 3902); + while (!socket.waitForConnected() && !timer.hasExpired(timeout)) { + socket.connectToHost("localhost", 3902); + } + + return socket.state() == QTcpSocket::ConnectedState; +} + +int main(int argc, char **argv) +{ + qputenv("ZANSHIN_USER_XMLDATA", USER_XMLDATA); + + QCoreApplication app(argc, argv); + Q_UNUSED(app); + + QDir::setCurrent(FEATURES_DIR); + + QProcess cukeSteps; + cukeSteps.setProcessChannelMode(QProcess::ForwardedChannels); + cukeSteps.start(CUKE_STEPS); + + ProcessKiller cukeStepsKiller(&cukeSteps); + Q_UNUSED(cukeStepsKiller); + + if (!waitForCukeSteps(10000)) { + qWarning() << "The cuke steps server didn't show up as expected, exiting..."; + return 1; + } + + const QStringList args = app.arguments().contains("wip") ? QStringList() + : QStringList({"--tags", "~@wip"}); + return QProcess::execute("cucumber", args); +} diff --git a/tests/features/renku/CMakeLists.txt b/tests/features/renku/CMakeLists.txt --- a/tests/features/renku/CMakeLists.txt +++ b/tests/features/renku/CMakeLists.txt @@ -1 +1,11 @@ add_subdirectory(features) + +add_executable(renku-features-run ../features-run.cpp) +add_test(renku-features-run renku-features-run) +add_definitions(-DUSER_XMLDATA="${CMAKE_CURRENT_SOURCE_DIR}/../testenv/data/testdata.xml" + -DCUKE_STEPS="${CMAKE_CURRENT_BINARY_DIR}/features/step_definitions/renku-cuke-steps" + -DFEATURES_DIR="${CMAKE_CURRENT_SOURCE_DIR}") +target_link_libraries(renku-features-run + Qt5::Core + Qt5::Network +) diff --git a/tests/features/zanshin/CMakeLists.txt b/tests/features/zanshin/CMakeLists.txt --- a/tests/features/zanshin/CMakeLists.txt +++ b/tests/features/zanshin/CMakeLists.txt @@ -1 +1,11 @@ add_subdirectory(features) + +add_executable(zanshin-features-run ../features-run.cpp) +add_test(zanshin-features-run zanshin-features-run) +add_definitions(-DUSER_XMLDATA="${CMAKE_CURRENT_SOURCE_DIR}/../testenv/data/testdata.xml" + -DCUKE_STEPS="${CMAKE_CURRENT_BINARY_DIR}/features/step_definitions/zanshin-cuke-steps" + -DFEATURES_DIR="${CMAKE_CURRENT_SOURCE_DIR}") +target_link_libraries(zanshin-features-run + Qt5::Core + Qt5::Network +)