starting work on report file output
This commit is contained in:
parent
0c368ec9f2
commit
3fdc69cfdd
@ -1,13 +1,12 @@
|
||||
#include "ConsoleOutput.h"
|
||||
|
||||
namespace HeadlessSpecRunner {
|
||||
ConsoleOutput::ConsoleOutput() : QObject(),
|
||||
ConsoleOutput::ConsoleOutput() : QObject(),
|
||||
showColors(false),
|
||||
consoleLogUsed(false) {
|
||||
outputIO = &std::cout;
|
||||
}
|
||||
|
||||
void ConsoleOutput::passed(const QString &specDetail) {
|
||||
void ConsoleOutput::passed(const QString &specDetail) {
|
||||
green();
|
||||
*outputIO << '.';
|
||||
clear();
|
||||
@ -15,9 +14,9 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
consoleLogUsed = false;
|
||||
successes.push(specDetail);
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::failed(const QString &specDetail) {
|
||||
void ConsoleOutput::failed(const QString &specDetail) {
|
||||
red();
|
||||
*outputIO << 'F';
|
||||
clear();
|
||||
@ -25,42 +24,42 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
consoleLogUsed = false;
|
||||
failures.push(specDetail);
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::green() {
|
||||
void ConsoleOutput::green() {
|
||||
if (showColors) std::cout << "\033[0;32m";
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::clear() {
|
||||
void ConsoleOutput::clear() {
|
||||
if (showColors) std::cout << "\033[m";
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::red() {
|
||||
void ConsoleOutput::red() {
|
||||
if (showColors) std::cout << "\033[0;31m";
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::yellow()
|
||||
{
|
||||
void ConsoleOutput::yellow()
|
||||
{
|
||||
if (showColors) std::cout << "\033[0;33m";
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::errorLog(const QString &msg, int lineNumber, const QString &sourceID) {
|
||||
void ConsoleOutput::errorLog(const QString &msg, int lineNumber, const QString &sourceID) {
|
||||
red();
|
||||
*outputIO << "[error] ";
|
||||
clear();
|
||||
*outputIO << qPrintable(sourceID) << ":" << lineNumber << " : " << qPrintable(msg);
|
||||
*outputIO << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::internalLog(const QString ¬e, const QString &msg) {
|
||||
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) {
|
||||
void ConsoleOutput::consoleLog(const QString &msg) {
|
||||
if (!consoleLogUsed) {
|
||||
*outputIO << std::endl;
|
||||
consoleLogUsed = true;
|
||||
@ -73,46 +72,46 @@ namespace HeadlessSpecRunner {
|
||||
clear();
|
||||
*outputIO << qPrintable(msg);
|
||||
*outputIO << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::logSpecFilename(const QString &name) {
|
||||
void ConsoleOutput::logSpecFilename(const QString &name) {
|
||||
*outputIO << std::endl << std::endl;
|
||||
red();
|
||||
*outputIO << qPrintable(name) << std::endl;
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::logSpecResult(const QString &result) {
|
||||
void ConsoleOutput::logSpecResult(const QString &result) {
|
||||
red();
|
||||
*outputIO << " " << qPrintable(result) << std::endl;
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration) {
|
||||
void ConsoleOutput::reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration) {
|
||||
red();
|
||||
*outputIO << std::endl << "FAIL: ";
|
||||
formatTestResults(totalTests, failedTests, duration);
|
||||
*outputIO << std::endl;
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration) {
|
||||
void ConsoleOutput::reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration) {
|
||||
green();
|
||||
*outputIO << std::endl << "PASS: ";
|
||||
formatTestResults(totalTests, failedTests, duration);
|
||||
*outputIO << std::endl;
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration) {
|
||||
void ConsoleOutput::reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration) {
|
||||
yellow();
|
||||
*outputIO << std::endl << "PASS with JS errors: ";
|
||||
formatTestResults(totalTests, failedTests, duration);
|
||||
*outputIO << std::endl;
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleOutput::formatTestResults(const QString &totalTests, const QString &failedTests, const QString &duration) {
|
||||
void ConsoleOutput::formatTestResults(const QString &totalTests, const QString &failedTests, const QString &duration) {
|
||||
*outputIO << qPrintable(totalTests) << " ";
|
||||
if (totalTests == "1") {
|
||||
*outputIO << "test";
|
||||
@ -137,6 +136,5 @@ namespace HeadlessSpecRunner {
|
||||
} else {
|
||||
*outputIO << "secs.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,10 @@
|
||||
#include <iostream>
|
||||
#include <QStack>
|
||||
|
||||
namespace HeadlessSpecRunner {
|
||||
class ConsoleOutput : public QObject {
|
||||
Q_OBJECT
|
||||
class ConsoleOutput : public QObject {
|
||||
public:
|
||||
ConsoleOutput();
|
||||
|
||||
void passed(const QString &specDetail);
|
||||
void failed(const QString &specDetail);
|
||||
void errorLog(const QString &msg, int lineNumber, const QString &sourceID);
|
||||
@ -25,6 +24,7 @@ namespace HeadlessSpecRunner {
|
||||
std::ostream *outputIO;
|
||||
QStack<QString> successes;
|
||||
QStack<QString> failures;
|
||||
|
||||
bool showColors;
|
||||
bool consoleLogUsed;
|
||||
private:
|
||||
@ -33,7 +33,6 @@ namespace HeadlessSpecRunner {
|
||||
void red();
|
||||
void yellow();
|
||||
void formatTestResults(const QString &totalTests, const QString &failedTests, const QString &duration);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -5,13 +5,11 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace HeadlessSpecRunner {
|
||||
ConsoleOutputTest::ConsoleOutputTest() : QObject() {
|
||||
}
|
||||
ConsoleOutputTest::ConsoleOutputTest() : QObject() {}
|
||||
|
||||
void ConsoleOutputTest::testPassed() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.consoleLogUsed = true;
|
||||
output.outputIO = &buffer;
|
||||
@ -24,7 +22,7 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testFailed() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.consoleLogUsed = true;
|
||||
output.outputIO = &buffer;
|
||||
@ -37,7 +35,7 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testErrorLog() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.outputIO = &buffer;
|
||||
output.errorLog("message", 1, "source");
|
||||
@ -46,7 +44,7 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testInternalLog() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.outputIO = &buffer;
|
||||
output.internalLog("note", "message");
|
||||
@ -55,7 +53,7 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testConsoleLog() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.consoleLogUsed = false;
|
||||
output.outputIO = &buffer;
|
||||
@ -65,7 +63,7 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testConsoleLogUsed() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.consoleLogUsed = true;
|
||||
output.outputIO = &buffer;
|
||||
@ -75,7 +73,7 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testLogSpecFilename() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.outputIO = &buffer;
|
||||
output.logSpecFilename("whatever");
|
||||
@ -84,7 +82,7 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testLogSpecResult() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.outputIO = &buffer;
|
||||
output.logSpecResult("whatever");
|
||||
@ -93,7 +91,7 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testReportResultsFailedSingular() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.outputIO = &buffer;
|
||||
output.reportFailure("1", "1", "1");
|
||||
@ -102,7 +100,7 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testReportResultsFailedPlural() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.outputIO = &buffer;
|
||||
output.reportFailure("2", "2", "2");
|
||||
@ -111,7 +109,7 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testReportResultsSucceeded() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.outputIO = &buffer;
|
||||
output.reportSuccess("2", "2", "2");
|
||||
@ -120,13 +118,12 @@ namespace HeadlessSpecRunner {
|
||||
|
||||
void ConsoleOutputTest::testReportResultsSucceededWithJSErrors() {
|
||||
stringstream buffer;
|
||||
HeadlessSpecRunner::ConsoleOutput output;
|
||||
ConsoleOutput output;
|
||||
|
||||
output.outputIO = &buffer;
|
||||
output.reportSuccessWithJSErrors("2", "2", "2");
|
||||
QVERIFY(buffer.str() == "\nPASS with JS errors: 2 tests, 2 failures, 2 secs.\n");
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(HeadlessSpecRunner::ConsoleOutputTest);
|
||||
QTEST_MAIN(ConsoleOutputTest);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef JHW_TEST_PAGE
|
||||
#define JHW_TEST_PAGE
|
||||
#ifndef JHW_TEST_CONSOLE_OUTPUT
|
||||
#define JHW_TEST_CONSOLE_OUTPUT
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <iostream>
|
||||
@ -8,8 +8,7 @@
|
||||
|
||||
#include "ConsoleOutput.h"
|
||||
|
||||
namespace HeadlessSpecRunner {
|
||||
class ConsoleOutputTest : public QObject {
|
||||
class ConsoleOutputTest : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ConsoleOutputTest();
|
||||
@ -28,8 +27,6 @@ namespace HeadlessSpecRunner {
|
||||
void testReportResultsFailedPlural();
|
||||
void testReportResultsSucceeded();
|
||||
void testReportResultsSucceededWithJSErrors();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "Page.h"
|
||||
|
||||
namespace HeadlessSpecRunner {
|
||||
Page::Page() : QWebPage(), confirmResult(true) {}
|
||||
|
||||
void Page::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) {
|
||||
@ -28,4 +27,3 @@ namespace HeadlessSpecRunner {
|
||||
void Page::oneFalseConfirm() {
|
||||
confirmResult = false;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <QtGui>
|
||||
#include <QtWebKit>
|
||||
|
||||
namespace HeadlessSpecRunner {
|
||||
class Page: public QWebPage {
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -20,6 +19,5 @@ namespace HeadlessSpecRunner {
|
||||
private:
|
||||
bool confirmResult;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "Page.h"
|
||||
#include "Page_test.h"
|
||||
|
||||
namespace HeadlessSpecRunner {
|
||||
PageTest::PageTest() : QObject(), internalLogCalled(false) {
|
||||
}
|
||||
|
||||
@ -39,7 +38,6 @@ namespace HeadlessSpecRunner {
|
||||
page.mainFrame()->setHtml("<script>cats();</script>");
|
||||
QVERIFY(consoleLogCalled);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(HeadlessSpecRunner::PageTest);
|
||||
QTEST_MAIN(PageTest);
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
#include "Page.h"
|
||||
|
||||
namespace HeadlessSpecRunner {
|
||||
class PageTest : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -14,7 +13,7 @@ namespace HeadlessSpecRunner {
|
||||
private:
|
||||
bool internalLogCalled;
|
||||
bool consoleLogCalled;
|
||||
HeadlessSpecRunner::Page page;
|
||||
Page page;
|
||||
|
||||
private slots:
|
||||
void internalLog(const QString ¬e, const QString &msg);
|
||||
@ -23,7 +22,6 @@ namespace HeadlessSpecRunner {
|
||||
void testJavaScriptConfirmWithoutLog();
|
||||
void testJavaScriptConsoleMessage();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
10
ext/jasmine-webkit-specrunner/ReportFileOutput.cpp
Normal file
10
ext/jasmine-webkit-specrunner/ReportFileOutput.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "ReportFileOutput.h"
|
||||
|
||||
ReportFileOutput::ReportFileOutput() : QObject() {
|
||||
|
||||
}
|
||||
|
||||
void ReportFileOutput::passed(const QString &specDetail) {
|
||||
*outputIO << "PASS||" << qPrintable(specDetail) << std::endl;
|
||||
successes.push(specDetail);
|
||||
}
|
29
ext/jasmine-webkit-specrunner/ReportFileOutput.h
Normal file
29
ext/jasmine-webkit-specrunner/ReportFileOutput.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef JHW_REPORT_FILE_OUTPUT
|
||||
#define JHW_REPORT_FILE_OUTPUT
|
||||
|
||||
#include <QObject>
|
||||
#include <iostream>
|
||||
#include <QStack>
|
||||
|
||||
class ReportFileOutput : public QObject {
|
||||
public:
|
||||
ReportFileOutput();
|
||||
|
||||
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);
|
||||
void logSpecResult(const QString &result);
|
||||
|
||||
void reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration);
|
||||
void reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration);
|
||||
void reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration);
|
||||
|
||||
std::ostream *outputIO;
|
||||
QStack<QString> successes;
|
||||
QStack<QString> failures;
|
||||
};
|
||||
|
||||
#endif
|
22
ext/jasmine-webkit-specrunner/ReportFileOutput_test.cpp
Normal file
22
ext/jasmine-webkit-specrunner/ReportFileOutput_test.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include "ReportFileOutput.h"
|
||||
#include "ReportFileOutput_test.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
ReportFileOutputTest::ReportFileOutputTest() : QObject() {}
|
||||
|
||||
void ReportFileOutputTest::testPassed() {
|
||||
stringstream buffer;
|
||||
ReportFileOutput output;
|
||||
|
||||
output.outputIO = &buffer;
|
||||
output.passed("test||done||file.js:23");
|
||||
QVERIFY(buffer.str() == "PASS||test||done||file.js:23\n");
|
||||
QVERIFY(output.successes.size() == 1);
|
||||
QVERIFY(output.failures.size() == 0);
|
||||
}
|
||||
|
||||
QTEST_MAIN(ReportFileOutputTest);
|
||||
|
19
ext/jasmine-webkit-specrunner/ReportFileOutput_test.h
Normal file
19
ext/jasmine-webkit-specrunner/ReportFileOutput_test.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef JHW_TEST_REPORT_FILE_OUTPUT
|
||||
#define JHW_TEST_REPORT_FILE_OUTPUT
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "ReportFileOutput.h"
|
||||
|
||||
class ReportFileOutputTest : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ReportFileOutputTest();
|
||||
private slots:
|
||||
void testPassed();
|
||||
};
|
||||
|
||||
#endif
|
7
ext/jasmine-webkit-specrunner/ReportFileOutput_test.pro
Normal file
7
ext/jasmine-webkit-specrunner/ReportFileOutput_test.pro
Normal file
@ -0,0 +1,7 @@
|
||||
include(common.pri)
|
||||
include(test.pri)
|
||||
|
||||
SOURCES += ReportFileOutput_test.cpp
|
||||
HEADERS += ReportFileOutput_test.h
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "Runner.h"
|
||||
|
||||
namespace HeadlessSpecRunner {
|
||||
Runner::Runner() : QObject()
|
||||
, m_runs(0)
|
||||
, hasErrors(false)
|
||||
@ -201,5 +200,4 @@ namespace HeadlessSpecRunner {
|
||||
QApplication::instance()->exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
#include "Page.h"
|
||||
#include "ConsoleOutput.h"
|
||||
#include "ReportFileOutput.h"
|
||||
|
||||
namespace HeadlessSpecRunner {
|
||||
class Runner: public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -38,7 +38,7 @@ namespace HeadlessSpecRunner {
|
||||
bool hasElement(const char *select);
|
||||
void timerEvent(QTimerEvent *event);
|
||||
private:
|
||||
HeadlessSpecRunner::Page m_page;
|
||||
Page m_page;
|
||||
QBasicTimer m_ticker;
|
||||
int m_runs;
|
||||
bool hasErrors;
|
||||
@ -49,10 +49,10 @@ namespace HeadlessSpecRunner {
|
||||
QString reportFilename;
|
||||
QStack<QString> failedSpecs;
|
||||
|
||||
HeadlessSpecRunner::ConsoleOutput consoleOutput;
|
||||
ConsoleOutput consoleOutput;
|
||||
ReportFileOutput reportFileOutput;
|
||||
|
||||
void loadSpec();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -4,6 +4,6 @@ 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
|
||||
SOURCES = Page.cpp Runner.cpp ConsoleOutput.cpp ReportFileOutput.cpp
|
||||
HEADERS = Page.h Runner.h ConsoleOutput.h ReportFileOutput.h
|
||||
|
||||
|
@ -54,7 +54,7 @@ int main(int argc, char** argv)
|
||||
|
||||
QApplication app(argc, argv);
|
||||
app.setApplicationName("jasmine-headless-webkit");
|
||||
HeadlessSpecRunner::Runner runner;
|
||||
Runner runner;
|
||||
runner.setColors(showColors);
|
||||
runner.reportFile(reporter);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user