Manual Test::Unit and popen's require space

T

Trans

Hi, I'm trying to manully run unit test using Test::Unit because I need
to isolate certain requires from others in the
course of the tests. Certain files I'm testing can potentially cause
conflits with others, so I need to run them in isolation. But I still
want to tally the tests/assertions/errors, etc. So I'm wondering if I'm
doing this right. Specifically, is popen("-", "w+") giving me a whole
seperate "require space" to utilize?

Here's my code so far:

def fork_test( testfile )
result = nil
IO.popen("-","w+") do |pipe|
result = pipe.instance_eval do
require 'test/unit'
require 'test/unit/collector'
require 'test/unit/collector/objectspace'
require 'test/unit/ui/testrunnermediator'
load( testfile )
tests = Test::Unit::Collector::ObjectSpace.new.collect
runner = Test::Unit::UI::TestRunnerMediator.new( tests )
runner.run_suite
end
end
p result
result
end

Thanks,
T.
 
A

Ara.T.Howard

Hi, I'm trying to manully run unit test using Test::Unit because I need
to isolate certain requires from others in the
course of the tests. Certain files I'm testing can potentially cause
conflits with others, so I need to run them in isolation. But I still
want to tally the tests/assertions/errors, etc. So I'm wondering if I'm
doing this right. Specifically, is popen("-", "w+") giving me a whole
seperate "require space" to utilize?

Here's my code so far:

def fork_test( testfile )
result = nil
IO.popen("-","w+") do |pipe|
result = pipe.instance_eval do
require 'test/unit'
require 'test/unit/collector'
require 'test/unit/collector/objectspace'
require 'test/unit/ui/testrunnermediator'
load( testfile )
tests = Test::Unit::Collector::ObjectSpace.new.collect
runner = Test::Unit::UI::TestRunnerMediator.new( tests )
runner.run_suite
end
end
p result
result
end

Thanks,
T.

i think you'll want to open up a pipe to the ruby interpreter and send a
program to it - forking will not give you a clean require space:

jib:~ > cat a.rb
require 'yaml'

src = <<-src
puts( require('yaml') ? 'required yaml' : 'already had yaml' )
src

#
# via child
#
stdout =
IO::popen('-', 'r+') do |child|
if child
child.puts src
child.close_write
child.read
else
eval STDIN.read
end
end
puts "child - stdout <#{ stdout.strip }>"

#
# via ruby
#
stdout =
IO::popen('ruby', 'r+') do |ruby|
ruby.puts src
ruby.close_write
ruby.read
end
puts "ruby - stdout <#{ stdout.strip }>"


jib:~ > ruby a.rb
child - stdout <already had yaml>
ruby - stdout <required yaml>

hth.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
T

Trans

Almost have it, but can anyone tell me how to stop Test::Unit from
running the automatic test runner?

Thanks,
T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top