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

View File

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

View File

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

View File

@ -1,14 +1,18 @@
module Jasmine::Headless::FileChecker module Jasmine::Headless::FileChecker
def excluded_formats
::Jasmine::Headless::EXCLUDED_FORMATS
end
def bad_format?(file) def bad_format?(file)
return if file.nil? return if file.nil?
::Jasmine::Headless::EXCLUDED_FORMATS.any? do |format| excluded_formats.any? do |format|
file[%r{\.#{format}(\.|$)}] file[%r{\.#{format}(\.|$)}]
end end
end end
def alert_bad_format(file) 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 end
def alert_if_bad_format?(file) def alert_if_bad_format?(file)

View File

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

View File

@ -57,6 +57,7 @@ module Jasmine
command << "-s #{options[:seed]}" command << "-s #{options[:seed]}"
command << '-c' if options[:colors] command << '-c' if options[:colors]
command << '-q' if options[:quiet]
options.file_reporters.each do |reporter, identifier, file| options.file_reporters.each do |reporter, identifier, file|
command << "-r #{file}" command << "-r #{file}"
@ -69,6 +70,7 @@ module Jasmine
def run def run
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache] Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
Jasmine::Headless.show_warnings = !@options[:quiet]
FilesList.reset! FilesList.reset!
@_targets = template_writer.write @_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' require 'spec_helper'
describe Jasmine::Headless::FileChecker do describe Jasmine::Headless::FileChecker do
include FakeFS::SpecHelpers
let(:test_class) do let(:test_class) do
object = Object.new object = Object.new
object.class.send(:include, Jasmine::Headless::FileChecker) object.class.send(:include, Jasmine::Headless::FileChecker)
object object
end end
context "bad_format?" do describe "#bad_format?" do
it "should return false wth correct format" do subject { test_class.bad_format?(file) }
test_class.bad_format?('foobar.js').should be_false
before do
test_class.stubs(:excluded_formats).returns(%w{erb string})
end end
it "should return false wth wrong format" do context 'nil' do
test_class.bad_format?('foobar.js.erb').should be_true let(:file) { nil }
it { should be_nil }
end end
it "should check for the whole extension" do context 'allowed format' do
test_class.bad_format?('foobar.string.js').should be_false 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 end
end end

View File

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

View File

@ -1,2 +1,38 @@
require 'spec_helper' 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) -> puts = (message) ->
JHW.print('stdout', message + "\n") JHW.print('stdout', message + "\n")
warn = (message) ->
puts(message) if !JHW.isQuiet()
# handle unloading # handle unloading
window.onbeforeunload = (e) -> window.onbeforeunload = (e) ->
e = e || window.event e = e || window.event
JHW.hasError() 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 e.returnValue = 'string' if e
@ -49,17 +52,17 @@ if window.JHW
# dialogs # dialogs
window.confirm = -> 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 true
window.prompt = -> 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 true
window.alert = (message) -> window.alert = (message) ->
puts "[alert] ".foreground('red') + message warn "[alert] ".foreground('red') + message
# color support # color support
JHW._setColors = (useColors) -> Intense.useColors = useColors JHW._setColors = (useColors) -> Intense.useColors = useColors

View File

@ -1,5 +1,6 @@
(function() { (function() {
var puts; var puts, warn;
if (window.JHW) { if (window.JHW) {
window.console = { window.console = {
log: function(data) { log: function(data) {
@ -39,13 +40,14 @@
puts = function(message) { puts = function(message) {
return JHW.print('stdout', message + "\n"); return JHW.print('stdout', message + "\n");
}; };
warn = function(message) {
if (!JHW.isQuiet()) return puts(message);
};
window.onbeforeunload = function(e) { window.onbeforeunload = function(e) {
e = e || window.event; e = e || window.event;
JHW.hasError(); 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.");
if (e) { if (e) e.returnValue = 'string';
e.returnValue = 'string';
}
return 'string'; return 'string';
}; };
JHW._hasErrors = false; JHW._hasErrors = false;
@ -55,15 +57,15 @@
return false; return false;
}; };
window.confirm = function() { 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; return true;
}; };
window.prompt = function() { 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; return true;
}; };
window.alert = function(message) { window.alert = function(message) {
return puts("[alert] ".foreground('red') + message); return warn("[alert] ".foreground('red') + message);
}; };
JHW._setColors = function(useColors) { JHW._setColors = function(useColors) {
return Intense.useColors = useColors; return Intense.useColors = useColors;
@ -75,14 +77,15 @@
_ref = jasmine.getEnv().reporter.subReporters_; _ref = jasmine.getEnv().reporter.subReporters_;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
reporter = _ref[_i]; reporter = _ref[_i];
if (reporter.consoleLogUsed != null) { if (reporter.consoleLogUsed != null) reporter.consoleLogUsed(msg);
reporter.consoleLogUsed(msg);
}
} }
JHW._usedConsole = true; JHW._usedConsole = true;
return puts(msg); return puts(msg);
}; };
} }
window.CoffeeScriptToFilename = {}; window.CoffeeScriptToFilename = {};
window.CSTF = window.CoffeeScriptToFilename; window.CSTF = window.CoffeeScriptToFilename;
}).call(this); }).call(this);