prototype: Minor cosmetic changes to the display of unit tests in terminal.

This commit is contained in:
Tobie Langel 2007-10-21 01:47:30 +00:00
parent 37bab18999
commit ba96fa77bf
3 changed files with 53 additions and 35 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Minor cosmetic changes to the display of unit tests in terminal. [Tobie Langel]
* Make submitting forms work in Opera < 9.1. Closes #9917, #9463, #8260. [kangax]
* Fix template evaluation with empty replacements. Closes #9692. [Ryan McGeary]

View File

@ -203,11 +203,14 @@ class JavaScriptTestTask < ::Rake::TaskLib
@queue = Queue.new
result = []
@server = WEBrick::HTTPServer.new(:Port => 4711) # TODO: make port configurable
@server.mount_proc("/results") do |req, res|
@queue.push(req.query['result'])
@queue.push({
:tests => req.query['tests'].to_i,
:assertions => req.query['assertions'].to_i,
:failures => req.query['failures'].to_i,
:errors => req.query['errors'].to_i
})
res.body = "OK"
end
@server.mount_proc("/content-type") do |req, res|
@ -225,19 +228,43 @@ class JavaScriptTestTask < ::Rake::TaskLib
task @name do
trap("INT") { @server.shutdown }
t = Thread.new { @server.start }
# run all combinations of browsers and tests
@browsers.each do |browser|
if browser.supported?
t0 = Time.now
results = {:tests => 0, :assertions => 0, :failures => 0, :errors => 0}
errors = []
failures = []
browser.setup
puts "\nStarted tests in #{browser}"
@tests.each do |test|
browser.visit("http://localhost:4711#{test}?resultsURL=http://localhost:4711/results&t=" + ("%.6f" % Time.now.to_f))
result = @queue.pop
puts "#{test} on #{browser}: #{result}"
result.each { |k, v| results[k] += v }
value = "."
if result[:failures] > 0
value = "F"
failures.push(test)
end
if result[:errors] > 0
value = "E"
errors.push(test)
end
print value
end
puts "\nFinished in #{(Time.now - t0).round.to_s} seconds."
puts " Failures: #{failures.join(', ')}" unless failures.empty?
puts " Errors: #{errors.join(', ')}" unless errors.empty?
puts "#{results[:tests]} tests, #{results[:assertions]} assertions, #{results[:failures]} failures, #{results[:errors]} errors"
browser.teardown
else
puts "Skipping #{browser}, not supported on this OS"
puts "\nSkipping #{browser}, not supported on this OS"
end
end

View File

@ -177,25 +177,25 @@ Test.Unit.Runner.prototype = {
// "FAILURE" if there was a failure, or
// "SUCCESS" if there was neither
getResult: function() {
var hasFailure = false;
for(var i=0;i<this.tests.length;i++) {
if (this.tests[i].errors > 0) {
return "ERROR";
}
if (this.tests[i].failures > 0) {
hasFailure = true;
}
}
if (hasFailure) {
return "FAILURE";
} else {
return "SUCCESS";
}
var results = {
tests: this.tests.length,
assertions: 0,
failures: 0,
errors: 0
};
return this.tests.inject(results, function(results, test) {
results.assertions += test.assertions;
results.failures += test.failures;
results.errors += test.errors;
return results;
});
},
postResults: function() {
if (this.options.resultsURL) {
new Ajax.Request(this.options.resultsURL,
{ method: 'get', parameters: 'result=' + this.getResult(), asynchronous: false });
{ method: 'get', parameters: this.getResult(), asynchronous: false });
}
},
runTests: function() {
@ -224,21 +224,10 @@ Test.Unit.Runner.prototype = {
this.runTests();
}
},
summary: function() {
var assertions = 0;
var failures = 0;
var errors = 0;
var messages = [];
for(var i=0;i<this.tests.length;i++) {
assertions += this.tests[i].assertions;
failures += this.tests[i].failures;
errors += this.tests[i].errors;
}
return (
this.tests.length + " tests, " +
assertions + " assertions, " +
failures + " failures, " +
errors + " errors");
return '#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors'
.interpolate(this.getResult());
}
}