Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ endif()
#

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} -Werror -Wall -Wextra -Wsuggest-override ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} -Wall -Wextra -Wsuggest-override ${CMAKE_CXX_FLAGS}")
# TODO: A better fix should handle ld's --as-needed flag
if(UNIX AND NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker '--no-as-needed'")
Expand Down Expand Up @@ -165,15 +165,12 @@ if(CUKE_ENABLE_QT_5)

message(STATUS "Found Qt version: ${Qt5Core_VERSION_STRING}")
if(Qt5Core_VERSION_STRING VERSION_LESS 5.15.0)
add_library(Qt::Core INTERFACE IMPORTED)
add_library(Qt::Gui INTERFACE IMPORTED)
add_library(Qt::Widgets INTERFACE IMPORTED)
add_library(Qt::Test INTERFACE IMPORTED)
set_target_properties(Qt::Core PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Core )
set_target_properties(Qt::Gui PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Gui )
set_target_properties(Qt::Widgets PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Widgets)
set_target_properties(Qt::Test PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Test )
add_library( Qt::Core ALIAS Qt5::Core)
add_library( Qt::Gui ALIAS Qt5::Gui)
add_library( Qt::Widgets ALIAS Qt5::Widgets)
add_library( Qt::Test ALIAS Qt5::Test)
endif()
set( CUKE_QT_RUNTIME_PATH $<TARGET_FILE_DIR:Qt5::Test> )
endif()

if(CUKE_ENABLE_QT_6)
Expand All @@ -185,6 +182,7 @@ if(CUKE_ENABLE_QT_6)
)

message(STATUS "Found Qt version: ${Qt6Core_VERSION}")
set( CUKE_QT_RUNTIME_PATH $<TARGET_FILE_DIR:Qt6::Test> )
endif()


Expand Down
1 change: 1 addition & 0 deletions run-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cmake -E chdir build cmake \
-DCUKE_ENABLE_BOOST_TEST=on \
-DCUKE_ENABLE_GTEST=on \
-DCUKE_ENABLE_QT_6=on \
-DCUKE_ENABLE_QT_5=off \
-DCUKE_ENABLE_EXAMPLES=on \
-DCUKE_TESTS_UNIT=on \
-DCUKE_CODE_COVERAGE=on \
Expand Down
68 changes: 63 additions & 5 deletions run-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ $cmake_params = "-E chdir build cmake",
$cmake_params += "-DCMAKE_CXX_STANDARD=${cpp_standard}"

$cmake_params += "-DCUKE_ENABLE_BOOST_TEST=OFF"
$cmake_params += "-DCUKE_ENABLE_GTEST=OFF"
$cmake_params += "-DCUKE_ENABLE_GTEST=ON"
$cmake_params += "-DCUKE_ENABLE_QT_6=OFF"
$cmake_params += "-DCUKE_ENABLE_EXAMPLES=OFF"
$cmake_params += "-DCUKE_TESTS_UNIT=OFF"
$cmake_params += "-DCUKE_ENABLE_QT_5=ON"
$cmake_params += "-DCUKE_ENABLE_EXAMPLES=ON"
$cmake_params += "-DCUKE_TESTS_UNIT=ON"
$cmake_params += "-DCUKE_CODE_COVERAGE=OFF"

$cmake_params += "-Dnlohmann_json_DIR=${nlohmann_json_DIR}"
Expand All @@ -61,6 +62,63 @@ $cmake_params += "-DTCLAP_ROOT=${TCLAP_ROOT}"

$cmake_params += ".."


Invoke-CMake "$cmake_params"
Invoke-CMake "--build","build" #,"--parallel"
Invoke-CMake "--build","build","--config","Release" #,"--parallel"
Invoke-CMake "--build","build","--config","Release","--target","RUN_TESTS"

#
# Execute Calc examples
#

$CalcTests = @("build\examples\Calc\Release\GTestCalculatorSteps.exe",
"build\examples\Calc\Release\BoostCalculatorSteps.exe",
"build\examples\Calc\Release\FuncArgsCalculatorSteps.exe")

If ((Get-Command "qmake.exe" -ErrorAction SilentlyContinue) -ne $null)
{
$CalcTests += "build\examples\Calc\Release\QtTestCalculatorSteps.exe"
}

For ($i=0; $i -lt $CalcTests.Length; $i++) {
If (Test-Path -path $CalcTests[$i] -PathType Leaf) {
Write-Host "Start Test $($CalcTests[$i])" -f Green
Start-Process -NoNewWindow $CalcTests[$i]
Start-Sleep -Seconds 1.0
Set-Location -Path 'examples/Calc'
Start-Process cucumber -NoNewWindow -Wait
set-Location -Path $PSScriptRoot
} Else {
Write-Host "Skipping $($CalcTests[$i]): file not exisiting" -f Yellow
}
}
#
# Execute QtCalc examples
#

