big merge

This commit is contained in:
John Bintz 2011-08-23 19:55:48 -04:00
commit 64037b205f
30 changed files with 407 additions and 46 deletions

View File

@ -13,3 +13,4 @@ gem 'growl'
gem 'rake', '0.8.7'
gem 'mocha', '0.9.12'
gem 'guard-jasmine-headless-webkit'
gem 'facter'

View File

@ -4,7 +4,11 @@
#
guard 'shell' do
watch(%r{ext/jasmine-webkit-specrunner/.*\.(cpp|h)}) { compile }
watch(%r{ext/jasmine-webkit-specrunner/.*\.(cpp|h|pro|pri)}) { |m|
if !m[0]['moc_']
compile
end
}
end
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
@ -22,7 +26,7 @@ guard 'jasmine-headless-webkit', :all_on_start => false do
end
def compile
system %{cd ext/jasmine-webkit-specrunner && ruby extconf.rb}
system %{cd ext/jasmine-webkit-specrunner && ruby test.rb && ruby extconf.rb}
end
compile

View File

@ -0,0 +1,39 @@
#include "ConsoleOutput.h"
namespace HeadlessSpecRunner {
ConsoleOutput::ConsoleOutput() : QObject(),
showColors(false) {
outputIO = &std::cout;
}
void ConsoleOutput::passed(const QString &specDetail) {
green();
*outputIO << '.';
clear();
fflush(stdout);
successes.push(specDetail);
}
void ConsoleOutput::failed(const QString &specDetail)
{
red();
*outputIO << 'F';
clear();
fflush(stdout);
failures.push(specDetail);
}
void ConsoleOutput::green() {
if (showColors) std::cout << "\033[0;32m";
}
void ConsoleOutput::clear() {
if (showColors) std::cout << "\033[m";
}
void ConsoleOutput::red() {
if (showColors) std::cout << "\033[0;31m";
}
}

View File

@ -0,0 +1,26 @@
#ifndef JHW_CONSOLE_OUTPUT
#define JHW_CONSOLE_OUTPUT
#include <QObject>
#include <iostream>
#include <QStack>
namespace HeadlessSpecRunner {
class ConsoleOutput : public QObject {
Q_OBJECT
public:
ConsoleOutput();
void passed(const QString &specDetail);
void failed(const QString &specDetail);
std::ostream *outputIO;
QStack<QString> successes;
QStack<QString> failures;
bool showColors;
private:
void green();
void clear();
void red();
};
}
#endif

View File

@ -0,0 +1,36 @@
#include <QtTest/QtTest>
#include "ConsoleOutput.h"
#include "ConsoleOutput_test.h"
using namespace std;
namespace HeadlessSpecRunner {
ConsoleOutputTest::ConsoleOutputTest() : QObject() {
}
void ConsoleOutputTest::testPassed() {
stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output;
output.outputIO = &buffer;
output.passed("test");
QVERIFY(buffer.str() == ".");
QVERIFY(output.successes.size() == 1);
QVERIFY(output.failures.size() == 0);
}
void ConsoleOutputTest::testFailed() {
stringstream buffer;
HeadlessSpecRunner::ConsoleOutput output;
output.outputIO = &buffer;
output.failed("test");
QVERIFY(buffer.str() == "F");
QVERIFY(output.successes.size() == 0);
QVERIFY(output.failures.size() == 1);
}
}
QTEST_MAIN(HeadlessSpecRunner::ConsoleOutputTest);

View File

@ -0,0 +1,25 @@
#ifndef JHW_TEST_PAGE
#define JHW_TEST_PAGE
#include <QtTest/QtTest>
#include <iostream>
#include <sstream>
#include <string>
#include "ConsoleOutput.h"
namespace HeadlessSpecRunner {
class ConsoleOutputTest : public QObject {
Q_OBJECT
public:
ConsoleOutputTest();
private slots:
void testPassed();
void testFailed();
};
}
#endif

View File

@ -0,0 +1,7 @@
include(common.pri)
include(test.pri)
SOURCES += ConsoleOutput_test.cpp
HEADERS += ConsoleOutput_test.h

View File

