require 'test/unit' require 'facet/consoleapp' class RubyCommentTester < Console::Application RETEST = /^=begin\s+test.*?\n(.*)\n=end/mi # option to display help def __verbose ; $VERBOSE = true ; end alias_method :_v, :__verbose # option to display help def __help puts HELP exit 0 end alias_method :_h, :__help def main( *filepaths ) filepaths.each { |fp| run_comment_test( fp ) } end private def run_comment_test( filepath ) code = File.read( filepath ) md = RETEST.match( code ) test_code = md[1] unless test_code puts "No test found for #{filepath}." return nil end require filepath eval test_code, TOPLEVEL_BINDING end end HELP = <<-EOS rubytest filename [filename ...] EOS