Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
some more c++ cleanup
  • Loading branch information
johnbintz committed Aug 29, 2011
1 parent aeb6d57 commit 904be27
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,3 +10,4 @@ ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner
moc_*.*
.DS_Store
hydra-runner.log
jhw-test
36 changes: 35 additions & 1 deletion ext/jasmine-webkit-specrunner/ConsoleOutput.cpp
Expand Up @@ -2,7 +2,8 @@

namespace HeadlessSpecRunner {
ConsoleOutput::ConsoleOutput() : QObject(),
showColors(false) {
showColors(false),
consoleLogUsed(false) {
outputIO = &std::cout;
}

Expand All @@ -12,6 +13,7 @@ namespace HeadlessSpecRunner {
clear();
outputIO->flush();

consoleLogUsed = false;
successes.push(specDetail);
}

Expand All @@ -22,6 +24,7 @@ namespace HeadlessSpecRunner {
clear();
outputIO->flush();

consoleLogUsed = false;
failures.push(specDetail);
}

Expand All @@ -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();
}
}

5 changes: 5 additions & 0 deletions ext/jasmine-webkit-specrunner/ConsoleOutput.h
Expand Up @@ -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();
Expand Down
42 changes: 42 additions & 0 deletions ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion ext/jasmine-webkit-specrunner/ConsoleOutput_test.h
Expand Up @@ -18,9 +18,12 @@ namespace HeadlessSpecRunner {
void testPassed();
void testFailed();
void testErrorLog();
void testInternalLog();
void testConsoleLog();
void testConsoleLogUsed();
void testLogSpecFilename();
};
}

#endif


4 changes: 2 additions & 2 deletions ext/jasmine-webkit-specrunner/Page.cpp
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
33 changes: 5 additions & 28 deletions ext/jasmine-webkit-specrunner/Runner.cpp
Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion ext/jasmine-webkit-specrunner/Runner.h
Expand Up @@ -46,7 +46,6 @@ namespace HeadlessSpecRunner {
bool showColors;
bool isFinished;
bool didFail;
bool consoleNotUsedThisRun;
QQueue<QString> runnerFiles;
QString reportFilename;
QStack<QString> failedSpecs;
Expand Down
Binary file removed ext/jasmine-webkit-specrunner/jhw-test
Binary file not shown.
16 changes: 12 additions & 4 deletions ext/jasmine-webkit-specrunner/test.rb
@@ -1,15 +1,23 @@
#!/usr/bin/env ruby

require 'fileutils'

system %{make clean}

$: << File.expand_path("../../../lib", __FILE__)
require 'qt/qmake'

Dir['*_test.pro'].each do |test|
$: << File.expand_path("../../../lib", __FILE__)
FileUtils.rm_f('jhw-test')

require 'qt/qmake'
Qt::Qmake.make!('jasmine-headless-webkit', test)

system %{./jhw-test}
if $?.exitstatus != 0
if File.file?('jhw-test')
system %{./jhw-test}
if $?.exitstatus != 0
exit 1
end
else
exit 1
end
end
Expand Down

0 comments on commit 904be27

Please sign in to comment.