factor out the console reporting from the runner
This commit is contained in:
parent
904be27e42
commit
0c368ec9f2
@ -17,8 +17,7 @@ namespace HeadlessSpecRunner {
|
|||||||
successes.push(specDetail);
|
successes.push(specDetail);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleOutput::failed(const QString &specDetail)
|
void ConsoleOutput::failed(const QString &specDetail) {
|
||||||
{
|
|
||||||
red();
|
red();
|
||||||
*outputIO << 'F';
|
*outputIO << 'F';
|
||||||
clear();
|
clear();
|
||||||
@ -40,6 +39,11 @@ namespace HeadlessSpecRunner {
|
|||||||
if (showColors) std::cout << "\033[0;31m";
|
if (showColors) std::cout << "\033[0;31m";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
red();
|
||||||
*outputIO << "[error] ";
|
*outputIO << "[error] ";
|
||||||
@ -77,5 +81,62 @@ namespace HeadlessSpecRunner {
|
|||||||
*outputIO << qPrintable(name) << std::endl;
|
*outputIO << qPrintable(name) << std::endl;
|
||||||
clear();
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
*outputIO << ", ";
|
||||||
|
|
||||||
|
*outputIO << qPrintable(failedTests) << " ";
|
||||||
|
if (failedTests == "1") {
|
||||||
|
*outputIO << "failure";
|
||||||
|
} else {
|
||||||
|
*outputIO << "failures";
|
||||||
|
}
|
||||||
|
|
||||||
|
*outputIO << ", ";
|
||||||
|
|
||||||
|
*outputIO << qPrintable(duration) << " ";
|
||||||
|
if (duration == "1") {
|
||||||
|
*outputIO << "sec.";
|
||||||
|
} else {
|
||||||
|
*outputIO << "secs.";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,11 @@ namespace HeadlessSpecRunner {
|
|||||||
void internalLog(const QString ¬e, const QString &msg);
|
void internalLog(const QString ¬e, const QString &msg);
|
||||||
void consoleLog(const QString &msg);
|
void consoleLog(const QString &msg);
|
||||||
void logSpecFilename(const QString &name);
|
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;
|
std::ostream *outputIO;
|
||||||
QStack<QString> successes;
|
QStack<QString> successes;
|
||||||
@ -26,6 +31,8 @@ namespace HeadlessSpecRunner {
|
|||||||
void green();
|
void green();
|
||||||
void clear();
|
void clear();
|
||||||
void red();
|
void red();
|
||||||
|
void yellow();
|
||||||
|
void formatTestResults(const QString &totalTests, const QString &failedTests, const QString &duration);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,51 @@ namespace HeadlessSpecRunner {
|
|||||||
output.logSpecFilename("whatever");
|
output.logSpecFilename("whatever");
|
||||||
QVERIFY(buffer.str() == "\n\nwhatever\n");
|
QVERIFY(buffer.str() == "\n\nwhatever\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConsoleOutputTest::testLogSpecResult() {
|
||||||
|
stringstream buffer;
|
||||||
|
HeadlessSpecRunner::ConsoleOutput output;
|
||||||
|
|
||||||
|
output.outputIO = &buffer;
|
||||||
|
output.logSpecResult("whatever");
|
||||||
|
QVERIFY(buffer.str() == " whatever\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleOutputTest::testReportResultsFailedSingular() {
|
||||||
|
stringstream buffer;
|
||||||
|
HeadlessSpecRunner::ConsoleOutput output;
|
||||||
|
|
||||||
|
output.outputIO = &buffer;
|
||||||
|
output.reportFailure("1", "1", "1");
|
||||||
|
QVERIFY(buffer.str() == "\nFAIL: 1 test, 1 failure, 1 sec.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleOutputTest::testReportResultsFailedPlural() {
|
||||||
|
stringstream buffer;
|
||||||
|
HeadlessSpecRunner::ConsoleOutput output;
|
||||||
|
|
||||||
|
output.outputIO = &buffer;
|
||||||
|
output.reportFailure("2", "2", "2");
|
||||||
|
QVERIFY(buffer.str() == "\nFAIL: 2 tests, 2 failures, 2 secs.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleOutputTest::testReportResultsSucceeded() {
|
||||||
|
stringstream buffer;
|
||||||
|
HeadlessSpecRunner::ConsoleOutput output;
|
||||||
|
|
||||||
|
output.outputIO = &buffer;
|
||||||
|
output.reportSuccess("2", "2", "2");
|
||||||
|
QVERIFY(buffer.str() == "\nPASS: 2 tests, 2 failures, 2 secs.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleOutputTest::testReportResultsSucceededWithJSErrors() {
|
||||||
|
stringstream buffer;
|
||||||
|
HeadlessSpecRunner::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(HeadlessSpecRunner::ConsoleOutputTest);
|
||||||
|
@ -22,6 +22,12 @@ namespace HeadlessSpecRunner {
|
|||||||
void testConsoleLog();
|
void testConsoleLog();
|
||||||
void testConsoleLogUsed();
|
void testConsoleLogUsed();
|
||||||
void testLogSpecFilename();
|
void testLogSpecFilename();
|
||||||
|
void testLogSpecResult();
|
||||||
|
|
||||||
|
void testReportResultsFailedSingular();
|
||||||
|
void testReportResultsFailedPlural();
|
||||||
|
void testReportResultsSucceeded();
|
||||||
|
void testReportResultsSucceededWithJSErrors();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,11 +7,11 @@ namespace HeadlessSpecRunner {
|
|||||||
PageTest::PageTest() : QObject(), internalLogCalled(false) {
|
PageTest::PageTest() : QObject(), internalLogCalled(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageTest::internalLog(const QString ¬e, const QString &msg) {
|
void PageTest::internalLog(const QString &, const QString &) {
|
||||||
internalLogCalled = true;
|
internalLogCalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageTest::consoleLog(const QString &message, int lineNumber, const QString &source) {
|
void PageTest::consoleLog(const QString &, int, const QString &) {
|
||||||
consoleLogCalled = true;
|
consoleLogCalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ namespace HeadlessSpecRunner {
|
|||||||
, m_runs(0)
|
, m_runs(0)
|
||||||
, hasErrors(false)
|
, hasErrors(false)
|
||||||
, usedConsole(false)
|
, usedConsole(false)
|
||||||
, showColors(false)
|
|
||||||
, isFinished(false)
|
, isFinished(false)
|
||||||
, didFail(false) {
|
, didFail(false) {
|
||||||
m_page.settings()->enablePersistentStorage();
|
m_page.settings()->enablePersistentStorage();
|
||||||
@ -64,7 +63,6 @@ namespace HeadlessSpecRunner {
|
|||||||
|
|
||||||
void Runner::setColors(bool colors)
|
void Runner::setColors(bool colors)
|
||||||
{
|
{
|
||||||
showColors = colors;
|
|
||||||
consoleOutput.showColors = colors;
|
consoleOutput.showColors = colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,30 +71,10 @@ namespace HeadlessSpecRunner {
|
|||||||
reportFilename = file;
|
reportFilename = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner::red()
|
|
||||||
{
|
|
||||||
if (showColors) std::cout << "\033[0;31m";
|
|
||||||
}
|
|
||||||
|
|
||||||
void Runner::green()
|
|
||||||
{
|
|
||||||
if (showColors) std::cout << "\033[0;32m";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Runner::hasError() {
|
bool Runner::hasError() {
|
||||||
return hasErrors;
|
return hasErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner::yellow()
|
|
||||||
{
|
|
||||||
if (showColors) std::cout << "\033[0;33m";
|
|
||||||
}
|
|
||||||
|
|
||||||
void Runner::clear()
|
|
||||||
{
|
|
||||||
if (showColors) std::cout << "\033[m";
|
|
||||||
}
|
|
||||||
|
|
||||||
void Runner::specPassed()
|
void Runner::specPassed()
|
||||||
{
|
{
|
||||||
consoleOutput.passed("");
|
consoleOutput.passed("");
|
||||||
@ -142,32 +120,21 @@ namespace HeadlessSpecRunner {
|
|||||||
|
|
||||||
void Runner::printResult(const QString &result)
|
void Runner::printResult(const QString &result)
|
||||||
{
|
{
|
||||||
red();
|
consoleOutput.logSpecResult(result);
|
||||||
std::cout << " " << qPrintable(result) << std::endl;
|
|
||||||
clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner::finishSuite(const QString &duration, const QString &total, const QString& failed)
|
void Runner::finishSuite(const QString &duration, const QString &total, const QString& failed)
|
||||||
{
|
{
|
||||||
std::cout << std::endl;
|
|
||||||
if (didFail) {
|
if (didFail) {
|
||||||
red();
|
consoleOutput.reportFailure(total, failed, duration);
|
||||||
std::cout << "FAIL: ";
|
|
||||||
} else {
|
} else {
|
||||||
green();
|
|
||||||
std::cout << "PASS";
|
|
||||||
|
|
||||||
if (hasErrors) {
|
if (hasErrors) {
|
||||||
std::cout << " with JS errors";
|
consoleOutput.reportSuccessWithJSErrors(total, failed, duration);
|
||||||
|
} else {
|
||||||
|
consoleOutput.reportSuccess(total, failed, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << ": ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << qPrintable(total) << " tests, " << qPrintable(failed) << " failures, " << qPrintable(duration) << " secs.";
|
|
||||||
clear();
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
if (!reportFilename.isEmpty()) {
|
if (!reportFilename.isEmpty()) {
|
||||||
QFile reportFH(reportFilename);
|
QFile reportFH(reportFilename);
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@ namespace HeadlessSpecRunner {
|
|||||||
int m_runs;
|
int m_runs;
|
||||||
bool hasErrors;
|
bool hasErrors;
|
||||||
bool usedConsole;
|
bool usedConsole;
|
||||||
bool showColors;
|
|
||||||
bool isFinished;
|
bool isFinished;
|
||||||
bool didFail;
|
bool didFail;
|
||||||
QQueue<QString> runnerFiles;
|
QQueue<QString> runnerFiles;
|
||||||
@ -52,10 +51,6 @@ namespace HeadlessSpecRunner {
|
|||||||
|
|
||||||
HeadlessSpecRunner::ConsoleOutput consoleOutput;
|
HeadlessSpecRunner::ConsoleOutput consoleOutput;
|
||||||
|
|
||||||
void red();
|
|
||||||
void green();
|
|
||||||
void yellow();
|
|
||||||
void clear();
|
|
||||||
void loadSpec();
|
void loadSpec();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user