-q to silence some noisy things, fixes #97

This commit is contained in:
John Bintz 2012-01-11 08:44:28 -05:00
parent 81f561282a
commit 1f56031d8b
17 changed files with 167 additions and 33 deletions

View File

@ -18,6 +18,7 @@ Runner::Runner() : QObject()
, usedConsole(false)
, isFinished(false)
, useColors(false)
, quiet(false)
{
page.settings()->enablePersistentStorage();
ticker.setInterval(TIMER_TICK);
@ -122,10 +123,18 @@ void Runner::setSeed(QString s) {
seed = s;
}
void Runner::setQuiet(bool q) {
quiet = q;
}
QString Runner::getSeed() {
return seed;
}
bool Runner::isQuiet() {
return quiet;
}
void Runner::print(const QString &fh, const QString &content) {
if (fh == "stdout") {
std::cout << qPrintable(content);

View File

@ -22,6 +22,7 @@ class Runner: public QObject {
void setColors(bool colors);
void setReportFiles(QStack<QString> &files);
void setSeed(QString s);
void setQuiet(bool q);
void addFile(const QString &spec);
void go();
@ -33,6 +34,7 @@ class Runner: public QObject {
void hasError();
void hasSpecFailure();
bool isQuiet();
QString getSeed();
void print(const QString &fh, const QString &content);
@ -54,6 +56,7 @@ class Runner: public QObject {
bool usedConsole;
bool isFinished;
bool useColors;
bool quiet;
QString seed;

View File

@ -30,17 +30,20 @@
int main(int argc, char** argv)
{
bool showColors = false;
bool isQuiet = false;
QString seed;
QStack<QString> reporterFiles;
int c, index;
while ((c = getopt(argc, argv, "cr:s:")) != -1) {
while ((c = getopt(argc, argv, "cr:s:q")) != -1) {
switch(c) {
case 'c':
showColors = true;
break;
case 'q':
isQuiet = true;
break;
case 'r':
reporterFiles.push(QString(optarg));
break;
@ -61,6 +64,7 @@ int main(int argc, char** argv)
Runner runner;
runner.setColors(showColors);
runner.setQuiet(isQuiet);
runner.setReportFiles(reporterFiles);
runner.setSeed(seed);

View File

@ -0,0 +1,8 @@
Feature: Bin - Quiet Messages
Scenario: Run a test that would cause a lot of messages to be displayed and silence them all
Given I have a test suite
When I run `bin/jasmine-headless-webkit -q -j spec/jasmine/noisy/noisy.yml`
Then the exit status should be 0
And the output should not include "[Skipping File]"
And the output should not include "You should mock"

View File

@ -0,0 +1,4 @@
Then /^the output should not include "([^"]*)"$/ do |string|
@output.should_not include(string)
end

View File

@ -35,6 +35,24 @@ module Jasmine
def root
@root ||= Pathname(File.expand_path('../../..', __FILE__))
end
def warn(message)
output.puts message if show_warnings?
end
def show_warnings=(show)
@show_warnings = show
end
def show_warnings?
@show_warnings = true if @show_warnings.nil?
@show_warnings
end
def output
$stdout
end
end
end
end

View File

@ -1,14 +1,18 @@
module Jasmine::Headless::FileChecker
def excluded_formats
::Jasmine::Headless::EXCLUDED_FORMATS
end
def bad_format?(file)
return if file.nil?
::Jasmine::Headless::EXCLUDED_FORMATS.any? do |format|
excluded_formats.any? do |format|
file[%r{\.#{format}(\.|$)}]
end
end
def alert_bad_format(file)
puts "[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ]
Jasmine::Headless.warn("[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ])
end
def alert_if_bad_format?(file)

View File

@ -17,9 +17,8 @@ module Jasmine
:full_run => true,
:enable_cache => true,
:files => [],
:reporters => [
[ 'Console' ]
]
:reporters => [ [ 'Console' ] ],
:quiet => false
}
DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit')
@ -39,6 +38,7 @@ module Jasmine
srand
@options[:seed] = rand(10000)
read_defaults_files
opts.each { |k, v| @options[k] = v if v }
end
@ -69,6 +69,8 @@ module Jasmine
@options[:full_run] = false
when '--list', '-l'
@options[:do_list] = true
when '--quiet', '-q'
@options[:quiet] = true
when '--seed'
@options[:seed] = arg.to_i
when '--format', '-f'
@ -105,7 +107,8 @@ module Jasmine
[ '--seed', GetoptLong::REQUIRED_ARGUMENT ],
[ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ],
[ '--out', GetoptLong::REQUIRED_ARGUMENT ],
[ '-h', '--help', GetoptLong::NO_ARGUMENT ]
[ '-h', '--help', GetoptLong::NO_ARGUMENT ],
[ '-q', '--quiet', GetoptLong::NO_ARGUMENT ]
)
command_line_args.each { |*args| process_option(*args) }
@ -166,6 +169,7 @@ module Jasmine
[ '--seed', 'Random order seed for spec file ordering' ],
[ '-f, --format <reporter<:filename>>', 'Specify an output reporter and possibly output filename' ],
[ '--out <filename>', 'Specify output filename for last defined reporter' ],
[ '-q, --quiet', "Silence most non-test related warnings" ],
[ '-h, --help', "You're looking at it" ]
]
@ -179,6 +183,7 @@ Options:
Available reporters:
Console Write out spec results to the console in a progress format (default)
Verbose Write out spec results to the console in a verbose format
File Write spec results in jasmine-headless-webkit ReportFile format
Tap Write spec results in TAP format

View File

@ -57,6 +57,7 @@ module Jasmine
command << "-s #{options[:seed]}"
command << '-c' if options[:colors]
command << '-q' if options[:quiet]
options.file_reporters.each do |reporter, identifier, file|
command << "-r #{file}"
@ -69,6 +70,7 @@ module Jasmine
def run
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
Jasmine::Headless.show_warnings = !@options[:quiet]
FilesList.reset!
@_targets = template_writer.write

View File

View File

@ -0,0 +1,8 @@
src_dir: spec/jasmine/noisy
src_files:
- '**/*'
spec_dir: spec/jasmine/noisy
spec_files:
- '**/*'

View File

@ -0,0 +1,2 @@
window.prompt("hello");

View File

@ -1,25 +1,41 @@
require 'spec_helper'
describe Jasmine::Headless::FileChecker do
include FakeFS::SpecHelpers
let(:test_class) do
object = Object.new
object.class.send(:include, Jasmine::Headless::FileChecker)
object
end
context "bad_format?" do
it "should return false wth correct format" do
test_class.bad_format?('foobar.js').should be_false
describe "#bad_format?" do
subject { test_class.bad_format?(file) }
before do
test_class.stubs(:excluded_formats).returns(%w{erb string})
end
it "should return false wth wrong format" do
test_class.bad_format?('foobar.js.erb').should be_true
context 'nil' do
let(:file) { nil }
it { should be_nil }
end
it "should check for the whole extension" do
test_class.bad_format?('foobar.string.js').should be_false
context 'allowed format' do
let(:file) { 'foobar.js' }
it { should be_false }
end
context 'unallowed format' do
let(:file) { 'foobar.erb' }
it { should be_true }
end
context 'check whole extension' do
let(:file) { 'foobar.string.js' }
it { should be_true }
end
end
end

View File

@ -91,6 +91,15 @@ describe Jasmine::Headless::Runner do
it_should_have_basics
it { should include("-r #{file}") }
end
context 'quiet' do
before do
options[:quiet] = true
end
it_should_have_basics
it { should include("-q") }
end
end
describe '#runner_filename' do

View File

@ -1,2 +1,38 @@
require 'spec_helper'
describe Jasmine::Headless do
describe '.warn' do
let(:output) { StringIO.new }
before do
described_class.stubs(:output).returns(output)
end
context 'warnings enabled' do
before do
described_class.stubs(:show_warnings?).returns(true)
end
it 'should work' do
described_class.warn("warning")
output.rewind
output.read.should == "warning\n"
end
end
context 'warnings disabled' do
before do
described_class.stubs(:show_warnings?).returns(false)
end
it 'should work' do
described_class.warn("warning")
output.rewind
output.read.should == ""
end
end
end
end

View File

@ -29,12 +29,15 @@ if window.JHW
puts = (message) ->
JHW.print('stdout', message + "\n")
warn = (message) ->
puts(message) if !JHW.isQuiet()
# handle unloading
window.onbeforeunload = (e) ->
e = e || window.event
JHW.hasError()
puts "The code tried to leave the test page. Check for unhandled form submits and link clicks."
warn "The code tried to leave the test page. Check for unhandled form submits and link clicks."
e.returnValue = 'string' if e
@ -49,17 +52,17 @@ if window.JHW
# dialogs
window.confirm = ->
puts "#{"[confirm]".foreground('red')} You should mock window.confirm. Returning true."
warn "#{"[confirm]".foreground('red')} You should mock window.confirm. Returning true."
true
window.prompt = ->
puts "#{"[prompt]".foreground('red')} You should mock window.prompt. Returning true."
warn "#{"[prompt]".foreground('red')} You should mock window.prompt. Returning true."
true
window.alert = (message) ->
puts "[alert] ".foreground('red') + message
warn "[alert] ".foreground('red') + message
# color support
JHW._setColors = (useColors) -> Intense.useColors = useColors

View File

@ -1,5 +1,6 @@
(function() {
var puts;
var puts, warn;
if (window.JHW) {
window.console = {
log: function(data) {
@ -39,13 +40,14 @@
puts = function(message) {
return JHW.print('stdout', message + "\n");
};
warn = function(message) {
if (!JHW.isQuiet()) return puts(message);
};
window.onbeforeunload = function(e) {
e = e || window.event;
JHW.hasError();
puts("The code tried to leave the test page. Check for unhandled form submits and link clicks.");
if (e) {
e.returnValue = 'string';
}
warn("The code tried to leave the test page. Check for unhandled form submits and link clicks.");
if (e) e.returnValue = 'string';
return 'string';
};
JHW._hasErrors = false;
@ -55,15 +57,15 @@
return false;
};
window.confirm = function() {
puts("" + ("[confirm]".foreground('red')) + " You should mock window.confirm. Returning true.");
warn("" + ("[confirm]".foreground('red')) + " You should mock window.confirm. Returning true.");
return true;
};
window.prompt = function() {
puts("" + ("[prompt]".foreground('red')) + " You should mock window.prompt. Returning true.");
warn("" + ("[prompt]".foreground('red')) + " You should mock window.prompt. Returning true.");
return true;
};
window.alert = function(message) {
return puts("[alert] ".foreground('red') + message);
return warn("[alert] ".foreground('red') + message);
};
JHW._setColors = function(useColors) {
return Intense.useColors = useColors;
@ -75,14 +77,15 @@
_ref = jasmine.getEnv().reporter.subReporters_;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
reporter = _ref[_i];
if (reporter.consoleLogUsed != null) {
reporter.consoleLogUsed(msg);
}
if (reporter.consoleLogUsed != null) reporter.consoleLogUsed(msg);
}
JHW._usedConsole = true;
return puts(msg);
};
}
window.CoffeeScriptToFilename = {};
window.CSTF = window.CoffeeScriptToFilename;
}).call(this);