-
Notifications
You must be signed in to change notification settings - Fork 133
adding windows test driver fix #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
83c7559
8ec2b38
75e4b0f
cfd1cd4
6895dc0
dc83164
b9232fd
bcb880d
aa604ef
85903d2
6a18103
3ffd0b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())); | ||
kreuzberger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!tempFile.open()) { | ||
return {}; | ||
} | ||
|
||
return {tempFile.fileName() + ".txt"}; | ||
kreuzberger marked this conversation as resolved.
Show resolved
Hide resolved
kreuzberger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good 👍 |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,30 @@ target_include_directories(utils INTERFACE | |
. | ||
) | ||
|
||
function(cuke_set_environment environment) | ||
set(options) | ||
set(oneValueArgs ) | ||
set(multiValueArgs RUNPATH) | ||
|
||
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() | ||
set(${environment} ${${environment}} PARENT_SCOPE) | ||
endfunction() | ||
|
||
Comment on lines
+14
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a lot of code to just support Windows. Is it possible to move this to run-windows.ps1 (if it makes sense). @cwellm any ideas from your side? |
||
function(cuke_add_driver_test TEST_FILE) | ||
get_filename_component(TEST_NAME ${TEST_FILE} NAME) | ||
message(STATUS "Adding " ${TEST_NAME}) | ||
|
@@ -63,6 +87,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) |
Uh oh!
There was an error while loading. Please reload this page.