@ -0,0 +1,45 @@
#include <QtTest/QtTest>
#include "Page.h"
#include "Page_test.h"
namespace HeadlessSpecRunner {
PageTest::PageTest() : QObject(), internalLogCalled(false) {
}
void PageTest::internalLog(const QString &note, const QString &msg) {
internalLogCalled = true;
}
void PageTest::consoleLog(const QString &message, int lineNumber, const QString &source) {
consoleLogCalled = true;
}
void PageTest::testJavaScriptConfirmWithLog() {
connect(&page, SIGNAL(internalLog(QString, QString)), this, SLOT(internalLog(QString, QString)));
internalLogCalled = false;
page.mainFrame()->setHtml("<script>confirm('test')</script>");
QVERIFY(internalLogCalled);
}
void PageTest::testJavaScriptConfirmWithoutLog() {
connect(&page, SIGNAL(internalLog(QString, QString)), this, SLOT(internalLog(QString, QString)));
internalLogCalled = false;
page.oneFalseConfirm();
page.mainFrame()->setHtml("<script>confirm('test')</script>");
QVERIFY(!internalLogCalled);
}
void PageTest::testJavaScriptConsoleMessage() {
connect(&page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(consoleLog(QString, int, QString)));
consoleLogCalled = false;
page.mainFrame()->setHtml("<script>cats();</script>");
QVERIFY(consoleLogCalled);
}
}
QTEST_MAIN(HeadlessSpecRunner::PageTest);

View File

@ -0,0 +1,29 @@
#ifndef JHW_TEST_PAGE
#define JHW_TEST_PAGE
#include <QtTest/QtTest>
#include "Page.h"
namespace HeadlessSpecRunner {
class PageTest : public QObject {
Q_OBJECT
public:
PageTest();
private:
bool internalLogCalled;
bool consoleLogCalled;
HeadlessSpecRunner::Page page;
private slots:
void internalLog(const QString &note, const QString &msg);
void consoleLog(const QString &message, int lineNumber, const QString &source);
void testJavaScriptConfirmWithLog();
void testJavaScriptConfirmWithoutLog();
void testJavaScriptConsoleMessage();
};
}
#endif

View File

@ -0,0 +1,6 @@
include(common.pri)
include(test.pri)
SOURCES += Page_test.cpp
HEADERS += Page_test.h

View File

