Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  def run
    rd, wr = IO.pipe
    rd.fcntl(Fcntl::F_SETFD, 1)
    ENV['TM_ERROR_FD'] = wr.to_i.to_s
    args = add_test_path( *[ ruby,
                             '-rcatch_exception', '-rstdin_dialog',
                             Array(@args), @path, ARGV.to_a ].flatten )
    stdin, stdout, stderr = Open3.popen3(*args)
    Thread.new { stdin.write @content; stdin.close } unless ENV.has_key? 'TM_FILEPATH'
    wr.close

    [ stdout, stderr, rd ]
  end

  attr_reader :display_name, :path
  
  private
  
  def add_test_path(*args)
    if test_script?
      path_ary = @path.split("/")
      if index = path_ary.rindex("test")
        test_path = File.join(*path_ary[0..-2])
        lib_path  = File.join( *( path_ary[0..-2] +
                                  [".."] * (path_ary.length - index - 1) ) +
                                  ["lib"] )
        if File.exist? lib_path
          args.insert(1, "-I#{lib_path}:#{test_path}")
        end
      end
    end
    args
  end