Sha256: 421cb537cf13df2a5e80b0d8cb4dfed398520b5250c987b4b6866f47a72d77dc

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

require 'drb'
require 'test/unit/collector'
require 'test/unit/collector/objectspace'
require 'test/unit/ui/testrunnermediator'

class Test::Unit::UI::ForkedTestRunner

  def initialize(suite) #, output_level=NORMAL, io=STDOUT)
    if (suite.respond_to?(:suite))
      @suite = suite.suite
    else
      @suite = suite
    end
    #@output_level = output_level
    #@io = io
    #@already_outputted = false
    #@faults = []
  end

  def start

    serialized_tests = Marshal.dump(@test)

    src = %{
      $output = STDOUT.dup
      STDOUT.reopen( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null" )

      tests = Marshal.load <<HERE_TESTS_HERE
#{serialized_tests}
HERE_TESTS_HERE

      runner = TestRunnerMediator.new( tests )

      result = runner.run_suite

      output << Marshal.dump(result)

      STDOUT.reopen($output)
      $output.close

      exit 0
    }

    result = IO.popen("ruby","w+") do |ruby|
      ruby.puts src
      ruby.close_write
      ruby.read
    end

    p testfile if $VERBOSE

    return Marshal.load(result)

  end

  private
  def load_comment_tests( filepath )
    rbfile = File.read( filepath )
    rblines = rbfile.split("\n")

    tests = []
    intest = nil
    comment = nil
    hcomment = nil

    rblines.each_with_index do |l,i|
      if /^(\ *#\ *)?=\ *begin testing/ =~ l
        intest = true
        comment = true unless $1
        next
      elsif intest and /^(\ *#\ *)?=\ *end/ =~ l
        intest = false
        comment = false
        next
      end
      hcomment = true if /^\ *#/ =~ l

      if intest and (comment or hcomment)
        l.pull if hcomment
        tests << l
      end
    end

    tests = tests.join("\n")
    tests.gsub!( %r{^([ ]*)testcase[ ]+(\w+)} ) { "#{$1}class TC_#{$2} < Test::Unit::TestCase" }
    tests.gsub!( %r{^([ ]*)test[ ]+(\w+)} ) { |md| "#{$1}def test_#{$2}" }

    tests
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reap-6.0.1 forge/unit_runner/forkedrunner.rb
reap-6.0.2 forge/unit_runner/forkedrunner.rb