starting work on report file output

This commit is contained in:
John Bintz 2011-08-30 15:59:09 -04:00
parent 0c368ec9f2
commit 3fdc69cfdd
17 changed files with 267 additions and 199 deletions

View File

@ -1,6 +1,5 @@
#include "ConsoleOutput.h"
namespace HeadlessSpecRunner {
ConsoleOutput::ConsoleOutput() : QObject(),
showColors(false),
consoleLogUsed(false) {
@ -138,5 +137,4 @@ namespace HeadlessSpecRunner {
*outputIO << "secs.";
}
}
}

View File

@ -5,11 +5,10 @@
#include <iostream>
#include <QStack>
namespace HeadlessSpecRunner {
class ConsoleOutput : public QObject {
Q_OBJECT
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:
@ -34,6 +34,5 @@ namespace HeadlessSpecRunner {
void yellow();
void formatTestResults(const QString &totalTests, const QString &failedTests, const QString &duration);
};
}
#endif

View File

@ -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);

View File

@ -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,7 +8,6 @@
#include "ConsoleOutput.h"
namespace HeadlessSpecRunner {
class ConsoleOutputTest : public QObject {
Q_OBJECT
public:
@ -29,7 +28,5 @@ namespace HeadlessSpecRunner {
void testReportResultsSucceeded();
void testReportResultsSucceededWithJSErrors();
};
}
#endif

View File

@ -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;
}
}

View File

@ -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

View File

@ -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);

View File

@ -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 &note, const QString &msg);
@ -23,7 +22,6 @@ namespace HeadlessSpecRunner {
void testJavaScriptConfirmWithoutLog();
void testJavaScriptConsoleMessage();
};
}
#endif

View 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);
}

View 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 &note, 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

View 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);

View 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

View File

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

View File

@ -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);
}
}
}

View File

@ -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

View File

@ -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

View File

@ -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);