@ -66,6 +66,7 @@ namespace HeadlessSpecRunner {
void Runner::setColors(bool colors)
{
showColors = colors;
consoleOutput.showColors = colors;
}
void Runner::reportFile(const QString &file)
@ -100,21 +101,15 @@ namespace HeadlessSpecRunner {
void Runner::specPassed()
{
consoleNotUsedThisRun = true;
green();
std::cout << '.';
clear();
fflush(stdout);
consoleOutput.passed("");
}
void Runner::specFailed(const QString &specDetail)
{
consoleNotUsedThisRun = true;
consoleOutput.failed("");
didFail = true;
red();
std::cout << 'F';
failedSpecs.push(specDetail);
clear();
fflush(stdout);
}
void Runner::errorLog(const QString &msg, int lineNumber, const QString &sourceID)

View File

@ -9,6 +9,7 @@
#include <QQueue>
#include "Page.h"
#include "ConsoleOutput.h"
namespace HeadlessSpecRunner {
class Runner: public QObject {
@ -50,6 +51,8 @@ namespace HeadlessSpecRunner {
QString reportFilename;
QStack<QString> failedSpecs;
HeadlessSpecRunner::ConsoleOutput consoleOutput;
void red();
void green();
void yellow();

View File

@ -0,0 +1,9 @@
TEMPLATE = app
CONFIG -= app_bundle
QMAKE_INFO_PLIST = Info.plist
QMAKESPEC = macx-g++
QT += network webkit
SOURCES = Page.cpp Runner.cpp ConsoleOutput.cpp
HEADERS = Page.h Runner.h ConsoleOutput.h

View File

@ -4,5 +4,6 @@ $: << File.expand_path("../../../lib", __FILE__)
require 'qt/qmake'
Qt::Qmake.make!('jasmine-headless-webkit')
system %{make clean}
Qt::Qmake.make!('jasmine-headless-webkit', 'specrunner.pro')

View File

@ -0,0 +1,19 @@
######################################################################
# Automatically generated by qmake (2.01a) Tue Aug 2 10:37:48 2011
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += . HeadlessSpecRunner Test
INCLUDEPATH += . HeadlessSpecRunner Test
# Input
HEADERS += HeadlessSpecRunner/ConsoleOutput.h \
HeadlessSpecRunner/Page.h \
HeadlessSpecRunner/Runner.h \
Test/Page_test.h
SOURCES += specrunner.cpp \
HeadlessSpecRunner/ConsoleOutput.cpp \
HeadlessSpecRunner/Page.cpp \
HeadlessSpecRunner/Runner.cpp \
Test/Page_test.cpp

Binary file not shown.

View File

@ -21,8 +21,8 @@
THE SOFTWARE.
*/
#include "HeadlessSpecRunner/Page.h"
#include "HeadlessSpecRunner/Runner.h"
#include "Page.h"
#include "Runner.h"
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
#error Use Qt 4.7 or later version

View File

@ -1,8 +1,4 @@
TEMPLATE = app
CONFIG -= app_bundle
include(common.pri)
SOURCES += specrunner.cpp
TARGET = jasmine-webkit-specrunner
SOURCES = HeadlessSpecRunner/Page.cpp HeadlessSpecRunner/Runner.cpp specrunner.cpp
HEADERS = HeadlessSpecRunner/Page.h HeadlessSpecRunner/Runner.h
QT += network webkit
QMAKE_INFO_PLIST = Info.plist
QMAKESPEC = macx-gcc

View File

@ -0,0 +1,3 @@
TARGET = jhw-test
QT += testlib

View File

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

View File

@ -2,9 +2,14 @@ require 'rbconfig'
require 'rubygems'
require 'rubygems/version'
begin
require 'facter'
rescue LoadError
warn 'Including Facter allows for detection of # of cpus, resulting in faster compilations.'
end
module Qt
class NotInstalledError < StandardError; end
class Qmake
class << self
QMAKES = %w{qmake-qt4 qmake}
@ -17,25 +22,34 @@ module Qt
make_path != nil
end
def command
case platform
def command(project_file = nil)
spec = (case platform
when :linux
"#{path} -spec linux-g++"
"linux-g++"
when :freebsd
"#{path} -spec freebsd-g++"
"freebsd-g++"
when :mac_os_x
"#{path} -spec macx-g++"
end
"macx-g++"
end)
command = "#{path} -spec #{spec}"
command << " #{project_file}" if project_file
command
end
def make!(name)
def make!(name, project_file = nil)
@name = name
check_make!
check_qmake!
system command
system %{make}
system command(project_file)
system %{make #{make_options}}
end
def make_options
"-j#{number_of_cpus}"
end
#
@ -81,6 +95,14 @@ module Qt
end
private
def number_of_cpus
if defined?(Facter)
Facter.sp_number_processors rescue Facter.processorcount
else
1
end
end
def get_exe_path(command)
path = %x{which #{command}}.strip
path = nil if path == ''
@ -120,6 +142,7 @@ MSG
when :freebsd
<<-MSG
Install /usr/ports/www/qt4-webkit and /usr/ports/devel/qmake4.
MSG
MSG
when :mac_os_x
<<-MSG

11
script/gemfile Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'penchant'
if Penchant::Gemfile.do_full_env_switch!(ARGV[0])
puts "Gemfile switched to #{ARGV[0]}"
else
exit 0
end

15
script/hooks/pre-commit Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
OLD_GIT_DIR=$GIT_DIR
if [ "$(penchant gemfile-env)" != "remote" ]; then
unset GIT_DIR
penchant gemfile remote
GIT_DIR=$OLD_GIT_DIR
git add Gemfile*
fi
bundle exec rake
R=$?
if [ $R -ne 0 ]; then exit $R; fi

35
script/initialize-environment Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env ruby
if File.file?('Gemfile.erb')
pwd = Dir.pwd
Dir.chdir '..' do
File.readlines(File.join(pwd, 'Gemfile.erb')).find_all { |line| line[':git'] }.each do |line|
repo = line[%r{:git => (['"])(.*)\1}, 2]
puts "Installing #{repo}"
system %{git clone #{repo}}
end
end
puts "Bundling for local environment"
system %{script/gemfile local}
else
puts "Bundling..."
system %{bundle}
end
puts "Installing git hooks"
system %{script/install-git-hooks}
bundle = File.file?('Gemfile') ? 'bundle exec' : ''
command = [ bundle, 'rake', '-s', '-T', 'bootstrap' ]
if !(%x{#{command.join(' ')}}).empty?
puts "Trying to run rake bootstrap..."
system %{#{bundle} rake bootstrap}
end
puts "Done!"

6
script/install-git-hooks Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
for hook in script/hooks/* ; do
ln -sf $PWD/$hook .git/hooks/${hook##*/}
done

View File

@ -136,5 +136,16 @@ describe Qt::Qmake do
end
end
end
describe '.make_options' do
let(:cpu_count) { 3 }
subject { Qt::Qmake.make_options }
before do
Qt::Qmake.stubs(:number_of_cpus).returns(cpu_count)
end
it { should == "-j#{cpu_count}" }
end
end