Ron Jeffries <ronjeffries / REMOVEacm.org> writes:

> Looks like Dave's has a cute feature to run any tests mentioned in the
> command line.

The following patch adds tat capability to Nathaniel's. It allows you to
specify test methods on the command line. You can specify either test
names, or regexps (between //'s) that match zero or more test names,
eg

    ruby my_tests.rb test_db_stuff /record/

runs the test 'test_db_stuff', and any test with 'record' in the name.

Cheers


Dave


--- packages/testunit/lib/test/unit.rb.orig	Sun Feb 24 21:21:46 2002
+++ packages/testunit/lib/test/unit.rb	Sun Feb 24 21:32:08 2002
@@ -143,18 +143,30 @@
 require 'test/unit/ui/testrunnermediator'
 
 at_exit {
-	if (!Test::Unit::UI::TestRunnerMediator.run?)
-		suite_name = $0.split('.')
-		suite_name.pop
-		suite_name = suite_name.join('.')
-		suite = Test::Unit::TestSuite.new(suite_name)
-		ObjectSpace.each_object(Class) {
-			| klass |
-			if (Test::Unit::TestCase > klass)
-				suite.add(klass.suite)
-			end
-		}
-		require 'test/unit/ui/console/testrunner'
-		Test::Unit::UI::Console::TestRunner.run(suite)
-	end
+  if (!Test::Unit::UI::TestRunnerMediator.run?)
+    suite_name = $0.split('.')
+    suite_name.pop
+    suite_name = suite_name.join('.')
+    suite = Test::Unit::TestSuite.new(suite_name)
+    test_classes = []
+    ObjectSpace.each_object(Class) do |klass|
+      test_classes << klass if (Test::Unit::TestCase > klass)
+    end
+
+    if ARGV.empty?
+      test_classes.each {|klass| suite.add(klass.suite)}
+    else
+      args = ARGV.map { |arg| (arg =~ %r{^/(.*)/$}) ? Regexp.new($1) : arg}
+      test_classes.each do |klass|
+        methods = klass.public_instance_methods
+        to_run = []
+        args.each do |test|
+          to_run.concat methods.grep(test)
+        end
+        to_run.uniq.each { |method| suite.add(klass.new(method)) }
+      end
+    end
+    require 'test/unit/ui/console/testrunner'
+    Test::Unit::UI::Console::TestRunner.run(suite)
+  end
 }