From ba96fa77bfa87cafa37bffb70ebcb86829107c96 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Sun, 21 Oct 2007 01:47:30 +0000 Subject: [PATCH] prototype: Minor cosmetic changes to the display of unit tests in terminal. --- CHANGELOG | 2 ++ test/lib/jstest.rb | 39 ++++++++++++++++++++++++++++++------ test/lib/unittest.js | 47 +++++++++++++++++--------------------------- 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5867df3..76b8216 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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] diff --git a/test/lib/jstest.rb b/test/lib/jstest.rb index 2f686ed..65e4189 100644 --- a/test/lib/jstest.rb +++ b/test/lib/jstest.rb @@ -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 diff --git a/test/lib/unittest.js b/test/lib/unittest.js index da849e1..993d512 100644 --- a/test/lib/unittest.js +++ b/test/lib/unittest.js @@ -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 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