require 'test/unit' require 'facet/consoleapp' # Run commented tests. # #-- # One wonders if this should be built as a Test::Unit::CommentAutoRunner #++ 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 ) test_code = nil md = RETEST.match( code ) test_code = md[1] if md unless test_code puts "No test found for #{filepath}." return nil end offset = code.split(/\n/).size - test_code.split(/\n/).size - 1 require filepath eval test_code, TOPLEVEL_BINDING, File.basename(filepath), offset end end HELP = <<-EOS rubytest filename [filename ...] EOS