From: Jeremy Hinegardner Date: 2007-02-16T13:50:18+09:00 Subject: Re: Best way to skip tests --gBBFr7Ir9EOA20Yy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Feb 16, 2007 at 04:25:13AM +0900, Daniel Berger wrote: > > If there isn't anything like this currently, would patches to add this > be accepted? I'd be happy to work on it. > Well kept thinking about this today and came up with a Module approach, still not exactly what you are looking for, but might be useful in the interum. % ruby -v platform-filter-test.rb ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-linux] Loaded suite platform-filter-test Started .... Finished in 0.001042 seconds. 4 tests, 4 assertions, 0 failures, 0 errors % ruby -v platform-filter-test.rb ruby 1.8.5 (2006-12-25 patchlevel 12) [x86_64-openbsd4.0] Loaded suite platform-filter-test Started ..Skipping TestCase RunOnlyOnLinuxOrDarwinTest .Skipping TestCase RunOnlyOnLinuxTest . Finished in 0.001433 seconds. 4 tests, 4 assertions, 0 failures, 0 errors % ruby -v platform-filter-test.rb ruby 1.8.5 (2006-08-25) [i686-darwin8.8.1] Loaded suite platform-filter-test Started ..Skipping TestCase DoNotRunOnDarwinTest .Skipping TestCase RunOnlyOnLinuxTest . Finished in 0.000834 seconds. 4 tests, 4 assertions, 0 failures, 0 errors Some modules and a little meta programming can be fun :-) enjoy, -jeremy -- ======================================================================== Jeremy Hinegardner jeremy@hinegardner.org --gBBFr7Ir9EOA20Yy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="platform-filter-test.rb" require 'test/unit' module Test module Unit class SkipTest < TestCase attr_accessor :in_place_of def self.skip_suite(in_place_of) s = TestSuite.new(name) t = new(:skip_test) t.in_place_of = in_place_of s << t end def skip_test $stderr.puts("Skipping TestCase #{in_place_of}") assert(true) end def test_nothing assert(true) end end module DoNotRunOnPlatform def self.included(mod) mod.extend(self) end def do_not_run_on(*p) @not_on_platforms = Array.new @not_on_platforms << p @not_on_platforms.flatten! end def suite if not @not_on_platforms.nil? then @not_on_platforms.each do |platform| if RUBY_PLATFORM.match(platform) then return SkipTest.skip_suite(self.name) end end end super end end module OnlyRunOnPlatform def self.included(mod) mod.extend(self) end def only_run_on(*p) @only_on_platforms = Array.new @only_on_platforms << p @only_on_platforms.flatten! end def suite if not @only_on_platforms.nil? then @only_on_platforms.each do |platform| if RUBY_PLATFORM.match(platform) then return super end end end return SkipTest.skip_suite(self.name) end end end end class RunOnlyOnLinuxTest < Test::Unit::TestCase include Test::Unit::OnlyRunOnPlatform only_run_on "linux" def test_linux assert_match(/linux/,RUBY_PLATFORM, "How could I fail. I should have only run on linux!!!") end end class RunOnlyOnLinuxOrDarwinTest < Test::Unit::TestCase include Test::Unit::OnlyRunOnPlatform only_run_on "linux", "darwin" def test_foo assert_match(/(linux|darwin)/,RUBY_PLATFORM, "Hmm... I should only be on linux or mac osx") end end class DoNotRunOnDarwinTest < Test::Unit::TestCase include Test::Unit::DoNotRunOnPlatform do_not_run_on "darwin" def test_darwin assert_no_match(/darwin/,RUBY_PLATFORM, "How could I fail. I should have been skipped. I'm on MacOSX!!!") end end --gBBFr7Ir9EOA20Yy--