4 require "my-assertions"
7 unless instance_methods.include?("to_int")
15 def setup_default_variables
16 test_dir = Pathname.new(File.dirname(__FILE__))
17 pwd = Pathname.new(Dir.pwd)
18 @base_dir = test_dir.relative_path_from(pwd).to_s
19 @author = ENV["USER"] || "sample-user"
20 @password = "sample-password"
21 @realm = "sample realm"
22 @repos_path = File.join(@base_dir, "repos")
23 @full_repos_path = File.expand_path(@repos_path)
24 @repos_uri = "file://#{@full_repos_path.sub(/^\/?/, '/')}"
25 @svnserve_host = "127.0.0.1"
26 @svnserve_ports = (64152..64282).collect{|x| x.to_s}
27 @wc_base_dir = File.join(@base_dir, "wc-tmp")
28 @wc_path = File.join(@wc_base_dir, "wc")
29 @full_wc_path = File.expand_path(@wc_path)
30 @tmp_path = File.join(@base_dir, "tmp")
31 @config_path = File.join(@base_dir, "config")
32 @greek = Greek.new(@tmp_path, @wc_path, @repos_uri)
35 def setup_basic(need_svnserve=false)
36 @need_svnserve = need_svnserve
37 setup_default_variables
41 setup_svnserve if @need_svnserve
45 GC.stress = true if GC.respond_to?(:stress=) and $DEBUG
49 GC.stress = false if GC.respond_to?(:stress=)
50 teardown_svnserve if @need_svnserve
60 before_pools = Svn::Core::Pool.number_of_pools
62 puts "before pools: #{before_pools}"
68 after_pools = Svn::Core::Pool.number_of_pools
69 puts "after pools: #{after_pools}"
74 def change_gc_status(prev_disabled)
86 def gc_disable(&block)
87 change_gc_status(GC.disable, &block)
91 change_gc_status(GC.enable, &block)
94 def setup_tmp(path=@tmp_path)
96 FileUtils.mkdir_p(path)
99 def teardown_tmp(path=@tmp_path)
100 FileUtils.rm_rf(path)
103 def setup_repository(path=@repos_path, config={}, fs_config={})
104 FileUtils.rm_rf(path)
105 FileUtils.mkdir_p(File.dirname(path))
106 Svn::Repos.create(path, config, fs_config)
107 @repos = Svn::Repos.open(@repos_path)
111 def teardown_repository(path=@repos_path)
112 @fs.close unless @fs.nil?
113 @repos.close unless @repos.nil?
114 Svn::Repos.delete(path) if File.exists?(path)
121 make_context("").checkout(@repos_uri, @wc_path)
125 FileUtils.rm_rf(@wc_base_dir)
130 Svn::Core::Config.ensure(@config_path)
134 FileUtils.rm_rf(@config_path)
137 def add_authentication
138 passwd_file = "passwd"
139 File.open(@repos.svnserve_conf, "w") do |conf|
144 password-db = #{passwd_file}
148 File.open(File.join(@repos.conf_dir, passwd_file), "w") do |f|
151 #{@author} = #{@password}
157 add_pre_revprop_change_hook
168 def prop(name, rev=nil)
172 def make_context(log)
173 ctx = Svn::Client::Context.new
174 ctx.set_log_msg_func do |items|
177 ctx.add_username_prompt_provider(0) do |cred, realm, username, may_save|
178 cred.username = @author
179 cred.may_save = false
181 setup_auth_baton(ctx.auth_baton)
185 def setup_auth_baton(auth_baton)
186 auth_baton[Svn::Core::AUTH_PARAM_CONFIG_DIR] = @config_path
187 auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = @author
190 def normalize_line_break(str)
192 str.gsub(/\n/, "\r\n")
199 @greek.setup(make_context("setup greek tree"))
204 /cygwin|mingw|mswin32|bccwin32/.match(RUBY_PLATFORM)
210 @repos_svnserve_uri = nil
212 # Look through the list of potential ports until we're able to
213 # successfully start svnserve on a free one.
214 @svnserve_ports.each do |port|
215 @svnserve_pid = fork {
218 "--listen-host", @svnserve_host,
219 "--listen-port", port,
220 "-d", "--foreground")
222 pid, status = Process.waitpid2(@svnserve_pid, Process::WNOHANG)
223 if status and status.exited?
225 STDERR.puts "port #{port} couldn't be used for svnserve"
228 # svnserve started successfully. Note port number and cease
230 @svnserve_port = port
231 @repos_svnserve_uri =
232 "svn://#{@svnserve_host}:#{@svnserve_port}#{@full_repos_path}"
236 if @svnserve_port.nil?
237 msg = "Can't run svnserve because available port "
238 msg << "isn't exist in [#{@svnserve_ports.join(', ')}]"
243 def teardown_svnserve
245 Process.kill(:TERM, @svnserve_pid)
247 Process.waitpid(@svnserve_pid)
253 def add_pre_revprop_change_hook
254 File.open(@repos.pre_revprop_change_hook, "w") do |hook|
262 if [ "$PROPNAME" = "#{Svn::Core::PROP_REVISION_LOG}" -a \
263 "$USER" = "#{@author}" ]; then
270 FileUtils.chmod(0755, @repos.pre_revprop_change_hook)
274 module SetupEnvironment
275 def setup_test_environment(top_dir, base_dir, ext_dir)
276 svnserve_dir = File.join(top_dir, 'subversion', 'svnserve')
277 ENV["PATH"] = "#{svnserve_dir}:#{ENV['PATH']}"
278 FileUtils.ln_sf(File.join(base_dir, ".libs"), ext_dir)
283 require 'windows_util'
284 include Windows::Svnserve
285 extend Windows::SetupEnvironment
288 extend SetupEnvironment