Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/bindings/swig/ruby/test/test_client.rb view on Meta::CPAN
# ====================================================================
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ====================================================================
require "my-assertions"
require "util"
require "svn/core"
require "svn/client"
class SvnClientTest < Test::Unit::TestCase
include SvnTestUtil
def setup
setup_basic(true)
end
def teardown
teardown_basic
end
def test_version
assert_equal(Svn::Core.subr_version, Svn::Client.version)
end
def test_add_not_recurse
log = "sample log"
dir = "dir"
dir_path = File.join(@wc_path, dir)
path = File.join(dir_path, dir)
uri = "#{@repos_uri}/#{dir}/#{dir}"
make_context(log) do |ctx|
FileUtils.mkdir(dir_path)
FileUtils.mkdir(path)
ctx.add(dir_path, false)
ctx.commit(@wc_path)
assert_raise(Svn::Error::FS_NOT_FOUND) do
ctx.cat(uri)
end
end
end
def test_add_recurse
log = "sample log"
file = "hello.txt"
src = "Hello"
dir = "dir"
dir_path = File.join(@wc_path, dir)
path = File.join(dir_path, file)
uri = "#{@repos_uri}/#{dir}/#{file}"
make_context(log) do |ctx|
FileUtils.mkdir(dir_path)
File.open(path, "w") {|f| f.print(src)}
ctx.add(dir_path)
ctx.commit(@wc_path)
assert_equal(src, ctx.cat(uri))
end
end
def test_add_force
log = "sample log"
file = "hello.txt"
src = "Hello"
dir = "dir"
dir_path = File.join(@wc_path, dir)
path = File.join(dir_path, file)
uri = "#{@repos_uri}/#{dir}/#{file}"
make_context(log) do |ctx|
FileUtils.mkdir(dir_path)
File.open(path, "w") {|f| f.print(src)}
ctx.add(dir_path, false)
ctx.commit(@wc_path)
assert_raise(Svn::Error::ENTRY_EXISTS) do
ctx.add(dir_path, true, false)
end
ctx.add(dir_path, true, true)
ctx.commit(@wc_path)
assert_equal(src, ctx.cat(uri))
end
src/subversion/subversion/bindings/swig/ruby/test/test_client.rb view on Meta::CPAN
end
end
def test_diff_summarize_peg
log = "sample log"
before = "before\n"
after = "after\n"
before_file = "before.txt"
after_file = "after.txt"
moved_file = "moved.txt"
before_path = File.join(@wc_path, before_file)
after_path = File.join(@wc_path, after_file)
moved_path = File.join(@wc_path, moved_file)
File.open(before_path, "w") {|f| f.print(before)}
make_context(log) do |ctx|
ctx.add(before_path)
commit_info = ctx.commit(@wc_path)
rev1 = commit_info.revision
ctx.mv(before_path, after_path)
commit_info = ctx.commit(@wc_path)
rev2 = commit_info.revision
File.open(after_path, "w") {|f| f.print(after)}
commit_info = ctx.commit(@wc_path)
rev3 = commit_info.revision
File.open(after_path, "w") {|f| f.print(before)}
commit_info = ctx.commit(@wc_path)
rev4 = commit_info.revision
ctx.mv(after_path, moved_path)
commit_info = ctx.commit(@wc_path)
rev5 = commit_info.revision
diffs = []
ctx.diff_summarize_peg(@repos_uri, rev3, rev4, rev3) do |diff|
diffs << diff
end
assert_equal([after_file], diffs.collect {|d| d.path})
kinds = diffs.collect do |d|
[d.kind_normal?, d.kind_added?, d.kind_modified?, d.kind_deleted?]
end
assert_equal([[false, false, true, false]], kinds)
assert_equal([false], diffs.collect {|d| d.prop_changed?})
node_kinds = diffs.collect do |d|
[d.node_kind_none?, d.node_kind_file?,
d.node_kind_dir?, d.node_kind_unknown?]
end
assert_equal([[false, true, false, false]], node_kinds)
end
end
def assert_changed(ctx, path)
statuses = []
ctx.status(path) do |_, status|
statuses << status
end
assert_not_equal([], statuses)
end
def assert_not_changed(ctx, path)
statuses = []
ctx.status(path) do |_, status|
statuses << status
end
assert_equal([], statuses)
end
def assert_merge
log = "sample log"
file = "sample.txt"
src = "sample\n"
trunk = File.join(@wc_path, "trunk")
branch = File.join(@wc_path, "branch")
branch_relative_uri = "/branch"
branch_uri = "#{@repos_uri}#{branch_relative_uri}"
trunk_path = File.join(trunk, file)
trunk_path_uri = "#{@repos_uri}/trunk/#{file}"
branch_path = File.join(branch, file)
branch_path_relative_uri = "#{branch_relative_uri}/#{file}"
branch_path_uri = "#{@repos_uri}#{branch_path_relative_uri}"
make_context(log) do |ctx|
ctx.mkdir(trunk, branch)
File.open(trunk_path, "w") {}
File.open(branch_path, "w") {}
ctx.add(trunk_path)
ctx.add(branch_path)
rev1 = ctx.commit(@wc_path).revision
File.open(branch_path, "w") {|f| f.print(src)}
rev2 = ctx.commit(@wc_path).revision
merged_entries = []
ctx.log_merged(trunk, nil, branch_uri, nil) do |entry|
merged_entries << entry
end
assert_equal_log_entries([], merged_entries)
assert_nil(ctx.merged(trunk))
merged_entries = []
yield(ctx, branch, rev1, rev2, trunk)
ctx.log_merged(trunk, nil, branch_uri, nil) do |entry|
merged_entries << entry
end
assert_equal_log_entries([
[
{branch_path_relative_uri => ["M", nil, -1]},
rev2,
{
"svn:author" => @author,
"svn:log" => log,
},
false,
]
],
merged_entries)
mergeinfo = ctx.merged(trunk)
assert_not_nil(mergeinfo)
assert_equal([branch_uri], mergeinfo.keys)
ranges = mergeinfo[branch_uri].collect {|range| range.to_a}
assert_equal([[1, 2, true]], ranges)
rev3 = ctx.commit(@wc_path).revision
assert_equal(normalize_line_break(src), ctx.cat(trunk_path, rev3))
ctx.rm(branch_path)
rev4 = ctx.commit(@wc_path).revision
yield(ctx, branch, rev3, rev4, trunk)
assert(!File.exist?(trunk_path))
merged_entries = []
ctx.log_merged(trunk, rev4, branch_uri, rev4) do |entry|
merged_entries << entry
end
assert_equal_log_entries([
[
{branch_path_relative_uri => ["M", nil, -1]},
rev2,
{
"svn:author" => @author,
"svn:log" => log,
},
false,
]
], merged_entries)
ctx.propdel("svn:mergeinfo", trunk)
merged_entries = []
ctx.log_merged(trunk, rev4, branch_uri, rev4) do |entry|
merged_entries << entry
end
assert_equal_log_entries([
[
{branch_path_relative_uri => ["M", nil, -1]},
rev2,
{
"svn:author" => @author,
"svn:log" => log,
},
false,
]
], merged_entries)
ctx.revert(trunk)
File.open(trunk_path, "a") {|f| f.print(src)}
yield(ctx, branch, rev3, rev4, trunk)
ctx.revert(trunk, false)
ctx.resolve(:path=>trunk_path,
:conflict_choice=>Svn::Wc::CONFLICT_CHOOSE_MERGED)
rev5 = ctx.commit(@wc_path).revision
assert(File.exist?(trunk_path))
ctx.up(@wc_path)
yield(ctx, branch, rev3, rev4, trunk, nil, false, true)
assert_changed(ctx, trunk)
ctx.propdel("svn:mergeinfo", trunk)
rev6 = ctx.commit(@wc_path).revision
yield(ctx, branch, rev3, rev4, trunk, nil, false, true, true)
assert_not_changed(ctx, trunk)
yield(ctx, branch, rev3, rev4, trunk, nil, false, true)
assert_changed(ctx, trunk)
end
end
def test_merge
assert_merge do |ctx, from, from_rev1, from_rev2, to, *rest|
ctx.merge(from, from_rev1, from, from_rev2, to, *rest)
end
end
def test_merge_peg
assert_merge do |ctx, from, from_rev1, from_rev2, to, *rest|
ctx.merge_peg(from, from_rev1, from_rev2, to, nil, *rest)
end
end
=begin
We haven't yet figured out what to expect in the case of an obstruction,
but it is no longer an error. Commenting out this test until that
decision is made (see issue #3680:
http://subversion.tigris.org/issues/show_bug.cgi?id=3680)
def test_cleanup
log = "sample log"
file = "sample.txt"
src = "sample\n"
path = File.join(@wc_path, file)
make_context(log) do |ctx|
File.open(path, "w") {|f| f.print(src)}
ctx.add(path)
rev = ctx.commit(@wc_path).revision
ctx.up(@wc_path, rev - 1)
File.open(path, "w") {|f| f.print(src)}
assert_raise(Svn::Error::WC_OBSTRUCTED_UPDATE) do
ctx.up(@wc_path, rev)
end
Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1) do |access|
assert_raise(Svn::Error::WC_LOCKED) do
ctx.commit(@wc_path)
end
end
ctx.set_cancel_func do
raise Svn::Error::CANCELLED
end
Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1) do |access|
assert_raise(Svn::Error::CANCELLED) do
ctx.cleanup(@wc_path)
end
assert_raise(Svn::Error::WC_LOCKED) do
ctx.commit(@wc_path)
end
end
src/subversion/subversion/bindings/swig/ruby/test/test_client.rb view on Meta::CPAN
File.open(path, "w") {|f| f.print(src)}
ctx.add(path)
ctx.commit(@wc_path)
assert_nothing_raised do
ctx.cat(path)
end
ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
cred.username = @author
cred.password = @password
cred.may_save = true
end
ctx.relocate(@wc_path, @repos_uri, @repos_svnserve_uri)
make_context(log) do |ctx|
assert_raises(Svn::Error::AuthnNoProvider) do
ctx.cat(path)
end
end
end
end
def test_resolved
log = "sample log"
file = "sample.txt"
dir = "dir"
src1 = "before\n"
src2 = "after\n"
dir_path = File.join(@wc_path, dir)
path = File.join(dir_path, file)
make_context(log) do |ctx|
ctx.mkdir(dir_path)
File.open(path, "w") {}
ctx.add(path)
rev1 = ctx.ci(@wc_path).revision
File.open(path, "w") {|f| f.print(src1)}
rev2 = ctx.ci(@wc_path).revision
ctx.up(@wc_path, rev1)
File.open(path, "w") {|f| f.print(src2)}
ctx.up(@wc_path)
assert_raises(Svn::Error::WcFoundConflict) do
ctx.ci(@wc_path)
end
ctx.resolved(dir_path, false)
assert_raises(Svn::Error::WcFoundConflict) do
ctx.ci(@wc_path)
end
ctx.resolved(dir_path)
info = nil
assert_nothing_raised do
info = ctx.ci(@wc_path)
end
assert_not_nil(info)
assert_equal(rev2 + 1, info.revision)
end
end
def test_copy
log = "sample log"
src = "source\n"
file1 = "sample1.txt"
file2 = "sample2.txt"
path1 = Pathname.new(@wc_path) + file1
path2 = Pathname.new(@wc_path) + file2
full_path2 = path2.expand_path
make_context(log) do |ctx|
File.open(path1, "w") {|f| f.print(src)}
ctx.add(path1.to_s)
ctx.ci(@wc_path)
ctx.cp(path1.to_s, path2.to_s)
infos = []
ctx.set_notify_func do |notify|
infos << [notify.path, notify]
end
ctx.ci(@wc_path)
assert_equal([full_path2.to_s].sort,
infos.collect{|path, notify| path}.sort)
path2_notify = infos.assoc(full_path2.to_s)[1]
assert(path2_notify.commit_added?)
assert_equal(File.open(path1) {|f| f.read},
File.open(path2) {|f| f.read})
end
end
def test_move
log = "sample log"
src = "source\n"
file1 = "sample1.txt"
file2 = "sample2.txt"
path1 = File.join(@wc_path, file1)
path2 = File.join(@wc_path, file2)
make_context(log) do |ctx|
File.open(path1, "w") {|f| f.print(src)}
ctx.add(path1)
ctx.ci(@wc_path)
ctx.mv(path1, path2)
infos = []
ctx.set_notify_func do |notify|
infos << [notify.path, notify]
end
ctx.ci(@wc_path)
assert_equal([path1, path2].sort.collect{|p|File.expand_path(p)},
infos.collect{|path, notify| path}.sort)
src/subversion/subversion/bindings/swig/ruby/test/test_client.rb view on Meta::CPAN
path = File.join(@wc_path, file)
uri = "#{@repos_uri}/#{file}"
make_context(log) do |ctx|
File.open(path, "w") {|f| f.print(src)}
ctx.add(path)
ctx.commit(@wc_path)
first_commit_time = Time.now
sleep(1)
File.open(path, "w") {|f| f.print(src_after)}
ctx.commit(@wc_path)
assert_equal(src, ctx.cat(uri, first_commit_time))
end
end
def assert_resolve(choice)
log = "sample log"
file = "sample.txt"
srcs = ["before\n","after\n"]
dir = "dir"
dir_path = File.join(@wc_path, dir)
path = File.join(dir_path, file)
make_context(log) do |ctx|
ctx.mkdir(dir_path)
File.open(path, "w") {}
ctx.add(path)
rev1 = ctx.ci(@wc_path).revision
File.open(path, "w") {|f| f.print(srcs[0])}
rev2 = ctx.ci(@wc_path).revision
ctx.up(@wc_path, rev1)
File.open(path, "w") {|f| f.print(srcs[1])}
ctx.up(@wc_path)
assert_raises(Svn::Error::WcFoundConflict) do
ctx.ci(@wc_path)
end
ctx.resolve(:path=>dir_path, :depth=>:empty, :conflict_choice=>choice)
assert_raises(Svn::Error::WcFoundConflict) do
ctx.ci(@wc_path)
end
ctx.resolve(:path=>dir_path, :depth=>:infinity, :conflict_choice=>choice)
yield ctx, path
end
end
def test_resolve_base
assert_resolve(Svn::Wc::CONFLICT_CHOOSE_BASE) do |ctx,path|
info = nil
assert_nothing_raised do
info = ctx.ci(@wc_path)
end
assert_not_nil(info)
assert_equal(3, info.revision)
assert_equal("", File.read(path))
end
end
def test_resolve_theirs_full
assert_resolve(Svn::Wc::CONFLICT_CHOOSE_THEIRS_FULL) do |ctx,path|
info = nil
assert_nothing_raised do
info = ctx.ci(@wc_path)
end
assert_not_nil(info)
assert_equal(-1, info.revision)
assert_equal("before\n", File.read(path))
end
end
def test_resolve_mine_full
assert_resolve(Svn::Wc::CONFLICT_CHOOSE_MINE_FULL) do |ctx,path|
info = nil
assert_nothing_raised do
info = ctx.ci(@wc_path)
end
assert_not_nil(info)
assert_equal(3, info.revision)
assert_equal("after\n", File.read(path))
end
end
def test_resolve_theirs_conflict
assert_resolve(Svn::Wc::CONFLICT_CHOOSE_THEIRS_FULL) do |ctx,path|
info = nil
assert_nothing_raised do
info = ctx.ci(@wc_path)
end
assert_not_nil(info)
assert_equal(-1, info.revision)
assert_equal("before\n", File.read(path))
end
end
def test_resolve_mine_conflict
assert_resolve(Svn::Wc::CONFLICT_CHOOSE_MINE_FULL) do |ctx,path|
info = nil
assert_nothing_raised do
info = ctx.ci(@wc_path)
end
assert_not_nil(info)
assert_equal(3, info.revision)
assert_equal("after\n", File.read(path))
end
end
def test_resolve_merged
assert_resolve(Svn::Wc::CONFLICT_CHOOSE_MERGED) do |ctx,path|
info = nil
assert_nothing_raised do
info = ctx.ci(@wc_path)
end
assert_not_nil(info)
assert_equal(3, info.revision)
assert_equal("<<<<<<< .mine\nafter\n=======\nbefore\n>>>>>>> .r2\n",
File.read(path))
end
end
end
( run in 0.801 second using v1.01-cache-2.11-cpan-524268b4103 )