diff --git a/.gitignore b/.gitignore index 198d3eb..801dd0a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner moc_*.* .DS_Store hydra-runner.log +jhw-test diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp b/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp index edca3ce..f6d9804 100644 --- a/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp +++ b/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp @@ -2,7 +2,8 @@ namespace HeadlessSpecRunner { ConsoleOutput::ConsoleOutput() : QObject(), - showColors(false) { + showColors(false), + consoleLogUsed(false) { outputIO = &std::cout; } @@ -12,6 +13,7 @@ namespace HeadlessSpecRunner { clear(); outputIO->flush(); + consoleLogUsed = false; successes.push(specDetail); } @@ -22,6 +24,7 @@ namespace HeadlessSpecRunner { clear(); outputIO->flush(); + consoleLogUsed = false; failures.push(specDetail); } @@ -44,4 +47,35 @@ namespace HeadlessSpecRunner { *outputIO << qPrintable(sourceID) << ":" << lineNumber << " : " << qPrintable(msg); *outputIO << std::endl; } + + void ConsoleOutput::internalLog(const QString ¬e, const QString &msg) { + red(); + *outputIO << "[" << qPrintable(note) << "] "; + clear(); + *outputIO << qPrintable(msg); + *outputIO << std::endl; + } + + void ConsoleOutput::consoleLog(const QString &msg) { + if (!consoleLogUsed) { + *outputIO << std::endl; + consoleLogUsed = true; + } + + green(); + *outputIO << "[console] "; + if (msg.contains("\n")) + *outputIO << std::endl; + clear(); + *outputIO << qPrintable(msg); + *outputIO << std::endl; + } + + void ConsoleOutput::logSpecFilename(const QString &name) { + *outputIO << std::endl << std::endl; + red(); + *outputIO << qPrintable(name) << std::endl; + clear(); + } } + diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput.h b/ext/jasmine-webkit-specrunner/ConsoleOutput.h index 5069e4e..51afb93 100644 --- a/ext/jasmine-webkit-specrunner/ConsoleOutput.h +++ b/ext/jasmine-webkit-specrunner/ConsoleOutput.h @@ -13,10 +13,15 @@ namespace HeadlessSpecRunner { void passed(const QString &specDetail); void failed(const QString &specDetail); void errorLog(const QString &msg, int lineNumber, const QString &sourceID); + void internalLog(const QString ¬e, const QString &msg); + void consoleLog(const QString &msg); + void logSpecFilename(const QString &name); + std::ostream *outputIO; QStack successes; QStack failures; bool showColors; + bool consoleLogUsed; private: void green(); void clear(); diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp index d99d7a8..e833549 100644 --- a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp +++ b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp @@ -13,22 +13,26 @@ namespace HeadlessSpecRunner { stringstream buffer; HeadlessSpecRunner::ConsoleOutput output; + output.consoleLogUsed = true; output.outputIO = &buffer; output.passed("test"); QVERIFY(buffer.str() == "."); QVERIFY(output.successes.size() == 1); QVERIFY(output.failures.size() == 0); + QVERIFY(output.consoleLogUsed == false); } void ConsoleOutputTest::testFailed() { stringstream buffer; HeadlessSpecRunner::ConsoleOutput output; + output.consoleLogUsed = true; output.outputIO = &buffer; output.failed("test"); QVERIFY(buffer.str() == "F"); QVERIFY(output.successes.size() == 0); QVERIFY(output.failures.size() == 1); + QVERIFY(output.consoleLogUsed == false); } void ConsoleOutputTest::testErrorLog() { @@ -39,6 +43,44 @@ namespace HeadlessSpecRunner { output.errorLog("message", 1, "source"); QVERIFY(buffer.str() == "[error] source:1 : message\n"); } + + void ConsoleOutputTest::testInternalLog() { + stringstream buffer; + HeadlessSpecRunner::ConsoleOutput output; + + output.outputIO = &buffer; + output.internalLog("note", "message"); + QVERIFY(buffer.str() == "[note] message\n"); + } + + void ConsoleOutputTest::testConsoleLog() { + stringstream buffer; + HeadlessSpecRunner::ConsoleOutput output; + + output.consoleLogUsed = false; + output.outputIO = &buffer; + output.consoleLog("log"); + QVERIFY(buffer.str() == "\n[console] log\n"); + } + + void ConsoleOutputTest::testConsoleLogUsed() { + stringstream buffer; + HeadlessSpecRunner::ConsoleOutput output; + + output.consoleLogUsed = true; + output.outputIO = &buffer; + output.consoleLog("log"); + QVERIFY(buffer.str() == "[console] log\n"); + } + + void ConsoleOutputTest::testLogSpecFilename() { + stringstream buffer; + HeadlessSpecRunner::ConsoleOutput output; + + output.outputIO = &buffer; + output.logSpecFilename("whatever"); + QVERIFY(buffer.str() == "\n\nwhatever\n"); + } } QTEST_MAIN(HeadlessSpecRunner::ConsoleOutputTest); diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h index 1537eea..3e13942 100644 --- a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h +++ b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h @@ -18,9 +18,12 @@ namespace HeadlessSpecRunner { void testPassed(); void testFailed(); void testErrorLog(); + void testInternalLog(); + void testConsoleLog(); + void testConsoleLogUsed(); + void testLogSpecFilename(); }; } #endif - diff --git a/ext/jasmine-webkit-specrunner/Page.cpp b/ext/jasmine-webkit-specrunner/Page.cpp index 6b9f91e..d277e21 100644 --- a/ext/jasmine-webkit-specrunner/Page.cpp +++ b/ext/jasmine-webkit-specrunner/Page.cpp @@ -11,7 +11,7 @@ namespace HeadlessSpecRunner { emit consoleLog(message, lineNumber, sourceID); } - bool Page::javaScriptConfirm(QWebFrame *frame, const QString &msg) { + bool Page::javaScriptConfirm(QWebFrame*, const QString&) { if (confirmResult) { emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true."); return true; @@ -21,7 +21,7 @@ namespace HeadlessSpecRunner { } } - void Page::javaScriptAlert(QWebFrame *frame, const QString &msg) { + void Page::javaScriptAlert(QWebFrame*, const QString &msg) { emit internalLog("alert", msg); } diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 7330bae..e129505 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -14,8 +14,7 @@ namespace HeadlessSpecRunner { , usedConsole(false) , showColors(false) , isFinished(false) - , didFail(false) - , consoleNotUsedThisRun(false) { + , didFail(false) { m_page.settings()->enablePersistentStorage(); connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool))); connect(&m_page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(errorLog(QString, int, QString))); @@ -100,13 +99,11 @@ namespace HeadlessSpecRunner { void Runner::specPassed() { - consoleNotUsedThisRun = true; consoleOutput.passed(""); } void Runner::specFailed(const QString &specDetail) { - consoleNotUsedThisRun = true; consoleOutput.failed(""); didFail = true; failedSpecs.push(specDetail); @@ -122,45 +119,25 @@ namespace HeadlessSpecRunner { } void Runner::internalLog(const QString ¬e, const QString &msg) { - red(); - std::cout << "[" << qPrintable(note) << "] "; - clear(); - std::cout << qPrintable(msg); - std::cout << std::endl; + consoleOutput.internalLog(note, msg); } void Runner::log(const QString &msg) { usedConsole = true; - green(); - if (consoleNotUsedThisRun) { - std::cout << std::endl; - consoleNotUsedThisRun = false; - } - std::cout << "[console] "; - clear(); - if (msg.contains("\n")) - std::cout << std::endl; - std::cout << qPrintable(msg); - std::cout << std::endl; + consoleOutput.consoleLog(msg); } void Runner::leavePageAttempt(const QString &msg) { - red(); - std::cout << "[error] "; - clear(); - std::cout << qPrintable(msg) << std::endl; + consoleOutput.internalLog("error", msg); m_page.oneFalseConfirm(); hasErrors = true; } void Runner::printName(const QString &name) { - std::cout << std::endl << std::endl; - red(); - std::cout << qPrintable(name) << std::endl; - clear(); + consoleOutput.logSpecFilename(name); } void Runner::printResult(const QString &result) diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index c00e575..9c76fd0 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -46,7 +46,6 @@ namespace HeadlessSpecRunner { bool showColors; bool isFinished; bool didFail; - bool consoleNotUsedThisRun; QQueue runnerFiles; QString reportFilename; QStack failedSpecs; diff --git a/ext/jasmine-webkit-specrunner/jhw-test b/ext/jasmine-webkit-specrunner/jhw-test deleted file mode 100755 index 763649b..0000000 Binary files a/ext/jasmine-webkit-specrunner/jhw-test and /dev/null differ diff --git a/ext/jasmine-webkit-specrunner/test.rb b/ext/jasmine-webkit-specrunner/test.rb index 4585da1..ca7f407 100644 --- a/ext/jasmine-webkit-specrunner/test.rb +++ b/ext/jasmine-webkit-specrunner/test.rb @@ -1,15 +1,23 @@ #!/usr/bin/env ruby +require 'fileutils' + system %{make clean} -Dir['*_test.pro'].each do |test| - $: << File.expand_path("../../../lib", __FILE__) +$: << File.expand_path("../../../lib", __FILE__) +require 'qt/qmake' + +Dir['*_test.pro'].each do |test| + FileUtils.rm_f('jhw-test') - require 'qt/qmake' Qt::Qmake.make!('jasmine-headless-webkit', test) - system %{./jhw-test} - if $?.exitstatus != 0 + if File.file?('jhw-test') + system %{./jhw-test} + if $?.exitstatus != 0 + exit 1 + end + else exit 1 end end