diff --git a/Guardfile b/Guardfile index f0c26ca..1488233 100644 --- a/Guardfile +++ b/Guardfile @@ -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 diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp b/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp new file mode 100644 index 0000000..431aacd --- /dev/null +++ b/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp @@ -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"; + } +} diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput.h b/ext/jasmine-webkit-specrunner/ConsoleOutput.h new file mode 100644 index 0000000..d63e3ac --- /dev/null +++ b/ext/jasmine-webkit-specrunner/ConsoleOutput.h @@ -0,0 +1,26 @@ +#ifndef JHW_CONSOLE_OUTPUT +#define JHW_CONSOLE_OUTPUT + +#include +#include +#include + +namespace HeadlessSpecRunner { + class ConsoleOutput : public QObject { + Q_OBJECT + public: + ConsoleOutput(); + void passed(const QString &specDetail); + void failed(const QString &specDetail); + std::ostream *outputIO; + QStack successes; + QStack failures; + private: + bool showColors; + void green(); + void clear(); + void red(); + }; +} + +#endif diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp new file mode 100644 index 0000000..6917615 --- /dev/null +++ b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp @@ -0,0 +1,36 @@ +#include + +#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); + diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h new file mode 100644 index 0000000..455113a --- /dev/null +++ b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h @@ -0,0 +1,25 @@ +#ifndef JHW_TEST_PAGE +#define JHW_TEST_PAGE + +#include +#include +#include +#include + +#include "ConsoleOutput.h" + +namespace HeadlessSpecRunner { + class ConsoleOutputTest : public QObject { + Q_OBJECT + public: + ConsoleOutputTest(); + + private slots: + void testPassed(); + void testFailed(); + }; +} + +#endif + + diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.pro b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.pro new file mode 100644 index 0000000..7b09285 --- /dev/null +++ b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.pro @@ -0,0 +1,7 @@ +include(common.pri) +include(test.pri) + +SOURCES += ConsoleOutput_test.cpp +HEADERS += ConsoleOutput_test.h + + diff --git a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/ConsoleOutput.cpp b/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/ConsoleOutput.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/ConsoleOutput.h b/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/ConsoleOutput.h deleted file mode 100644 index 86238e5..0000000 --- a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/ConsoleOutput.h +++ /dev/null @@ -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 diff --git a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Page.cpp b/ext/jasmine-webkit-specrunner/Page.cpp similarity index 100% rename from ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Page.cpp rename to ext/jasmine-webkit-specrunner/Page.cpp diff --git a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Page.h b/ext/jasmine-webkit-specrunner/Page.h similarity index 100% rename from ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Page.h rename to ext/jasmine-webkit-specrunner/Page.h diff --git a/ext/jasmine-webkit-specrunner/Test/Page_test.cpp b/ext/jasmine-webkit-specrunner/Page_test.cpp similarity index 93% rename from ext/jasmine-webkit-specrunner/Test/Page_test.cpp rename to ext/jasmine-webkit-specrunner/Page_test.cpp index fd0c288..a184d26 100644 --- a/ext/jasmine-webkit-specrunner/Test/Page_test.cpp +++ b/ext/jasmine-webkit-specrunner/Page_test.cpp @@ -1,7 +1,7 @@ #include -#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); + diff --git a/ext/jasmine-webkit-specrunner/Test/Page_test.h b/ext/jasmine-webkit-specrunner/Page_test.h similarity index 94% rename from ext/jasmine-webkit-specrunner/Test/Page_test.h rename to ext/jasmine-webkit-specrunner/Page_test.h index 7df1587..7d500b1 100644 --- a/ext/jasmine-webkit-specrunner/Test/Page_test.h +++ b/ext/jasmine-webkit-specrunner/Page_test.h @@ -3,7 +3,7 @@ #include -#include "HeadlessSpecRunner/Page.h" +#include "Page.h" namespace HeadlessSpecRunner { class PageTest : public QObject { diff --git a/ext/jasmine-webkit-specrunner/Page_test.moc b/ext/jasmine-webkit-specrunner/Page_test.moc deleted file mode 100644 index e370a71..0000000 --- a/ext/jasmine-webkit-specrunner/Page_test.moc +++ /dev/null @@ -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 ." -#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(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 diff --git a/ext/jasmine-webkit-specrunner/Page_test.pro b/ext/jasmine-webkit-specrunner/Page_test.pro new file mode 100644 index 0000000..9482e83 --- /dev/null +++ b/ext/jasmine-webkit-specrunner/Page_test.pro @@ -0,0 +1,6 @@ +include(common.pri) +include(test.pri) + +SOURCES += Page_test.cpp +HEADERS += Page_test.h + diff --git a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp similarity index 97% rename from ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.cpp rename to ext/jasmine-webkit-specrunner/Runner.cpp index 2ec04d1..b5c5ee2 100644 --- a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -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) diff --git a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h similarity index 94% rename from ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.h rename to ext/jasmine-webkit-specrunner/Runner.h index 46d3bf7..8f416e7 100644 --- a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -9,6 +9,7 @@ #include #include "Page.h" +#include "ConsoleOutput.h" namespace HeadlessSpecRunner { class Runner: public QObject { @@ -49,6 +50,8 @@ namespace HeadlessSpecRunner { QString reportFilename; QStack failedSpecs; + HeadlessSpecRunner::ConsoleOutput consoleOutput; + void red(); void green(); void yellow(); diff --git a/ext/jasmine-webkit-specrunner/common.pri b/ext/jasmine-webkit-specrunner/common.pri new file mode 100644 index 0000000..e19d607 --- /dev/null +++ b/ext/jasmine-webkit-specrunner/common.pri @@ -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 + diff --git a/ext/jasmine-webkit-specrunner/extconf.rb b/ext/jasmine-webkit-specrunner/extconf.rb index d7e6907..d950511 100644 --- a/ext/jasmine-webkit-specrunner/extconf.rb +++ b/ext/jasmine-webkit-specrunner/extconf.rb @@ -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') diff --git a/ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner-test b/ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner-test deleted file mode 100755 index 897d9f4..0000000 Binary files a/ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner-test and /dev/null differ diff --git a/ext/jasmine-webkit-specrunner/jhw-test b/ext/jasmine-webkit-specrunner/jhw-test new file mode 100755 index 0000000..ed6d280 Binary files /dev/null and b/ext/jasmine-webkit-specrunner/jhw-test differ diff --git a/ext/jasmine-webkit-specrunner/specrunner.cpp b/ext/jasmine-webkit-specrunner/specrunner.cpp index 4827ac9..0ae4469 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.cpp +++ b/ext/jasmine-webkit-specrunner/specrunner.cpp @@ -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 diff --git a/ext/jasmine-webkit-specrunner/specrunner.pro b/ext/jasmine-webkit-specrunner/specrunner.pro index 43201b9..820c444 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.pro +++ b/ext/jasmine-webkit-specrunner/specrunner.pro @@ -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 diff --git a/ext/jasmine-webkit-specrunner/specrunner_test.cpp b/ext/jasmine-webkit-specrunner/specrunner_test.cpp deleted file mode 100644 index 08689cc..0000000 --- a/ext/jasmine-webkit-specrunner/specrunner_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Test/Page_test.h" -#include - -QTEST_MAIN -int main(int argc, char *argv[]) { - QCoreApplication app(argc, argv); - HeadlessSpecRunner::PageTest pageTest; - QTest::qExec(&pageTest); -} - diff --git a/ext/jasmine-webkit-specrunner/specrunner_test.pro b/ext/jasmine-webkit-specrunner/specrunner_test.pro deleted file mode 100644 index 9a4f921..0000000 --- a/ext/jasmine-webkit-specrunner/specrunner_test.pro +++ /dev/null @@ -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 - diff --git a/ext/jasmine-webkit-specrunner/test.pri b/ext/jasmine-webkit-specrunner/test.pri new file mode 100644 index 0000000..4804421 --- /dev/null +++ b/ext/jasmine-webkit-specrunner/test.pri @@ -0,0 +1,3 @@ +TARGET = jhw-test +QT += testlib + diff --git a/ext/jasmine-webkit-specrunner/test.rb b/ext/jasmine-webkit-specrunner/test.rb new file mode 100644 index 0000000..6934d3e --- /dev/null +++ b/ext/jasmine-webkit-specrunner/test.rb @@ -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 +