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