more qt testing work

This commit is contained in:
John Bintz 2011-08-03 12:26:39 -04:00
parent 370eb182d8
commit 4fb82c2e7c
26 changed files with 182 additions and 143 deletions

View File

@ -4,7 +4,11 @@
#
guard 'shell' do
watch(%r{ext/jasmine-webkit-specrunner/.*\.(cpp|h)}) { compile }
watch(%r{ext/jasmine-webkit-specrunner/.*\.(cpp|h|pro|pri)}) { |m|
if !m[0]['moc_']
compile
end
}
end
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
@ -22,7 +26,7 @@ guard 'jasmine-headless-webkit', :all_on_start => false do
end
def compile
system %{cd ext/jasmine-webkit-specrunner && ruby extconf.rb}
system %{cd ext/jasmine-webkit-specrunner && ruby test.rb && ruby extconf.rb}
end
compile

View File

@ -0,0 +1,39 @@
#include "ConsoleOutput.h"
namespace HeadlessSpecRunner {
ConsoleOutput::ConsoleOutput() : QObject(),
showColors(false) {
outputIO = &std::cout;
}
void ConsoleOutput::passed(const QString &specDetail) {
green();
*outputIO << '.';
clear();
fflush(stdout);
successes.push(specDetail);
}
void ConsoleOutput::failed(const QString &specDetail)
{
red();
*outputIO << 'F';
clear();
fflush(stdout);
failures.push(specDetail);
}
void ConsoleOutput::green() {
if (showColors) std::cout << "\033[0;32m";
}
void ConsoleOutput::clear() {
if (showColors) std::cout << "\033[m";
}
void ConsoleOutput::red() {
if (showColors) std::cout << "\033[0;31m";
}
}

View File

@ -0,0 +1,26 @@
#ifndef JHW_CONSOLE_OUTPUT
#define JHW_CONSOLE_OUTPUT
#include <QObject>
#include <iostream>
#include <QStack>
namespace HeadlessSpecRunner {
class ConsoleOutput : public QObject {
Q_OBJECT
public:
ConsoleOutput();
void passed(const QString &specDetail);
void failed(const QString &specDetail);
std::ostream *outputIO;
QStack<QString> successes;
QStack<QString> failures;
private:
bool showColors;
void green();
void clear();
void red();
};
}
#endif

View File

@ -0,0 +1,36 @@
#include <QtTest/QtTest>
#include "ConsoleOutput.h"
#include "ConsoleOutput_test.h"
using namespace std;
namespace HeadlessSpecRunner {
ConsoleOutputTest::ConsoleOutputTest() : QObject() {
}
void ConsoleOutputTest::testPassed() {
stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output;
output.outputIO = &buffer;
output.passed("test");
QVERIFY(buffer.str() == ".");
QVERIFY(output.successes.size() == 1);
QVERIFY(output.failures.size() == 0);
}
void ConsoleOutputTest::testFailed() {
stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output;
output.outputIO = &buffer;
output.failed("test");
QVERIFY(buffer.str() == "F");
QVERIFY(output.successes.size() == 0);
QVERIFY(output.failures.size() == 1);
}
}
QTEST_MAIN(HeadlessSpecRunner::ConsoleOutputTest);

View File

@ -0,0 +1,25 @@
#ifndef JHW_TEST_PAGE
#define JHW_TEST_PAGE
#include <QtTest/QtTest>
#include <iostream>
#include <sstream>
#include <string>
#include "ConsoleOutput.h"
namespace HeadlessSpecRunner {
class ConsoleOutputTest : public QObject {
Q_OBJECT
public:
ConsoleOutputTest();
private slots:
void testPassed();
void testFailed();
};
}
#endif

View File

@ -0,0 +1,7 @@
include(common.pri)
include(test.pri)
SOURCES += ConsoleOutput_test.cpp
HEADERS += ConsoleOutput_test.h

View File

@ -1,14 +0,0 @@
#ifndef JHW_CONSOLE_REPORTER
#define JHW_CONSOLE_REPORTER
namespace HeadlessSpecRunner {
class ConsoleReporter : public QObject {
Q_OBJECT
public:
ConsoleReporter();
void passed(const QString &specDetail);
void failed(const QString &specDetail);
}
}
#endif

View File

