From: Daniel Berger Date: 2006-07-14T04:26:51+09:00 Subject: Re: [PATCH] --fqname option to test/unit/autorunner.rb --------------080905040209010307040007 Content-Type: text/plain; format=flowed; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sam Roberts wrote: >=20 > One question, could the syntax of --name be extended, so if there is a = # > or a :: in it is referring to a specific test name in a specific test > suite? I think it would be useful to just have a single option, a bit > like rdoc, if it is specific enough it will run one test, if not it = will > run multiple. Just a thought. >=20 > Thanks, > Sam Hm, good idea, so I've attached a patch that does that. :) Note that it only works on strings passed to -n, not regular = expressions. Anyway, given the following test file: # ts_all.rb require 'test/unit' class Foo def stuff "foo" end end class Bar def stuff "bar" end end class TC_Foo < Test::Unit::TestCase def setup @foo =3D Foo.new end def test_stuff assert_equal("foo", @foo.stuff) end def teardown @foo =3D nil end end class TC_Bar < Test::Unit::TestCase def setup @bar =3D Bar.new end def test_stuff assert_equal("bar", @bar.stuff) assert_equal(1,1) end def teardown @bar =3D nil end end You get these results: # Runs all tests that match 'test_stuff' >ruby tstest.rb -n test_stuff Loaded suite tstest Started .. Finished in 0.002937 seconds. 2 tests, 3 assertions, 0 failures, 0 errors # Only runs test_stuff from TC_Bar >ruby tstest.rb -n TC_Bar#test_stuff Loaded suite tstest Started . Finished in 0.002202 seconds. 1 tests, 2 assertions, 0 failures, 0 errors # Only runs test_stuff from TC_Foo >ruby tstest.rb -n TC_Foo#test_stuff Loaded suite tstest Started . Finished in 0.002114 seconds. 1 tests, 1 assertions, 0 failures, 0 errors Enjoy! Dan This communication is the property of Qwest and may contain confidential = or privileged information. Unauthorized use of this communication is = strictly=20 prohibited and may be unlawful. If you have received this communication = in error, please immediately notify the sender by reply e-mail and = destroy=20 all copies of the communication and any attachments. --------------080905040209010307040007 Content-Type: text/x-patch; name="autorunner.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="autorunner.diff" --- autorunner.orig Thu Jul 13 12:50:03 2006 +++ autorunner.rb Thu Jul 13 13:14:38 2006 @@ -133,11 +133,23 @@ "Runs tests matching NAME.", "(patterns may be used).") do |n| n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) + case n when Regexp - @filters << proc{|t| n =~ t.method_name ? true : nil} + @filters << proc{ |t| + n =~ t.method_name ? true : nil + } else - @filters << proc{|t| n == t.method_name ? true : nil} + if n =~ /#/ + klass, n = n.split('#') + end + @filters << proc{ |t| + if klass + klass == t.class.to_s && n == t.method_name ? true : nil + else + n == t.method_name ? true : nil + end + } end end --------------080905040209010307040007--