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_*.*
.DS_Store
hydra-runner.log
jhw-test

View File

@ -2,7 +2,8 @@
namespace HeadlessSpecRunner {
ConsoleOutput::ConsoleOutput() : QObject(),
showColors(false) {
showColors(false),
consoleLogUsed(false) {
outputIO = &std::cout;
}
@ -12,6 +13,7 @@ namespace HeadlessSpecRunner {
clear();
outputIO->flush();
consoleLogUsed = false;
successes.push(specDetail);
}
@ -22,6 +24,7 @@ namespace HeadlessSpecRunner {
clear();
outputIO->flush();
consoleLogUsed = false;
failures.push(specDetail);
}
@ -44,4 +47,35 @@ namespace HeadlessSpecRunner {
*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;
}
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 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);
std::ostream *outputIO;
QStack<QString> successes;
QStack<QString> failures;
bool showColors;
bool consoleLogUsed;
private:
void green();
void clear();

View File

@ -13,22 +13,26 @@ namespace HeadlessSpecRunner {
stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output;
output.consoleLogUsed = true;
output.outputIO = &buffer;
output.passed("test");
QVERIFY(buffer.str() == ".");
QVERIFY(output.successes.size() == 1);
QVERIFY(output.failures.size() == 0);
QVERIFY(output.consoleLogUsed == false);
}
void ConsoleOutputTest::testFailed() {
stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output;
output.consoleLogUsed = true;
output.outputIO = &buffer;
output.failed("test");
QVERIFY(buffer.str() == "F");
QVERIFY(output.successes.size() == 0);
QVERIFY(output.failures.size() == 1);
QVERIFY(output.consoleLogUsed == false);
}
void ConsoleOutputTest::testErrorLog() {
@ -39,6 +43,44 @@ namespace HeadlessSpecRunner {
output.errorLog("message", 1, "source");
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);

View File

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

View File

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

View File

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

View File

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

View File

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