Permalink
Browse files

+ Split minitest-excludes out of minitest

[git-p4: depot-paths = "//src/minitest-excludes/dev/": change = 6830]
  • Loading branch information...
0 parents commit 3a081407885cebf13546341affa9a9d904b39037 @zenspider zenspider committed Dec 21, 2011
Showing with 286 additions and 0 deletions.
  1. +26 −0 .autotest
  2. +6 −0 History.txt
  3. +8 −0 Manifest.txt
  4. +49 −0 README.txt
  5. +15 −0 Rakefile
  6. +72 −0 lib/minitest/excludes.rb
  7. +43 −0 test/metametameta.rb
  8. +67 −0 test/test_minitest_excludes.rb
@@ -0,0 +1,26 @@
+# -*- ruby -*-
+
+require "autotest/restart"
+
+Autotest.add_hook :initialize do |at|
+ at.testlib = "minitest/autorun"
+ at.add_exception "tmp"
+
+# at.extra_files << "../some/external/dependency.rb"
+#
+# at.libs << ":../some/external"
+#
+# at.add_exception "vendor"
+#
+# at.add_mapping(/dependency.rb/) do |f, _|
+# at.files_matching(/test_.*rb$/)
+# end
+#
+# %w(TestA TestB).each do |klass|
+# at.extra_class_map[klass] = "test/test_misc.rb"
+# end
+end
+
+# Autotest.add_hook :run_command do |at|
+# system "rake build"
+# end
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2011-12-20
+
+* 1 major enhancement
+
+ * Birthday!
+
@@ -0,0 +1,8 @@
+.autotest
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+bin/minitest-excludes
+lib/minitest-excludes.rb
+test/test_minitest-excludes.rb
@@ -0,0 +1,49 @@
+= minitest-excludes
+
+home :: https://github.com/seattlerb/minitest-excludes
+rdoc :: http://docs.seattlerb.org/minitest-excludes
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* sudo gem install minitest-excludes
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) Ryan Davis, seattle.rb
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
+# -*- ruby -*-
+
+require "rubygems"
+require "hoe"
+
+Hoe.plugin :isolate
+Hoe.plugin :seattlerb
+
+Hoe.spec "minitest-excludes" do
+ developer "Ryan Davis", "ryand-ruby@zenspider.com"
+
+ dependency "minitest", "~> 2.8"
+end
+
+# vim: syntax=ruby
@@ -0,0 +1,72 @@
+require 'minitest/unit'
+
+##
+# minitest/excludes.rb extends MiniTest::Unit::TestCase to provide a
+# clean API for excluding certain tests you don't want to run under
+# certain conditions.
+#
+# For example, in test/test_xyz.rb you have:
+#
+# class TestXYZ < MiniTest::Unit::TestCase
+# def test_good
+# # test that passes
+# end
+#
+# def test_bad
+# # test that fails only on jruby
+# end
+# end
+#
+# For jruby runs, you can add test/excludes/TestXYZ.rb with:
+#
+# exclude :test_bad, "Uses ObjectSpace" if jruby?
+#
+# The file is instance_eval'd on TestXYZ so you can call the exclude
+# class method directly. Since it is ruby you can provide any sort
+# of conditions you want to figure out if your tests should be
+# excluded.
+#
+# TestCase.exclude causes test methods to call skip with the reason
+# you provide. If you run your tests in verbose mode, you'll see a
+# full report of the tests you've excluded.
+#
+# If you want to change where the exclude files are located, you can
+# set the EXCLUDE_DIR environment variable.
+
+class MiniTest::Unit::TestCase
+ EXCLUDE_DIR = ENV['EXCLUDE_DIR'] || "test/excludes"
+
+ ##
+ # Exclude a test from a testcase. This is intended to be used by
+ # exclusion files.
+
+ def self.exclude name, reason
+ return warn "Method #{self}##{name} is not defined" unless
+ method_defined? name
+
+ remove_method name
+ end
+
+ ##
+ # Loads the exclusion file for the class, if any.
+
+ def self.load_excludes
+ @__load_excludes__ ||=
+ begin
+ if name and not name.empty? then
+ file = File.join EXCLUDE_DIR, "#{name.gsub(/::/, '/')}.rb"
+ instance_eval File.read file if File.exist? file
+ end
+ true
+ end
+ end
+
+ class << self
+ alias :old_test_methods :test_methods # :nodoc:
+
+ def test_methods # :nodoc:
+ load_excludes
+ old_test_methods
+ end
+ end
+end
@@ -0,0 +1,43 @@
+require 'tempfile'
+require 'stringio'
+require 'minitest/autorun'
+
+class MetaMetaMetaTestCase < MiniTest::Unit::TestCase
+ def assert_report expected = nil
+ expected ||= <<-EOM.gsub(/^ {6}/, '')
+ Run options: --seed 42
+
+ # Running tests:
+
+ .
+
+ Finished tests in 0.00
+
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
+ EOM
+
+ output = @output.string.dup
+ output.sub!(/Finished tests in .*/, "Finished tests in 0.00")
+ output.sub!(/Loaded suite .*/, 'Loaded suite blah')
+ output.gsub!(/[\w\/]+\/test\/[^:]+:\d+/, 'FILE:LINE')
+ output.gsub!(/(?:.\/)?test\/[^:]+:\d+/, 'FILE:LINE')
+ output.gsub!(/\[[^\]]+\]/, '[FILE:LINE]')
+ assert_equal(expected, output)
+ end
+
+ def setup
+ super
+ srand 42
+ MiniTest::Unit::TestCase.reset
+ @tu = MiniTest::Unit.new
+ @output = StringIO.new("")
+ MiniTest::Unit.runner = nil # protect the outer runner from the inner tests
+ MiniTest::Unit.output = @output
+ end
+
+ def teardown
+ super
+ MiniTest::Unit.output = $stdout
+ Object.send :remove_const, :ATestCase if defined? ATestCase
+ end
+end
@@ -0,0 +1,67 @@
+require 'test/metametameta'
+require 'minitest/excludes'
+
+class TestMiniTestExcludes < MetaMetaMetaTestCase
+ def test_cls_excludes
+ srand 42
+ old_exclude_base = MiniTest::Unit::TestCase::EXCLUDE_DIR
+
+ @assertion_count = 0
+
+ Dir.mktmpdir do |path|
+ MiniTest::Unit::TestCase::EXCLUDE_DIR.replace(path)
+ Dir.mkdir File.join path, "ATestCase"
+
+ s = 'exclude :test_test2, "because it is borked"'
+
+ File.open File.join(path, "ATestCase.rb"), "w" do |f|
+ f.puts s
+ end
+
+ File.open File.join(path, "ATestCase/Nested.rb"), "w" do |f|
+ f.puts s
+ end
+
+ tc1 = tc2 = nil
+
+ tc1 = Class.new(MiniTest::Unit::TestCase) do
+ def test_test1; assert true end
+ def test_test2; assert false end # oh noes!
+ def test_test3; assert true end
+
+ tc2 = Class.new(MiniTest::Unit::TestCase) do
+ def test_test1; assert true end
+ def test_test2; assert false end # oh noes!
+ def test_test3; assert true end
+ end
+ end
+
+ Object.const_set(:ATestCase, tc1)
+ ATestCase.const_set(:Nested, tc2)
+
+ assert_equal %w(test_test3 test_test1), ATestCase.test_methods
+ assert_equal %w(test_test1 test_test3), ATestCase::Nested.test_methods
+
+ @tu.run %w[--seed 42 --verbose]
+
+ expected = <<-EOM.gsub(/^ {8}/, '')
+ Run options: --seed 42 --verbose
+
+ # Running tests:
+
+ ATestCase#test_test1 = 0.00 s = .
+ ATestCase#test_test3 = 0.00 s = .
+ ATestCase::Nested#test_test1 = 0.00 s = .
+ ATestCase::Nested#test_test3 = 0.00 s = .
+
+
+ Finished tests in 0.00
+
+ 4 tests, 4 assertions, 0 failures, 0 errors, 0 skips
+ EOM
+ assert_report expected
+ end
+ ensure
+ MiniTest::Unit::TestCase::EXCLUDE_DIR.replace(old_exclude_base)
+ end
+end

0 comments on commit 3a08140

Please sign in to comment.