Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7983

Show
Ignore:
Timestamp:
10/21/07 01:47:30 (1 year ago)
Author:
tobie
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/trunk/CHANGELOG

    r7960 r7983  
    11*SVN* 
     2 
     3* Minor cosmetic changes to the display of unit tests in terminal. [Tobie Langel] 
    24 
    35* Make submitting forms work in Opera < 9.1. Closes #9917, #9463, #8260. [kangax] 
  • spinoffs/prototype/trunk/test/lib/jstest.rb

    r7265 r7983  
    204204    @queue = Queue.new 
    205205 
    206     result = [] 
    207  
    208206    @server = WEBrick::HTTPServer.new(:Port => 4711) # TODO: make port configurable 
    209207    @server.mount_proc("/results") do |req, res| 
    210       @queue.push(req.query['result']) 
     208      @queue.push({ 
     209        :tests => req.query['tests'].to_i, 
     210        :assertions => req.query['assertions'].to_i, 
     211        :failures => req.query['failures'].to_i, 
     212        :errors => req.query['errors'].to_i 
     213      }) 
    211214      res.body = "OK" 
    212215    end 
     
    226229      trap("INT") { @server.shutdown } 
    227230      t = Thread.new { @server.start } 
    228  
     231       
    229232      # run all combinations of browsers and tests 
    230233      @browsers.each do |browser| 
    231234        if browser.supported? 
     235          t0 = Time.now 
     236          results = {:tests => 0, :assertions => 0, :failures => 0, :errors => 0} 
     237          errors = [] 
     238          failures = [] 
    232239          browser.setup 
     240          puts "\nStarted tests in #{browser}" 
    233241          @tests.each do |test| 
    234242            browser.visit("http://localhost:4711#{test}?resultsURL=http://localhost:4711/results&t=" + ("%.6f" % Time.now.to_f)) 
     243  
    235244            result = @queue.pop 
    236             puts "#{test} on #{browser}: #{result}" 
     245            result.each { |k, v| results[k] += v } 
     246            value = "." 
     247             
     248            if result[:failures] > 0 
     249              value = "F" 
     250              failures.push(test) 
     251            end 
     252             
     253            if result[:errors] > 0 
     254              value = "E" 
     255              errors.push(test) 
     256            end 
     257             
     258            print value 
    237259          end 
     260           
     261          puts "\nFinished in #{(Time.now - t0).round.to_s} seconds." 
     262          puts "  Failures: #{failures.join(', ')}" unless failures.empty? 
     263          puts "  Errors:   #{errors.join(', ')}" unless errors.empty? 
     264          puts "#{results[:tests]} tests, #{results[:assertions]} assertions, #{results[:failures]} failures, #{results[:errors]} errors" 
    238265          browser.teardown 
    239266        else 
    240           puts "Skipping #{browser}, not supported on this OS" 
     267          puts "\nSkipping #{browser}, not supported on this OS" 
    241268        end 
    242269      end 
  • spinoffs/prototype/trunk/test/lib/unittest.js

    r7298 r7983  
    178178  //  "SUCCESS" if there was neither 
    179179  getResult: function() { 
    180     var hasFailure = false; 
    181     for(var i=0;i<this.tests.length;i++) { 
    182       if (this.tests[i].errors > 0) { 
    183         return "ERROR"; 
    184       } 
    185       if (this.tests[i].failures > 0) { 
    186         hasFailure = true; 
    187       } 
    188     } 
    189     if (hasFailure) { 
    190       return "FAILURE"
    191     } else { 
    192       return "SUCCESS"
    193     } 
    194   }, 
     180    var results = { 
     181      tests: this.tests.length, 
     182      assertions: 0, 
     183      failures: 0, 
     184      errors: 0 
     185    }; 
     186     
     187    return this.tests.inject(results, function(results, test) { 
     188      results.assertions += test.assertions; 
     189      results.failures   += test.failures; 
     190      results.errors     += test.errors
     191      return results; 
     192    })
     193  }, 
     194   
    195195  postResults: function() { 
    196196    if (this.options.resultsURL) { 
    197197      new Ajax.Request(this.options.resultsURL,  
    198         { method: 'get', parameters: 'result=' + this.getResult(), asynchronous: false }); 
     198        { method: 'get', parameters: this.getResult(), asynchronous: false }); 
    199199    } 
    200200  }, 
     
    225225    } 
    226226  }, 
     227   
    227228  summary: function() { 
    228     var assertions = 0; 
    229     var failures = 0; 
    230     var errors = 0; 
    231     var messages = []; 
    232     for(var i=0;i<this.tests.length;i++) { 
    233       assertions +=   this.tests[i].assertions; 
    234       failures   +=   this.tests[i].failures; 
    235       errors     +=   this.tests[i].errors; 
    236     } 
    237     return ( 
    238       this.tests.length + " tests, " +  
    239       assertions + " assertions, " +  
    240       failures   + " failures, " + 
    241       errors     + " errors"); 
     229    return '#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors' 
     230      .interpolate(this.getResult()); 
    242231  } 
    243232}