Using ruby to test IronRuby

This is not pretty, but it’s a start. It started as a nobel goal of publishing an easy to read output of all the ruby tests here, but I’m not there yet, and really want to try to get a post up every weekday at least, so here’s what I’ve got so far.

I’m no ruby expert yet, but here is the script I wrote to run all the tests. It basically recursively searches all the paths below the “root” path for files named test_*, and then changes to that folder, and runs rbx filename, and appends the output to a text file. I’ve also thrown the text file up on the server here, although it desperately needs some formatting.

Code (ruby)
  1.  
  2. start_folder = ‘C:projectsIronRuby-Pre-Alpha1TestsRuby’
  3.  
  4. class TestRunner
  5.  
  6.         def initialize
  7.                 output_file_name = ‘c:IronRubyTests.log
  8.                 @output_file = File.open(output_file_name, ‘w’)
  9.         end
  10.  
  11.         def run_tests(folder, file)
  12.           putstest ‘ + file
  13.           @output_file << ‘Running tests in ‘ + file
  14.           Dir.chdir(folder)
  15.           @output_file << `rbx #{file}`
  16.         end
  17.  
  18.         def scan_folder(folder)
  19.           Dir.chdir(folder)
  20.           Dir.foreach(folder) do |f|
  21.                 if f != "." and f != ".."
  22.                   fullpath = folder + ” + f
  23.               run_tests(folder, f) if f =~ /test_*/
  24.               scan_folder(fullpath) if File.directory?(fullpath)
  25.             end
  26.           end
  27.         end
  28. end
  29.  
  30. tester = TestRunner.new
  31. tester.scan_folder(start_folder)

Please feel free to comment, I’m no ruby expert by any means yet, just hope to get there, and see IronRuby as a means to sneak it through IT, and hence learn it far more in depth. More on those devious little thoughts later :) Although most of the tests in IronRuby are still erroring, or I’m not running them right, I’m still very optimistic.

Edit, thanks Dan!

Dan, who will quickly get sick of me asking him ruby questions, commented on Dir.glob. When you use the right tools, it’s amazing what you can get done.

Code (ruby)
  1.  
  2. start_folder = ‘C:/projects/IronRuby-Pre-Alpha1/Tests/Ruby’
  3. @output_file = File.open(‘c:\tests.log‘, ‘w’)
  4.  
  5. def run_tests(file)
  6.   Dir.chdir(File.dirname(file))
  7.   puts ‘rbx #{File.basename(file)}’
  8.   @output_file << ‘Running tests in ‘ + file + "\r\n" + `rbx #{File.basename(file)}` + "\r\n"
  9. end
  10.        
  11. Dir.glob("#{start_folder}/**/test_*.rb").each do |f|
  12.         run_tests(f)
  13. end
  14.  

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Using ruby to test IronRuby”

  1. […] it’s obvious the team has been busy. If you want to compare these to the last run the results are here, as well as the tiny script to run them […]

Leave a Reply