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,142 +1,140 @@
#include "ConsoleOutput.h"
namespace HeadlessSpecRunner {
ConsoleOutput::ConsoleOutput() : QObject(),
ConsoleOutput::ConsoleOutput() : QObject(),
showColors(false),
consoleLogUsed(false) {
outputIO = &std::cout;
}
void ConsoleOutput::passed(const QString &specDetail) {
green();
*outputIO << '.';
clear();
outputIO->flush();
void ConsoleOutput::passed(const QString &specDetail) {
green();
*outputIO << '.';
clear();
outputIO->flush();
consoleLogUsed = false;
successes.push(specDetail);
}
consoleLogUsed = false;
successes.push(specDetail);
}
void ConsoleOutput::failed(const QString &specDetail) {
red();
*outputIO << 'F';
clear();
outputIO->flush();
void ConsoleOutput::failed(const QString &specDetail) {
red();
*outputIO << 'F';
clear();
outputIO->flush();
consoleLogUsed = false;
failures.push(specDetail);
}
consoleLogUsed = false;
failures.push(specDetail);
}
void ConsoleOutput::green() {
if (showColors) std::cout << "\033[0;32m";
}
void ConsoleOutput::green() {
if (showColors) std::cout << "\033[0;32m";
}
void ConsoleOutput::clear() {
if (showColors) std::cout << "\033[m";
}
void ConsoleOutput::clear() {
if (showColors) std::cout << "\033[m";
}
void ConsoleOutput::red() {
if (showColors) std::cout << "\033[0;31m";
}
void ConsoleOutput::red() {
if (showColors) std::cout << "\033[0;31m";
}
void ConsoleOutput::yellow()
{
if (showColors) std::cout << "\033[0;33m";
}
void ConsoleOutput::yellow()
{
if (showColors) std::cout << "\033[0;33m";
}
void ConsoleOutput::errorLog(const QString &msg, int lineNumber, const QString &sourceID) {
red();
*outputIO << "[error] ";
clear();
*outputIO << qPrintable(sourceID) << ":" << lineNumber << " : " << qPrintable(msg);
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 &note, 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;
}
void ConsoleOutput::internalLog(const QString &note, const QString &msg) {
red();
*outputIO << "[" << qPrintable(note) << "] ";
clear();
*outputIO << qPrintable(msg);
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();
}
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) {
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) {
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) {
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) {
*outputIO << qPrintable(totalTests) << " ";
if (totalTests == "1") {
*outputIO << "test";
} else {
*outputIO << "tests";
}
void ConsoleOutput::consoleLog(const QString &msg) {
if (!consoleLogUsed) {
*outputIO << std::endl;
consoleLogUsed = true;
}
*outputIO << ", ";
green();
*outputIO << "[console] ";
if (msg.contains("\n"))
*outputIO << std::endl;
clear();
*outputIO << qPrintable(msg);
*outputIO << std::endl;
*outputIO << qPrintable(failedTests) << " ";
if (failedTests == "1") {
*outputIO << "failure";
} else {
*outputIO << "failures";
}
void ConsoleOutput::logSpecFilename(const QString &name) {
*outputIO << std::endl << std::endl;
red();
*outputIO << qPrintable(name) << std::endl;
clear();
}
*outputIO << ", ";
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) {
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) {
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) {
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) {
*outputIO << qPrintable(totalTests) << " ";
if (totalTests == "1") {
*outputIO << "test";
} else {
*outputIO << "tests";
}
*outputIO << ", ";
*outputIO << qPrintable(failedTests) << " ";
if (failedTests == "1") {
*outputIO << "failure";
} else {
*outputIO << "failures";
}
*outputIO << ", ";
*outputIO << qPrintable(duration) << " ";
if (duration == "1") {
*outputIO << "sec.";
} else {
*outputIO << "secs.";
}
*outputIO << qPrintable(duration) << " ";
if (duration == "1") {
*outputIO << "sec.";
} else {
*outputIO << "secs.";
}
}

View File

@ -5,35 +5,34 @@
#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);
void internalLog(const QString &note, const QString &msg);
void consoleLog(const QString &msg);
void logSpecFilename(const QString &name);
void logSpecResult(const QString &result);
class ConsoleOutput : public QObject {
public:
ConsoleOutput();
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);
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);
std::ostream *outputIO;
QStack<QString> successes;
QStack<QString> failures;
bool showColors;
bool consoleLogUsed;
private:
void green();
void clear();
void red();
void yellow();
void formatTestResults(const QString &totalTests, const QString &failedTests, const QString &duration);
};
}
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;
bool showColors;
bool consoleLogUsed;
private:
void green();
void clear();
void red();
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,28 +8,25 @@
#include "ConsoleOutput.h"
namespace HeadlessSpecRunner {
class ConsoleOutputTest : public QObject {
Q_OBJECT
public:
ConsoleOutputTest();
class ConsoleOutputTest : public QObject {
Q_OBJECT
public:
ConsoleOutputTest();
private slots:
void testPassed();
void testFailed();
void testErrorLog();
void testInternalLog();
void testConsoleLog();
void testConsoleLogUsed();
void testLogSpecFilename();
void testLogSpecResult();
void testFailed();
void testErrorLog();
void testInternalLog();
void testConsoleLog();
void testConsoleLogUsed();
void testLogSpecFilename();
void testLogSpecResult();
void testReportResultsFailedSingular();
void testReportResultsFailedPlural();
void testReportResultsSucceeded();
void testReportResultsSucceededWithJSErrors();
};
}
void testReportResultsFailedSingular();
void testReportResultsFailedPlural();
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);