If ((Get-Command "qmake.exe" -ErrorAction SilentlyContinue) -eq $null)
{
Write-Host "Qt not found in PATH, skipping QtCalc Tests" -f Yellow
}
Else
{
$QtCalcTests = @("build\examples\CalcQt\Release\GTestCalculatorQtSteps.exe",
"build\examples\CalcQt\Release\QtTestCalculatorQtSteps.exe",
"build\examples\CalcQt\Release\BoostCalculatorQtSteps.exe")

For ($i=0; $i -lt $QtCalcTests.Length; $i++) {
If (Test-Path -path $QtCalcTests[$i] -PathType Leaf) {
Write-Host "Start Test $($QtCalcTests[$i])" -f Green
Start-Process -NoNewWindow $QtCalcTests[$i]
Start-Sleep -Seconds 1.0
Set-Location -Path 'examples/CalcQt'
Start-Process cucumber -NoNewWindow -Wait
set-Location -Path $PSScriptRoot
} Else {
Write-Host "Skipping $($QtCalcTests[$i]): file not exisiting" -f Yellow
}
}
}

Invoke-CMake "--build","build","--config","Release","--target","INSTALL"


67 changes: 60 additions & 7 deletions src/drivers/QtTestDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,81 @@
#include <QTextStream>
#include <QTemporaryFile>

#include <iostream>

namespace cucumber {
namespace internal {

// wraps the QTemporaryFile creation
// on Windows the file could not be written as long as QTemporaryFile owner of the file.
Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling, I'd suggest (but I'm not a native speaker):

// Wraps the QTemporaryFile creation.
// Needed because on Windows, the file can not be written from QtTest as long as we keep it open.


class TemporaryFileWrapper {
public:
static TemporaryFileWrapper create() {
QTemporaryFile tempFile(QString("%1/%2_%3")
.arg(
QDir::tempPath(),
qApp->applicationName().isEmpty() ? "qt_temp"
: qApp->applicationName()
)
.arg(qApp->applicationPid()));

if (!tempFile.open()) {
return {};
}

return {tempFile.fileName() + ".txt"};
}

TemporaryFileWrapper() :
filename{} {
}

TemporaryFileWrapper(QString filename) :
filename{filename} {
}

~TemporaryFileWrapper() {
QFile::remove(filename);
}

bool exists() const {
return !filename.isEmpty();
}

QString name() const {
return filename;
}

QString read() const {
QFile file{filename};
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return QString();
QTextStream in(&file);
return in.readAll();
}

private:
QString filename;
};

const InvokeResult QtTestStep::invokeStepBody() {
QTemporaryFile file;
if (!file.open()) {
const auto file = TemporaryFileWrapper::create();
if (!file.exists()) {
return InvokeResult::failure("Unable to open temporary file needed for this test");
}
file.close();

QtTestObject testObject(this);
int returnValue = QTest::qExec(
&testObject,
QStringList() << "test"
<< "-o" << file.fileName()
<< "-o" << file.name()
);

if (returnValue == 0) {
return InvokeResult::success();
} else {
file.open();
QTextStream ts(&file);
return InvokeResult::failure(ts.readAll().toLocal8Bit());
return InvokeResult::failure(file.read().toLocal8Bit());
Comment on lines +66 to +81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

}
}

Expand Down
33 changes: 33 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ target_include_directories(utils INTERFACE
.
)

function(cuke_set_environment environment)
set(options)
set(oneValueArgs )
set(multiValueArgs RUNPATH BINPATH)

cmake_parse_arguments(CUKE_ENV "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT "${CUKE_ENV_UNPARSED_ARGUMENTS}" STREQUAL "")
message(
FATAL_ERROR
"unparsed arguments in call to cuke_set_environment: ${CUKE_ENV_UNPARSED_ARGUMENTS} from ${CMAKE_CURRENT_LIST_FILE}"
)
endif()

if( NOT "${CUKE_ENV_RUNPATH}" STREQUAL "")
if(WIN32)
string(REPLACE ";" "\;" CUKE_ENV_RUNPATH "${CUKE_ENV_RUNPATH}")
endif()
set(RUNPATH "$<IF:$<PLATFORM_ID:Windows>,PATH,LD_LIBRARY_PATH>")
list(APPEND environment "$<IF:$<PLATFORM_ID:Windows>,PATH,LD_LIBRARY_PATH>=path_list_prepend:$<SHELL_PATH:${CUKE_ENV_RUNPATH}>")
endif()
if( NOT "${CUKE_ENV_BINPATH}" STREQUAL "")
if(WIN32)
string(REPLACE ";" "\;" CUKE_ENV_BINPATH "${CUKE_ENV_BINPATH}")
endif()
list(APPEND environment "PATH=path_list_prepend:$<SHELL_PATH:${CUKE_ENV_BINPATH}>")
endif()

set(${environment} ${${environment}} PARENT_SCOPE)
endfunction()

function(cuke_add_driver_test TEST_FILE)
get_filename_component(TEST_NAME ${TEST_FILE} NAME)
message(STATUS "Adding " ${TEST_NAME})
Expand Down Expand Up @@ -63,6 +94,8 @@ if((TARGET Qt::Test)
AND (NOT VALGRIND_TESTS)
)
cuke_add_driver_test(integration/drivers/QtTestDriverTest Qt::Test)
cuke_set_environment( QTTEST_ENVIRONMENT RUNPATH "${CUKE_QT_RUNTIME_PATH}" )
set_tests_properties(QtTestDriverTest PROPERTIES ENVIRONMENT_MODIFICATION ${QTTEST_ENVIRONMENT})
endif()

cuke_add_driver_test(integration/drivers/GenericDriverTest)