Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/bindings/swig/ruby/test/util.rb view on Meta::CPAN
# Tale of a hack...
#
# Here we are, %SVN-WC-ROOT%/subversion/bindings/swig/ruby/test/util.rb,
# trying to require %SVN-WC-ROOT%/subversion/bindings/swig/ruby/svn/util.rb,
# all the while supporting both Ruby 1.8 and 1.9. Simply using this,
#
# require "svn/util"
#
# works for Ruby 1.8 if the CWD is subversion/bindings/swig/ruby
# when we are running the tests, e.g.:
#
# %SVN-WC-ROOT%/subversion/bindings/swig/ruby>ruby test\run-test.rb
#
# This is because the CWD is included in the load path when Ruby 1.8
# searches for required files. But this doesn't work for Ruby 1.9,
# which doesn't include the CWD this way, so instead we could use this:
#
# require "./svn/util"
#
# But that only works if ./svn/util is relative to the CWD (again if the
# CWD is %SVN-WC-ROOT%/subversion/bindings/swig/ruby). However, if we run
# the tests from a different CWD and specify
# %SVN-WC-ROOT%/subversion/bindings/swig/ruby as an additional $LOAD_PATH
# using the ruby -I option, then that fails on both 1.8 and 1.9 with a
# LoadError.
#
# The usual solution in a case like this is to use require_relative,
#
# require_relative "../svn/util"
#
# But that's only available in Ruby 1.9. We could require the backports gem
# but there is a simple workaround, just calculate the full path of util:
require File.join(File.dirname(__FILE__), '../svn/util')
require "tmpdir"
require "my-assertions"
class Time
unless instance_methods.include?("to_int")
alias to_int to_i
end
end
require 'greek_tree'
module SvnTestUtil
def setup_default_variables
@author = ENV["USER"] || "sample-user"
@password = "sample-password"
@realm = "sample realm"
@svnserve_host = "127.0.0.1"
@svnserve_ports = (64152..64282).collect{|x| x.to_s}
@tmp_path = Dir.mktmpdir
@wc_path = File.join(@tmp_path, "wc")
@import_path = File.join(@tmp_path, "import")
@repos_path = File.join(@tmp_path, "repos")
@full_repos_path = File.expand_path(@repos_path)
@repos_uri = "file://#{@full_repos_path.sub(/^\/?/, '/')}"
@config_path = "config"
@greek = Greek.new(@tmp_path, @import_path, @wc_path, @repos_uri)
end
def setup_basic(need_svnserve=false)
@need_svnserve = need_svnserve
setup_default_variables
setup_tmp
setup_tmp(@import_path)
setup_repository
add_hooks
setup_svnserve if @need_svnserve
setup_config
setup_wc
add_authentication
GC.stress = true if GC.respond_to?(:stress=) and $DEBUG
end
def teardown_basic
GC.stress = false if GC.respond_to?(:stress=)
teardown_svnserve if @need_svnserve
teardown_repository
teardown_wc
teardown_config
teardown_tmp
gc
end
def gc
if $DEBUG
before_pools = Svn::Core::Pool.number_of_pools
puts
puts "before pools: #{before_pools}"
end
gc_enable do
GC.start
end
if $DEBUG
after_pools = Svn::Core::Pool.number_of_pools
puts "after pools: #{after_pools}"
STDOUT.flush
end
end
def change_gc_status(prev_disabled)
begin
yield
ensure
if prev_disabled
GC.disable
else
GC.enable
end
end
end
def gc_disable(&block)
change_gc_status(GC.disable, &block)
( run in 0.649 second using v1.01-cache-2.11-cpan-5b529ec07f3 )