jasmine-headless-webkit/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp

148 lines
3.4 KiB
C++
Raw Normal View History

2011-08-03 16:26:39 +00:00
#include "ConsoleOutput.h"
2011-08-30 19:59:09 +00:00
ConsoleOutput::ConsoleOutput() : QObject(),
2011-08-29 17:35:36 +00:00
showColors(false),
consoleLogUsed(false) {
2011-08-03 16:26:39 +00:00
outputIO = &std::cout;
}
2011-08-30 19:59:09 +00:00
void ConsoleOutput::passed(const QString &specDetail) {
green();
*outputIO << '.';
clear();
outputIO->flush();
2011-08-03 16:26:39 +00:00
2011-08-30 19:59:09 +00:00
consoleLogUsed = false;
successes.push(specDetail);
}
2011-08-03 16:26:39 +00:00
2011-08-30 19:59:09 +00:00
void ConsoleOutput::failed(const QString &specDetail) {
red();
*outputIO << 'F';
clear();
outputIO->flush();
2011-08-03 16:26:39 +00:00
2011-08-30 19:59:09 +00:00
consoleLogUsed = false;
failures.push(specDetail);
}
2011-08-03 16:26:39 +00:00
2011-08-30 19:59:09 +00:00
void ConsoleOutput::green() {
if (showColors) std::cout << "\033[0;32m";
}
2011-08-03 16:26:39 +00:00
2011-08-30 19:59:09 +00:00
void ConsoleOutput::clear() {
if (showColors) std::cout << "\033[m";
}
2011-08-03 16:26:39 +00:00
2011-08-30 19:59:09 +00:00
void ConsoleOutput::red() {
if (showColors) std::cout << "\033[0;31m";
}
2011-08-26 15:18:04 +00:00
2011-08-30 19:59:09 +00:00
void ConsoleOutput::yellow()
{
if (showColors) std::cout << "\033[0;33m";
}
2011-08-30 19:59:09 +00:00
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;
}
2011-08-29 17:35:36 +00:00
2011-08-30 19:59:09 +00:00
void ConsoleOutput::consoleLog(const QString &msg) {
if (!consoleLogUsed) {
2011-08-29 17:35:36 +00:00
*outputIO << std::endl;
2011-08-30 19:59:09 +00:00
consoleLogUsed = true;
2011-08-29 17:35:36 +00:00
}
2011-08-30 19:59:09 +00:00
green();
*outputIO << "[console] ";
if (msg.contains("\n"))
2011-08-29 17:35:36 +00:00
*outputIO << std::endl;
2011-08-30 19:59:09 +00:00
clear();
*outputIO << qPrintable(msg);
*outputIO << std::endl;
}
2011-08-29 17:35:36 +00:00
2011-08-30 19:59:09 +00:00
void ConsoleOutput::logSpecFilename(const QString &name) {
*outputIO << std::endl << std::endl;
red();
*outputIO << qPrintable(name) << std::endl;
clear();
}
2011-08-30 19:59:09 +00:00
void ConsoleOutput::logSpecResult(const QString &result) {
QStringList lines = result.split("\n");
QStringListIterator linesIterator(lines);
2011-08-30 19:59:09 +00:00
red();
while (linesIterator.hasNext()) {
*outputIO << " " << qPrintable(linesIterator.next()) << std::endl;
yellow();
}
2011-08-30 19:59:09 +00:00
clear();
}
2011-08-30 19:59:09 +00:00
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();
}
2011-08-30 19:59:09 +00:00
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";
}
2011-08-30 19:59:09 +00:00
*outputIO << ", ";
*outputIO << qPrintable(failedTests) << " ";
if (failedTests == "1") {
*outputIO << "failure";
} else {
*outputIO << "failures";
}
2011-08-30 19:59:09 +00:00
*outputIO << ", ";
*outputIO << qPrintable(duration) << " ";
if (duration == "1") {
*outputIO << "sec.";
} else {
*outputIO << "secs.";
}
2011-08-03 16:26:39 +00:00
}
2011-08-29 17:35:36 +00:00