From: jonathan gold Date: 2006-07-07T06:50:37+09:00 Subject: [PATCH] --fqname option to test/unit/autorunner.rb --------------030606020306040805000508 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hello, I'd like to contribute a patch to test/unit/autorunner.rb that allows a new option '--fqname', which would be the logical AND of what is today '--testcase' with '--name'. I have tests in files with many testcases, some of which use subclassing or an include to repeatedly run different variations of the same test. Right now, if the method "test_foo" is defined/included in both FooTestCase and BarTestCase, there is no way for me to tell autorunner to run just the "test_foo" method in the FooTestCase class. If I say '--testcase FooTestCase', I run all methods in FooTestCase. If I say '--name test_foo' then I run test_foo in both FooTestCase and in BarTestCase. The proposed patch allows me to say '--fqname FooTestCase#test_foo' and have only that single test case be run. I'm new to the ruby community, so apologize if I'm overlooking the correcct way to submit code like this. I didn't see any guidelines for applying to become a committer or someone with the rights to request write access to the CVS repository, and, judging from the email threads on this list, the thing to do is put 'PATCH' in the subject line and then provide the diff (attached). Hopefully this is correct, but please let me know what I can do to help make things easier. I'm looking forward to hearing from you. jon --------------030606020306040805000508 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="autorunner.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="autorunner.diff" --- lib/test/unit/autorunner.rb.orig 2006-07-06 14:52:11.000000000 -0700 +++ lib/test/unit/autorunner.rb 2006-07-06 14:51:10.000000000 -0700 @@ -153,6 +153,26 @@ module Test end end + o.on('-q', '--fqname=TESTCASE#NAME', String, + "Runs test NAME in TestCase TESTCASE", + "This switch is the logical AND of --testcase and --name.", + "It behaves similarly to --testcase and --name, in that the", + "argument can be a literal or a '/' enclosed regex. In the", + "case of the former, it will be checked for an exact match.", + "In the case of the latter, the regex will be matched", + "against the string created by joining a TestCase's classname", + "and the name of a test method with the '#' character.") do |n| + n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) + case n + when Regexp + @filters << proc{|t| + n =~ ("#{t.class.to_s}\##{t.method_name}") ? true : nil} + else + @filters << proc{|t| + n == ("#{t.class.to_s}\##{t.method_name}") ? true : nil} + end + end + o.on('-v', '--verbose=[LEVEL]', OUTPUT_LEVELS, "Set the output level (default is verbose).", "(" + keyword_display(OUTPUT_LEVELS) + ")") do |l| --------------030606020306040805000508--