From: "Ara.T.Howard" Date: 2005-08-11T23:21:11+09:00 Subject: Re: Manual Test::Unit and popen's require space On Thu, 11 Aug 2005, Trans wrote: > 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 ruby - stdout 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 ===============================================================================