5 class SvnRaTest < Test::Unit::TestCase
17 assert_equal(Svn::Core.subr_version, Svn::Ra.version)
21 session = Svn::Ra::Session.open(@repos_uri)
22 assert_equal(File.read(File.join(@repos_path, "db", "uuid")).strip,
26 def test_open_without_callback
27 assert_nothing_raised do
28 Svn::Ra::Session.open(@repos_uri)
37 path = File.join(@wc_path, file)
38 ctx = make_context(log)
40 path_props = {"my-prop" => "value"}
41 callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
42 session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
44 assert_equal(youngest_rev, session.latest_revnum)
45 assert_equal(@repos_uri, session.repos_root)
47 File.open(path, "w") {|f| f.print(src)}
49 info = ctx.ci(@wc_path)
52 assert_equal(info.revision, session.dated_revision(info.date))
53 content, props = session.file(file, info.revision)
54 assert_equal(src, content)
56 Svn::Core::PROP_ENTRY_COMMITTED_DATE,
57 Svn::Core::PROP_ENTRY_UUID,
58 Svn::Core::PROP_ENTRY_LAST_AUTHOR,
59 Svn::Core::PROP_ENTRY_COMMITTED_REV,
62 entries, props = session.dir("", info.revision)
63 assert_equal([file], entries.keys)
64 assert(entries[file].file?)
66 Svn::Core::PROP_ENTRY_COMMITTED_DATE,
67 Svn::Core::PROP_ENTRY_UUID,
68 Svn::Core::PROP_ENTRY_LAST_AUTHOR,
69 Svn::Core::PROP_ENTRY_COMMITTED_REV,
73 entries, props = session.dir("", info.revision, Svn::Core::DIRENT_KIND)
74 assert_equal(Svn::Core::NODE_FILE, entries[file].kind)
75 entries, props = session.dir("", info.revision, 0)
76 assert_equal(Svn::Core::NODE_NONE, entries[file].kind)
78 ctx = make_context(log2)
79 File.open(path, "w") {|f| f.print(src * 2)}
80 path_props.each do |key, value|
81 ctx.prop_set(key, value, path)
83 info = ctx.ci(@wc_path)
87 receiver = Proc.new do |changed_paths, revision, author, date, message|
88 logs << [revision, message]
90 session.log([file], rev1, rev2, rev2 - rev1 + 1, &receiver)
94 ].sort_by {|rev, log| rev},
95 logs.sort_by {|rev, log| rev})
97 assert_equal(Svn::Core::NODE_FILE, session.check_path(file))
98 assert_equal(Svn::Core::NODE_FILE, session.stat(file).kind)
104 session.locations(file, [rev1, rev2]))
107 session.file_revs(file, rev1, rev2) do |_path, rev, rev_props, prop_diffs|
108 hashed_prop_diffs = {}
109 prop_diffs.each do |prop|
110 hashed_prop_diffs[prop.name] = prop.value
112 infos << [rev, _path, hashed_prop_diffs]
115 [rev1, "/#{file}", {}],
116 [rev2, "/#{file}", path_props],
121 session.file_revs2(file, rev1, rev2) do |_path, rev, rev_props, prop_diffs|
122 infos << [rev, _path, prop_diffs]
125 [rev1, "/#{file}", {}],
126 [rev2, "/#{file}", path_props],
130 assert_equal({}, session.get_locks(""))
132 session.lock({file => rev2}) do |_path, do_lock, lock, ra_err|
133 locks << [_path, do_lock, lock, ra_err]
136 locks.collect{|_path, *rest| _path}.sort)
137 lock = locks.assoc(file)[2]
138 assert_equal(["/#{file}"],
139 session.get_locks("").collect{|_path, *rest| _path})
140 assert_equal(lock.token, session.get_lock(file).token)
141 assert_equal([lock.token],
142 session.get_locks(file).values.collect{|l| l.token})
143 session.unlock({file => lock.token})
144 assert_equal({}, session.get_locks(file))
147 def assert_property_access
150 path = File.join(@wc_path, file)
151 ctx = make_context(log)
153 callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
154 session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
156 FileUtils.touch(path)
158 info = ctx.commit(@wc_path)
160 assert_equal(@author, yield(session, :get, Svn::Core::PROP_REVISION_AUTHOR))
161 assert_equal(log, yield(session, :get, Svn::Core::PROP_REVISION_LOG))
163 Svn::Core::PROP_REVISION_AUTHOR,
164 Svn::Core::PROP_REVISION_DATE,
165 Svn::Core::PROP_REVISION_LOG,
167 yield(session, :list).keys.sort)
168 yield(session, :set, Svn::Core::PROP_REVISION_LOG, nil)
169 assert_nil(yield(session, :get ,Svn::Core::PROP_REVISION_LOG))
171 Svn::Core::PROP_REVISION_AUTHOR,
172 Svn::Core::PROP_REVISION_DATE,
174 yield(session, :list).keys.sort)
178 assert_property_access do |session, action, *args|
192 def test_prop_with_no_ruby_way
193 assert_property_access do |session, action, *args|
200 session.set_prop(key, value)
210 src1 = "sample source1"
211 src2 = "sample source2"
212 path = File.join(@wc_path, file)
213 path_in_repos = "/#{file}"
214 ctx = make_context(log)
216 callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
217 session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
219 File.open(path, "w") {|f| f.print(src1)}
221 rev1 = ctx.ci(@wc_path).revision
223 File.open(path, "w") {|f| f.print(src2)}
224 rev2 = ctx.ci(@wc_path).revision
228 editor, editor_baton = session.commit_editor(log) {}
229 reporter = session.update(rev2, "", editor, editor_baton)
230 reporter.abort_report
232 editor, editor_baton = session.commit_editor(log) {}
233 reporter = session.update2(rev2, "", editor)
234 reporter.abort_report
240 src1 = "a\nb\nc\nd\ne\n"
241 src2 = "a\nb\nC\nd\ne\n"
242 path = File.join(@wc_path, file)
243 path_in_repos = "/#{file}"
244 ctx = make_context(log)
246 callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
247 session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
249 File.open(path, "w") {|f| f.print(src1)}
251 rev1 = ctx.ci(@wc_path).revision
253 File.open(path, "w") {|f| f.print(src2)}
254 rev2 = ctx.ci(@wc_path).revision
258 editor = Svn::Delta::BaseEditor.new # dummy
259 reporter = session.diff(rev2, "", @repos_uri, editor)
260 reporter.set_path("", rev1, false, nil)
261 reporter.finish_report
264 def test_commit_editor
268 ctx = make_context(log)
269 callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
270 session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
274 expected_info = [1, @author]
275 start_time = Time.now
277 editor, baton = session.commit_editor(log) do |rev, date, author|
278 actual_info = [rev, author]
283 root = editor.open_root(-1)
284 editor.add_directory(dir_uri, root, nil, -1)
289 assert_equal(expected_info, actual_info)
290 assert_operator(start_time..(Time.now), :include?, actual_date)
294 def test_commit_editor2
298 ctx = make_context(log)
299 callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
300 session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
304 expected_info = [1, @author]
305 start_time = Time.now
307 editor = session.commit_editor2(log) do |info|
308 actual_info = [info.revision, info.author]
309 actual_date = info.date
312 root = editor.open_root(-1)
313 editor.add_directory(dir_uri, root, nil, -1)
318 assert_equal(expected_info, actual_info)
319 assert_operator(start_time..(Time.now), :include?, actual_date)
327 dir_path = File.join(@wc_path, dir)
328 deep_dir_path = File.join(dir_path, deep_dir)
330 ctx = make_context(log)
335 ctx.mkdir(deep_dir_path)
338 callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
339 session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
341 entries, props = session.dir(dir, nil)
342 assert_equal([deep_dir], entries.keys)
343 assert_raise(Svn::Error::FS_NOT_FOUND) do
344 session.dir(deep_dir)
347 session.reparent("#{@repos_uri}/#{dir}")
348 assert_raise(Svn::Error::FS_NOT_FOUND) do
351 entries, props = session.dir(deep_dir)
352 assert_equal([], entries.keys)
354 assert_raise(Svn::Error::RA_ILLEGAL_URL) do
355 session.reparent("file:///tmp/xxx")
364 trunk = File.join(@wc_path, "trunk")
365 branch = File.join(@wc_path, "branch")
366 trunk_path = File.join(trunk, file)
367 branch_path = File.join(branch, file)
368 session_relative_trunk_path = "trunk"
369 repository_branch_path = "/branch"
371 ctx = make_context(log)
372 ctx.mkdir(trunk, branch)
373 File.open(trunk_path, "w") {}
374 File.open(branch_path, "w") {}
377 rev1 = ctx.commit(@wc_path).revision
379 File.open(branch_path, "w") {|f| f.print(src)}
380 rev2 = ctx.commit(@wc_path).revision
382 callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
383 session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
385 assert_nil(session.mergeinfo(session_relative_trunk_path))
386 ctx.merge(branch, rev1, branch, rev2, trunk)
387 assert_nil(session.mergeinfo(session_relative_trunk_path))
389 rev3 = ctx.commit(@wc_path).revision
390 mergeinfo = session.mergeinfo(session_relative_trunk_path)
391 assert_equal([session_relative_trunk_path], mergeinfo.keys)
392 trunk_mergeinfo = mergeinfo[session_relative_trunk_path]
393 assert_equal([repository_branch_path], trunk_mergeinfo.keys)
394 assert_equal([[1, 2, true]],
395 trunk_mergeinfo[repository_branch_path].collect {|range|
399 rev4 = ctx.commit(@wc_path).revision
401 ctx.merge(branch, rev3, branch, rev4, trunk)
402 assert(!File.exist?(trunk_path))
403 rev5 = ctx.commit(@wc_path).revision
405 mergeinfo = session.mergeinfo(session_relative_trunk_path, rev5)
406 assert_equal([session_relative_trunk_path], mergeinfo.keys)
407 trunk_mergeinfo = mergeinfo[session_relative_trunk_path]
408 assert_equal([repository_branch_path], trunk_mergeinfo.keys)
409 assert_equal([[1, 2, true], [3, 4, true]],
410 trunk_mergeinfo[repository_branch_path].collect {|range|