-
Notifications
You must be signed in to change notification settings - Fork 131
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
QtTest driver v3 #165
QtTest driver v3 #165
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick scan through the source, definitely didn't look at everything yet.
The failing tests on Travis are a bit worrying.
CMakeLists.txt
Outdated
@@ -122,8 +122,13 @@ if(NOT CUKE_DISABLE_QT) | |||
find_package(Qt5Test) | |||
|
|||
if(${Qt5Core_FOUND} AND ${Qt5Widgets_FOUND} AND ${Qt5Test_FOUND}) | |||
set(QT5_FOUND true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just check for Qt5TEST_FOUND
instead where you need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course
CMakeLists.txt
Outdated
message(STATUS "Found Qt version: ${Qt5Core_VERSION_STRING}") | ||
set(QT_LIBRARIES Qt5::Core Qt5::Widgets Qt5::Test) | ||
if(NOT ${Qt5Core_VERSION_STRING} VERSION_LESS 5.7) | ||
message(STATUS "C++11 is needed from Qt version 5.7.0, building with c++11 enabled") | ||
set(CMAKE_CXX_STANDARD 11) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This precludes building as C++14 or 17. You could instead use target_compile_features(cucumber-cpp PUBLIC ${some_CXX11_features_that_Qt_5_7_uses})
where that list of features that you require are a subset of CMAKE_CXX_KNOWN_FEATURES.
Or an easier approach may be to write it like this to prevent overriding the user-requested C++ version:
if(NOT Qt5Core_VERSION_STRING VERSION_LESS 5.7
AND (NOT DEFINED CMAKE_CXX_STANDARD OR NOT CMAKE_CXX_STANDARD STREQUAL 98))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll go for the second version :)
examples/CalcQt/CMakeLists.txt
Outdated
if(QT5_FOUND) | ||
add_executable(QtTestCalculatorQtSteps features/step_definitions/QtTestCalculatorQtSteps) | ||
set_target_properties(QtTestCalculatorQtSteps PROPERTIES AUTOMOC ON) | ||
target_include_directories(QtTestCalculatorQtSteps PUBLIC src) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make that PRIVATE instead. PUBLIC is generally only useful for libraries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy-paste issue :)
examples/CalcQt/CMakeLists.txt
Outdated
add_executable(QtTestCalculatorQtSteps features/step_definitions/QtTestCalculatorQtSteps) | ||
set_target_properties(QtTestCalculatorQtSteps PROPERTIES AUTOMOC ON) | ||
target_include_directories(QtTestCalculatorQtSteps PUBLIC src) | ||
target_link_libraries(QtTestCalculatorQtSteps libcalcqt ${QT_LIBRARIES} ${CUKE_LIBRARIES}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add PRIVATE
between the target and the libraries it links to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok - didn't know it is necessary
Q_OBJECT | ||
public: | ||
QtTestObject(QtTestStep* qtTestStep): step(qtTestStep) {} | ||
virtual ~QtTestObject() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're requiring C++11 anyway, correct?
Then please use
virtual ~QtTestObject() = default;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only for Qt > 5.7, which is not the case for instance on our travis linux instances
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, thanks for clearing this up.
examples/CalcQt/CMakeLists.txt
Outdated
@@ -12,8 +12,8 @@ if(QT_LIBRARIES) | |||
if(Qt5TEST_FOUND) | |||
add_executable(QtTestCalculatorQtSteps features/step_definitions/QtTestCalculatorQtSteps) | |||
set_target_properties(QtTestCalculatorQtSteps PROPERTIES AUTOMOC ON) | |||
target_include_directories(QtTestCalculatorQtSteps PUBLIC src) | |||
target_link_libraries(QtTestCalculatorQtSteps libcalcqt ${QT_LIBRARIES} ${CUKE_LIBRARIES}) | |||
target_include_directories(QtTestCalculatorQtSteps PRIVATE src) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this again. You're probably adding this for the examples/CalcQt/src/CalculatorWidget.h
file. But that's already reachable because you're linking to libcalcqt
. I.e. CMake propagates the usage requirement of libcalcqt
to this target. You shouldn't need this entire target_include_directories
directive.
@muggenhor - any idea why first appveyor build failed? |
All green at last! And rebased onto master + squashed all commits. @muggenhor please re-review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really well done, just one CMake remark and a few nitpicks.
src/CMakeLists.txt
Outdated
qt5_wrap_cpp(MOC_FILE ../include/cucumber-cpp/internal/drivers/QtTestDriver.hpp) | ||
list(APPEND CUKE_SOURCES ${MOC_FILE}) | ||
list(APPEND CUKE_SOURCES drivers/QtTestDriver.cpp) | ||
list(APPEND CUKE_DEP_LIBRARIES ${QT_LIBRARIES}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only add Qt5::Test
, the rest isn't necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right
src/drivers/QtTestDriver.cpp
Outdated
|
||
const InvokeResult QtTestStep::invokeStepBody() { | ||
QTemporaryFile file; | ||
QString fileName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot about it :)
src/drivers/QtTestDriver.cpp
Outdated
|
||
QtTestObject testObject(this); | ||
int returnValue = QTest::qExec(&testObject, QStringList() << "test" << "-o" << file.fileName()); | ||
if(returnValue == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space between if
and opening brace please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, we need that clang-format PR merged :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can copy the .clang-format
file from that PR into your local working copy and execute this to format everything changes since master (replace origin/master with the most recent commit of the master branch that you based your changes on).:
git clang-format-3.8 --binary=/usr/bin/clang-format-3.8 --style=file --commit=origin/master
class QtTestStepDouble : public QtTestStep { | ||
public: | ||
QtTestStepDouble() : QtTestStep() { | ||
testRun = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize this member var in the initializer list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Q_OBJECT | ||
public: | ||
QtTestObject(QtTestStep* qtTestStep): step(qtTestStep) {} | ||
virtual ~QtTestObject() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, thanks for clearing this up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some clang-format
inspired changes
@@ -0,0 +1,4 @@ | |||
#include <QTest> | |||
// Pretend to be GTest | |||
#define EXPECT_EQ QCOMPARE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove whitespace from the end of the line.
namespace cucumber { | ||
namespace internal { | ||
|
||
class QtTestStep : public BasicStep{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need a space between the base class and opening curly brace
|
||
class QtTestStep : public BasicStep{ | ||
friend class QtTestObject; | ||
public: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need an empty line before the access label
class QtTestStep : public BasicStep{ | ||
friend class QtTestObject; | ||
public: | ||
QtTestStep(): BasicStep() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space between braces and colon
|
||
#define STEP_INHERITANCE(step_name) ::cucumber::internal::QtTestStep | ||
|
||
class QtTestObject: public QObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space before colon
class QtTestObject: public QObject { | ||
Q_OBJECT | ||
public: | ||
QtTestObject(QtTestStep* qtTestStep): step(qtTestStep) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space before colon
src/drivers/QtTestDriver.cpp
Outdated
QtTestObject testObject(this); | ||
int returnValue = QTest::qExec(&testObject, QStringList() << "test" << "-o" << file.fileName()); | ||
if (returnValue == 0) | ||
return InvokeResult::success(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put curly braces around this statement (using different styles for the if
and else
branch is inconsistent).
src/drivers/QtTestDriver.cpp
Outdated
file.close(); | ||
|
||
QtTestObject testObject(this); | ||
int returnValue = QTest::qExec(&testObject, QStringList() << "test" << "-o" << file.fileName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format
suggests this instead, and I like it.
int returnValue = QTest::qExec(&testObject,
QStringList() << "test"
<< "-o"
<< file.fileName());
QtTestDriverTest test; | ||
return test.run(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please no empty line at end of file
|
||
class QtTestStepDouble : public QtTestStep { | ||
public: | ||
QtTestStepDouble() : QtTestStep(), testRun(false) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No space between curly braces
I've applied all those format changes, I'll rebase/squash now |
examples/Calc/CMakeLists.txt
Outdated
|
||
if(Qt5TEST_FOUND) | ||
add_executable(QtTestCalculatorSteps features/step_definitions/QtTestCalculatorSteps) | ||
target_link_libraries(QtTestCalculatorSteps Calc ${QT_LIBRARIES} ${CUKE_LIBRARIES}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can replace ${QT_LIBRARIES}
with Qt5::Test
here as you only need the test framework, not the GUI stuff.
examples/CalcQt/CMakeLists.txt
Outdated
@@ -9,12 +9,20 @@ if(QT_LIBRARIES) | |||
add_executable(calcqt src/CalcQt.cpp) | |||
target_link_libraries(calcqt libcalcqt ${QT_LIBRARIES}) | |||
|
|||
if(Qt5TEST_FOUND) | |||
add_executable(QtTestCalculatorQtSteps features/step_definitions/QtTestCalculatorQtSteps) | |||
set_target_properties(QtTestCalculatorQtSteps PROPERTIES AUTOMOC ON) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you enable AUTOMOC for this? I don't see any moc-able object in your one source file.
class QtTestObject : public QObject { | ||
Q_OBJECT | ||
public: | ||
QtTestObject(QtTestStep* qtTestStep): step(qtTestStep) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space before colon
Squashed and rebased - I think it's ready for merge. @muggenhor do you agree? |
Build is failing due to #169 |
Implementation based on temporary file. When building QtTest driver C++11 is enabled globally to prevent issue cucumber#141.
Ok, rebased and it's all green now. Any more comments or shall I merge? |
hi! |
@konserw great contribution! |
Nice work @konserw ! |
Summary
QtTest based test driver for cucumber-cpp.
Details
Implementation based on temporary file.
When building QtTest driver C++11 is enabled globally to prevent issue #141.
Motivation and Context
It's useful for projects written in Qt.
It is third revision of this driver.
How Has This Been Tested?
Unit test is included as well as steps for examples.
Types of changes
Checklist: