some more c++ cleanup

This commit is contained in:
John Bintz 2011-08-29 13:35:36 -04:00
parent aeb6d57505
commit 904be27e42
10 changed files with 107 additions and 38 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner
moc_*.* moc_*.*
.DS_Store .DS_Store
hydra-runner.log hydra-runner.log
jhw-test

View File

@ -2,7 +2,8 @@
namespace HeadlessSpecRunner { namespace HeadlessSpecRunner {
ConsoleOutput::ConsoleOutput() : QObject(), ConsoleOutput::ConsoleOutput() : QObject(),
showColors(false) { showColors(false),
consoleLogUsed(false) {
outputIO = &std::cout; outputIO = &std::cout;
} }
@ -12,6 +13,7 @@ namespace HeadlessSpecRunner {
clear(); clear();
outputIO->flush(); outputIO->flush();
consoleLogUsed = false;
successes.push(specDetail); successes.push(specDetail);
} }
@ -22,6 +24,7 @@ namespace HeadlessSpecRunner {
clear(); clear();
outputIO->flush(); outputIO->flush();
consoleLogUsed = false;
failures.push(specDetail); failures.push(specDetail);
} }
@ -44,4 +47,35 @@ namespace HeadlessSpecRunner {
*outputIO << qPrintable(sourceID) << ":" << lineNumber << " : " << qPrintable(msg); *outputIO << qPrintable(sourceID) << ":" << lineNumber << " : " << qPrintable(msg);
*outputIO << std::endl; *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;
}
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();
}
} }

View File

@ -13,10 +13,15 @@ namespace HeadlessSpecRunner {
void passed(const QString &specDetail); void passed(const QString &specDetail);
void failed(const QString &specDetail); void failed(const QString &specDetail);
void errorLog(const QString &msg, int lineNumber, const QString &sourceID); 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);
std::ostream *outputIO; std::ostream *outputIO;
QStack<QString> successes; QStack<QString> successes;
QStack<QString> failures; QStack<QString> failures;
bool showColors; bool showColors;
bool consoleLogUsed;
private: private:
void green(); void green();
void clear(); void clear();

View File

@ -13,22 +13,26 @@ namespace HeadlessSpecRunner {
stringstream buffer; stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output; HeadlessSpecRunner::ConsoleOutput output;
output.consoleLogUsed = true;
output.outputIO = &buffer; output.outputIO = &buffer;
output.passed("test"); output.passed("test");
QVERIFY(buffer.str() == "."); QVERIFY(buffer.str() == ".");
QVERIFY(output.successes.size() == 1); QVERIFY(output.successes.size() == 1);
QVERIFY(output.failures.size() == 0); QVERIFY(output.failures.size() == 0);
QVERIFY(output.consoleLogUsed == false);
} }
void ConsoleOutputTest::testFailed() { void ConsoleOutputTest::testFailed() {
stringstream buffer; stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output; HeadlessSpecRunner::ConsoleOutput output;
output.consoleLogUsed = true;
output.outputIO = &buffer; output.outputIO = &buffer;
output.failed("test"); output.failed("test");
QVERIFY(buffer.str() == "F"); QVERIFY(buffer.str() == "F");
QVERIFY(output.successes.size() == 0); QVERIFY(output.successes.size() == 0);
QVERIFY(output.failures.size() == 1); QVERIFY(output.failures.size() == 1);
QVERIFY(output.consoleLogUsed == false);
} }
void ConsoleOutputTest::testErrorLog() { void ConsoleOutputTest::testErrorLog() {
@ -39,6 +43,44 @@ namespace HeadlessSpecRunner {
output.errorLog("message", 1, "source"); output.errorLog("message", 1, "source");
QVERIFY(buffer.str() == "[error] source:1 : message\n"); QVERIFY(buffer.str() == "[error] source:1 : message\n");
} }
void ConsoleOutputTest::testInternalLog() {
stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output;
output.outputIO = &buffer;
output.internalLog("note", "message");
QVERIFY(buffer.str() == "[note] message\n");
}
void ConsoleOutputTest::testConsoleLog() {
stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output;
output.consoleLogUsed = false;
output.outputIO = &buffer;
output.consoleLog("log");
QVERIFY(buffer.str() == "\n[console] log\n");
}
void ConsoleOutputTest::testConsoleLogUsed() {
stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output;
output.consoleLogUsed = true;
output.outputIO = &buffer;
output.consoleLog("log");
QVERIFY(buffer.str() == "[console] log\n");
}
void ConsoleOutputTest::testLogSpecFilename() {
stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output;
output.outputIO = &buffer;
output.logSpecFilename("whatever");
QVERIFY(buffer.str() == "\n\nwhatever\n");
}
} }
QTEST_MAIN(HeadlessSpecRunner::ConsoleOutputTest); QTEST_MAIN(HeadlessSpecRunner::ConsoleOutputTest);

View File

