Sha256: c6b83a93d1617abc1e3d6cfb5309dff7b948f530822bde7324f9e6d04dd9a588

Contents?: true

Size: 1012 Bytes

Versions: 2

Compression:

Stored size: 1012 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reap-6.0.1 lib/reap/bin/rubytest.rb
reap-6.0.0 lib/reap/bin/rubytest.rb