@ -1,7 +1,7 @@
#include <QtTest/QtTest>
#include "HeadlessSpecRunner/Page.h"
#include "Test/Page_test.h"
#include "Page.h"
#include "Page_test.h"
namespace HeadlessSpecRunner {
PageTest::PageTest() : QObject(), internalLogCalled(false) {
@ -41,3 +41,5 @@ namespace HeadlessSpecRunner {
}
}
QTEST_MAIN(HeadlessSpecRunner::PageTest);

View File

@ -3,7 +3,7 @@
#include <QtTest/QtTest>
#include "HeadlessSpecRunner/Page.h"
#include "Page.h"
namespace HeadlessSpecRunner {
class PageTest : public QObject {

View File

@ -1,79 +0,0 @@
/****************************************************************************
** Meta object code from reading C++ file 'Page_test.cpp'
**
** Created: Tue Aug 2 10:10:26 2011
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.3)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'Page_test.cpp' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 62
#error "This file was generated using the moc from 4.7.3. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_HeadlessSpecRunner__PageTestHelper[] = {
// content:
5, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: signature, parameters, type, tag, flags
45, 36, 35, 35, 0x0a,
0 // eod
};
static const char qt_meta_stringdata_HeadlessSpecRunner__PageTestHelper[] = {
"HeadlessSpecRunner::PageTestHelper\0\0"
"note,msg\0internalLog(QString,QString)\0"
};
const QMetaObject HeadlessSpecRunner::PageTestHelper::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_HeadlessSpecRunner__PageTestHelper,
qt_meta_data_HeadlessSpecRunner__PageTestHelper, 0 }
};
#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &HeadlessSpecRunner::PageTestHelper::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION
const QMetaObject *HeadlessSpecRunner::PageTestHelper::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}
void *HeadlessSpecRunner::PageTestHelper::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_HeadlessSpecRunner__PageTestHelper))
return static_cast<void*>(const_cast< PageTestHelper*>(this));
return QObject::qt_metacast(_clname);
}
int HeadlessSpecRunner::PageTestHelper::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
switch (_id) {
case 0: internalLog((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
default: ;
}
_id -= 1;
}
return _id;
}
QT_END_MOC_NAMESPACE

View File

@ -0,0 +1,6 @@
include(common.pri)
include(test.pri)
SOURCES += Page_test.cpp
HEADERS += Page_test.h

View File

@ -96,21 +96,15 @@ namespace HeadlessSpecRunner {
void Runner::specPassed()
{
consoleNotUsedThisRun = true;
green();
std::cout << '.';
clear();
fflush(stdout);
consoleOutput.passed("");
}
void Runner::specFailed(const QString &specDetail)
{
consoleNotUsedThisRun = true;
consoleOutput.failed("");
didFail = true;
red();
std::cout << 'F';
failedSpecs.push(specDetail);
clear();
fflush(stdout);
}
void Runner::errorLog(const QString &msg, int lineNumber, const QString &sourceID)

View File

@ -9,6 +9,7 @@
#include <QQueue>
#include "Page.h"
#include "ConsoleOutput.h"
namespace HeadlessSpecRunner {
class Runner: public QObject {
@ -49,6 +50,8 @@ namespace HeadlessSpecRunner {
QString reportFilename;
QStack<QString> failedSpecs;
HeadlessSpecRunner::ConsoleOutput consoleOutput;
void red();
void green();
void yellow();

View File

@ -0,0 +1,9 @@
TEMPLATE = app
CONFIG -= app_bundle
QMAKE_INFO_PLIST = Info.plist
QMAKESPEC = macx-g++
QT += network webkit
SOURCES = Page.cpp Runner.cpp ConsoleOutput.cpp
HEADERS = Page.h Runner.h ConsoleOutput.h

View File

@ -4,7 +4,6 @@ $: << File.expand_path("../../../lib", __FILE__)
require 'qt/qmake'
Qt::Qmake.make!('jasmine-headless-webkit tests', 'specrunner_test.pro')
system %{jasmine-webkit-specrunner-test}
system %{make clean}
Qt::Qmake.make!('jasmine-headless-webkit', 'specrunner.pro')

Binary file not shown.

View File

@ -21,8 +21,8 @@
THE SOFTWARE.
*/
#include "HeadlessSpecRunner/Page.h"
#include "HeadlessSpecRunner/Runner.h"
#include "Page.h"
#include "Runner.h"
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
#error Use Qt 4.7 or later version

View File

@ -1,8 +1,4 @@
TEMPLATE = app
CONFIG -= app_bundle
include(common.pri)
SOURCES += specrunner.cpp
TARGET = jasmine-webkit-specrunner
SOURCES = HeadlessSpecRunner/Page.cpp HeadlessSpecRunner/Runner.cpp specrunner.cpp
HEADERS = HeadlessSpecRunner/Page.h HeadlessSpecRunner/Runner.h
QT += network webkit
QMAKE_INFO_PLIST = Info.plist
QMAKESPEC = macx-gcc

View File

@ -1,10 +0,0 @@
#include "Test/Page_test.h"
#include <QTest>
QTEST_MAIN
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
HeadlessSpecRunner::PageTest pageTest;
QTest::qExec(&pageTest);
}

View File

@ -1,16 +0,0 @@
TEMPLATE = app
CONFIG -= app_bundle
TARGET = jasmine-webkit-specrunner-test
SOURCES = HeadlessSpecRunner/Page.cpp \
HeadlessSpecRunner/Runner.cpp \
Test/Page_test.cpp \
specrunner_test.cpp
HEADERS = HeadlessSpecRunner/Page.h \
HeadlessSpecRunner/Runner.h \
Test/Page_test.h
QT += network webkit testlib
QMAKE_INFO_PLIST = Info.plist
QMAKESPEC = macx-gcc

View File

@ -0,0 +1,3 @@
TARGET = jhw-test
QT += testlib

View File

@ -0,0 +1,9 @@
#!/usr/bin/env ruby
Dir['*_test.pro'].each do |test|
system %{make clean && qmake #{test} && make && ./jhw-test}
if $?.exitstatus != 0
exit 1
end
end