@ -18,9 +18,12 @@ namespace HeadlessSpecRunner {
void testPassed(); void testPassed();
void testFailed(); void testFailed();
void testErrorLog(); void testErrorLog();
void testInternalLog();
void testConsoleLog();
void testConsoleLogUsed();
void testLogSpecFilename();
}; };
} }
#endif #endif

View File

@ -11,7 +11,7 @@ namespace HeadlessSpecRunner {
emit consoleLog(message, lineNumber, sourceID); emit consoleLog(message, lineNumber, sourceID);
} }
bool Page::javaScriptConfirm(QWebFrame *frame, const QString &msg) { bool Page::javaScriptConfirm(QWebFrame*, const QString&) {
if (confirmResult) { if (confirmResult) {
emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true."); emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true.");
return true; return true;
@ -21,7 +21,7 @@ namespace HeadlessSpecRunner {
} }
} }
void Page::javaScriptAlert(QWebFrame *frame, const QString &msg) { void Page::javaScriptAlert(QWebFrame*, const QString &msg) {
emit internalLog("alert", msg); emit internalLog("alert", msg);
} }

View File

@ -14,8 +14,7 @@ namespace HeadlessSpecRunner {
, usedConsole(false) , usedConsole(false)
, showColors(false) , showColors(false)
, isFinished(false) , isFinished(false)
, didFail(false) , didFail(false) {
, consoleNotUsedThisRun(false) {
m_page.settings()->enablePersistentStorage(); m_page.settings()->enablePersistentStorage();
connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool))); connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool)));
connect(&m_page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(errorLog(QString, int, QString))); connect(&m_page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(errorLog(QString, int, QString)));
@ -100,13 +99,11 @@ namespace HeadlessSpecRunner {
void Runner::specPassed() void Runner::specPassed()
{ {
consoleNotUsedThisRun = true;
consoleOutput.passed(""); consoleOutput.passed("");
} }
void Runner::specFailed(const QString &specDetail) void Runner::specFailed(const QString &specDetail)
{ {
consoleNotUsedThisRun = true;
consoleOutput.failed(""); consoleOutput.failed("");
didFail = true; didFail = true;
failedSpecs.push(specDetail); failedSpecs.push(specDetail);
@ -122,45 +119,25 @@ namespace HeadlessSpecRunner {
} }
void Runner::internalLog(const QString &note, const QString &msg) { void Runner::internalLog(const QString &note, const QString &msg) {
red(); consoleOutput.internalLog(note, msg);
std::cout << "[" << qPrintable(note) << "] ";
clear();
std::cout << qPrintable(msg);
std::cout << std::endl;
} }
void Runner::log(const QString &msg) void Runner::log(const QString &msg)
{ {
usedConsole = true; usedConsole = true;
green(); consoleOutput.consoleLog(msg);
if (consoleNotUsedThisRun) {
std::cout << std::endl;
consoleNotUsedThisRun = false;
}
std::cout << "[console] ";
clear();
if (msg.contains("\n"))
std::cout << std::endl;
std::cout << qPrintable(msg);
std::cout << std::endl;
} }
void Runner::leavePageAttempt(const QString &msg) void Runner::leavePageAttempt(const QString &msg)
{ {
red(); consoleOutput.internalLog("error", msg);
std::cout << "[error] ";
clear();
std::cout << qPrintable(msg) << std::endl;
m_page.oneFalseConfirm(); m_page.oneFalseConfirm();
hasErrors = true; hasErrors = true;
} }
void Runner::printName(const QString &name) void Runner::printName(const QString &name)
{ {
std::cout << std::endl << std::endl; consoleOutput.logSpecFilename(name);
red();
std::cout << qPrintable(name) << std::endl;
clear();
} }
void Runner::printResult(const QString &result) void Runner::printResult(const QString &result)

View File

@ -46,7 +46,6 @@ namespace HeadlessSpecRunner {
bool showColors; bool showColors;
bool isFinished; bool isFinished;
bool didFail; bool didFail;
bool consoleNotUsedThisRun;
QQueue<QString> runnerFiles; QQueue<QString> runnerFiles;
QString reportFilename; QString reportFilename;
QStack<QString> failedSpecs; QStack<QString> failedSpecs;

View File

@ -1,16 +1,24 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'fileutils'
system %{make clean} system %{make clean}
Dir['*_test.pro'].each do |test| $: << File.expand_path("../../../lib", __FILE__)
$: << File.expand_path("../../../lib", __FILE__) require 'qt/qmake'
Dir['*_test.pro'].each do |test|
FileUtils.rm_f('jhw-test')
require 'qt/qmake'
Qt::Qmake.make!('jasmine-headless-webkit', test) Qt::Qmake.make!('jasmine-headless-webkit', test)
if File.file?('jhw-test')
system %{./jhw-test} system %{./jhw-test}
if $?.exitstatus != 0 if $?.exitstatus != 0
exit 1 exit 1
end end
else
exit 1
end
end end