Skip to content
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

Merged
merged 4 commits into from
Nov 4, 2017
Merged

QtTest driver v3 #165

merged 4 commits into from
Nov 4, 2017

Conversation

konserw
Copy link
Contributor

@konserw konserw commented Aug 23, 2017

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

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • It is my own work, its copyright is implicitly assigned to the project and no substantial part of it has been copied from other sources (including Stack Overflow). In rare occasions this is acceptable, like in CMake modules where the original copyright information should be kept.
  • I'm using the same code standards as the existing code (indentation, spacing, variable naming, ...).
  • I've added tests for my code.
  • I have verified whether my change requires changes to the documentation
  • My change either requires no documentation change or I've updated the documentation accordingly.
  • My branch has been rebased to master, keeping only relevant commits.

@konserw konserw mentioned this pull request Aug 23, 2017
@konserw konserw requested a review from muggenhor August 23, 2017 20:42
Copy link
Contributor

@muggenhor muggenhor left a 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)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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))

Copy link
Contributor Author

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 :)

if(QT5_FOUND)
add_executable(QtTestCalculatorQtSteps features/step_definitions/QtTestCalculatorQtSteps)
set_target_properties(QtTestCalculatorQtSteps PROPERTIES AUTOMOC ON)
target_include_directories(QtTestCalculatorQtSteps PUBLIC src)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy-paste issue :)

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})
Copy link
Contributor

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.

Copy link
Contributor Author

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() {}
Copy link
Contributor

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;

Copy link
Contributor Author

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

Copy link
Contributor

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.

@@ -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)
Copy link
Contributor

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.

@konserw
Copy link
Contributor Author

konserw commented Aug 24, 2017

@muggenhor - any idea why first appveyor build failed?

@konserw
Copy link
Contributor Author

konserw commented Aug 25, 2017

All green at last! And rebased onto master + squashed all commits. @muggenhor please re-review :)

Copy link
Contributor

@muggenhor muggenhor left a 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.

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})
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right


const InvokeResult QtTestStep::invokeStepBody() {
QTemporaryFile file;
QString fileName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot about it :)


QtTestObject testObject(this);
int returnValue = QTest::qExec(&testObject, QStringList() << "test" << "-o" << file.fileName());
if(returnValue == 0)
Copy link
Contributor

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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() {}
Copy link
Contributor

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.

Copy link
Contributor

@muggenhor muggenhor left a 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
Copy link
Contributor

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{
Copy link
Contributor

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:
Copy link
Contributor

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() {}
Copy link
Contributor

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 {
Copy link
Contributor

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) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

space before colon

QtTestObject testObject(this);
int returnValue = QTest::qExec(&testObject, QStringList() << "test" << "-o" << file.fileName());
if (returnValue == 0)
return InvokeResult::success();
Copy link
Contributor

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).

file.close();

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

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();
}

Copy link
Contributor

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) { }
Copy link
Contributor

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

@cucumber cucumber deleted a comment from coveralls Aug 25, 2017
@cucumber cucumber deleted a comment from coveralls Aug 25, 2017
@cucumber cucumber deleted a comment from coveralls Aug 25, 2017
@konserw
Copy link
Contributor Author

konserw commented Aug 25, 2017

I've applied all those format changes, I'll rebase/squash now

@cucumber cucumber deleted a comment from coveralls Aug 25, 2017
@cucumber cucumber deleted a comment from coveralls Aug 25, 2017

if(Qt5TEST_FOUND)
add_executable(QtTestCalculatorSteps features/step_definitions/QtTestCalculatorSteps)
target_link_libraries(QtTestCalculatorSteps Calc ${QT_LIBRARIES} ${CUKE_LIBRARIES})
Copy link
Contributor

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.

@@ -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)
Copy link
Contributor

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) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

missing space before colon

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 96.7% when pulling 1d34255 on konserw:qttest3 into 6551a0e on cucumber:master.

@cucumber cucumber deleted a comment from coveralls Sep 1, 2017
@cucumber cucumber deleted a comment from coveralls Sep 1, 2017
@cucumber cucumber deleted a comment from coveralls Sep 1, 2017
@konserw
Copy link
Contributor Author

konserw commented Sep 13, 2017

Squashed and rebased - I think it's ready for merge. @muggenhor do you agree?

@konserw
Copy link
Contributor Author

konserw commented Sep 13, 2017

Build is failing due to #169

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.003%) to 96.697% when pulling 89d5080 on konserw:qttest3 into 0928f25 on cucumber:master.

Implementation based on temporary file.
When building QtTest driver C++11 is enabled
globally to prevent issue cucumber#141.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 96.707% when pulling fe975ee on konserw:qttest3 into ec26000 on cucumber:master.

@konserw
Copy link
Contributor Author

konserw commented Oct 13, 2017

Ok, rebased and it's all green now. Any more comments or shall I merge?

@marco-piccolino
Copy link

hi!
Is this gonna make it into master any soon?
Really looking forward to it.
Thanks for the hard work!

@paoloambrosio paoloambrosio merged commit fe975ee into cucumber:master Nov 4, 2017
paoloambrosio added a commit that referenced this pull request Nov 4, 2017
@paoloambrosio
Copy link
Member

@konserw great contribution!

@muggenhor
Copy link
Contributor

Nice work @konserw !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants