[Ruby] Bug in Test::Unit?

Corey Jewett ml at syntheticplayground.com
Sat Aug 4 16:00:47 PDT 2007


I find myself using an (I can only assume) underused feature of  
Test::Unit. Specifically, setting Test::Unit.run = false is supposed  
to keep Test::Unit from running at_exit. However, the logic in the  
following block is wrong. (from the bottom of test/unit.rb)

at_exit do
   unless $! || Test::Unit.run?
     exit Test::Unit::AutoRunner.run
   end
end

According to the docs #run? when false should not trigger the  
AutoRunner. The double negative (unless/false) cause AutoRunner to  
run. Conversely if I set Test::Unit.run = true then I get the desired  
behavior.

I think the proper fix here requires also fixing #run? itself so that  
nil is treated as true since that's the normal behavior. Am I crazy?  
Or should I file this as a bug?

--- unit.rb.orig        2007-08-04 15:42:05.000000000 -0700
+++ unit.rb     2007-08-04 15:56:35.000000000 -0700
@@ -268,13 +268,13 @@

      # Automatically run tests at exit?
      def self.run?
-      @run ||= false
+      @run != false
      end
    end
  end

  at_exit do
-  unless $! || Test::Unit.run?
+  if !$! && Test::Unit.run?
      exit Test::Unit::AutoRunner.run
    end
  end


Corey


More information about the Ruby mailing list