-
Notifications
You must be signed in to change notification settings - Fork 137
QtTest driver #110
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 #110
Conversation
|
I've rebased to clean up commit history - now I believe it's ready for merging. |
| QCOMPARE(framework.isCleanedUp, false); | ||
| QTest::qExec(&framework); | ||
| QCOMPARE(framework.isInitialized, true); | ||
| QCOMPARE(framework.isCleanedUp, 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.
This is not testing the driver. QtTestSteps has nothing to do with the driver.
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've used boost test as example - how this is different?
class BoostDriverTest : public DriverTest {
public:
virtual void runAllTests() {
stepInvocationInitsBoostTest();
DriverTest::runAllTests();
}
private:
void stepInvocationInitsBoostTest() {
std::cout << "= Init =" << std::endl;
using namespace boost::unit_test;
BoostStepDouble step;
expectFalse("Framework is not initialized before the first test", framework::is_initialized());
step.invokeStepBody();
expectTrue("Framework is initialized after the first test", framework::is_initialized());
}
};
int main(int argc, char **argv) {
BoostDriverTest 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.
The tests for the Boost driver exercise a test double that inherits from the class under test (instead of exercising the framework directly). Assertions instead check properties of the test framework to make sure that the .invokeStepBody() method did something on the system.
class BoostStepDouble : public BoostStep { VS class QtTestSteps : public QObject {
step.invokeStepBody(); VS QTest::qExec(&framework);
|
Apart from the comments, nice PR! |
|
...and don't forget to add something in the library dependencies of the README file! |
|
I've updated readme, rebased it and partly fixed file writting problem. |
|
Any idea on why would this test pass on gcc and fail on clang? |
|
Stupid mistake - those bool variables were uninitialized, that defaults to false (0) on gcc, but not on clang |
|
Anyone any comments? |
|
If no comments merge please :) |
beb427b to
9ed70ac
Compare
|
Just rebased against current master |
|
Rebased and all green - ready to merge ;) |
|
One last commit - for compatibility with Qt >= 5.7 c++11 has to be enabled. I wasn't sure if new PR would be better for this... |
|
I have to say I don't like the Posix implementation at all:
You are right: there is no way out of the horribly closed implementation that Qt has done (shame on them!). On a Posix system we could create a new process running the same code base (fork) and read from its output, but that is not supported by Windows. At this point the lesser of all evils is to use the temporary file solution for all implementations :-( |
paoloambrosio
left a comment
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.
Hopefully last comments before it can be merged :-)
src/drivers/QtTestDriver.cpp
Outdated
| if (file.open()) { | ||
| fileName = file.fileName(); | ||
| } | ||
| file.close(); |
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.
If the file cannot be opened, the filename will be null and nothing would work. Perhaps we should stop here and return a failure.
Also can the file be opened in QIODevice::ReadOnly?
src/drivers/QtTestDriver.cpp
Outdated
| return InvokeResult::success(); | ||
| else | ||
| { | ||
| file.open(); |
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.
If we close the file at the end (QTemporaryFile's destructor does it) we don't need to re-open it. Also please mind the coding conventions (spaces, braces, ...):
if (...) {
...
} else {
...
}
src/drivers/QtTestDriver.cpp
Outdated
| { | ||
| file.open(); | ||
| QTextStream ts(&file); | ||
| return InvokeResult::failure(ts.readAll().toLatin1()); |
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 toLatin1? I'm no Qt expert but toLocal8Bit looks more like the OS's character set... am I wrong?
|
|
||
| class QtTestStep : public BasicStep{ | ||
| public: | ||
| QtTestStep(): IsInitialized(false), IsCleanedUp(false), 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.
Is there a reason why here and in several other places you are using UpperCamelCase instead of lowerCamelCase?
|
I'm not sure but I believe that there could be an alternative to writing a real file, that is to write the output to a named pipe (available on both Windows and Posix systems, but with different APIs). Happy to merge this with file based I/O as a multi-platform pipe implementation is not straightforward. |
601a020 to
be94cb7
Compare
|
Please take a look at new implementation using pipes for both POSIX and windows. |
|
I've also experimented with moving qttest::qexec to another thread but then first step from calcqt example always fail (widget does not render, so label is empty), you can check here: https://github.com/konserw/cucumber-cpp/tree/qttestthread |
|
@konserw for pre-built Qt on Travis CI you can take a look here: https://github.com/benlau/qtci |
462150a to
77e0a3b
Compare
Use pipe on POSIX systems to get output from QtTestDriver Use pipe to get output from QtTest also on Windows Pipe abstraction layer moved to separate header Included also QtTest steps for Calc and CalcQt examples
It's QtTest based test driver for cucumber-cpp.
I'm not sure if unit test for that is OK.
Looking forward for any comments ;)