⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_client.rb

📁 subversion-1.4.3-1.tar.gz 配置svn的源码
💻 RB
📖 第 1 页 / 共 4 页
字号:
require "my-assertions"require "util"require "svn/core"require "svn/client"class SvnClientTest < Test::Unit::TestCase  include SvnTestUtil  def setup    setup_basic  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"    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}"    ctx = make_context(log)    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::FS_NOT_FOUND) do      ctx.cat(uri)    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}"    ctx = make_context(log)    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  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}"    ctx = make_context(log)    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  def test_add_no_ignore    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}"    ctx = make_context(log)    FileUtils.mkdir(dir_path)    File.open(path, "w") {|f| f.print(src)}    ctx.add(dir_path, false)    ctx.propset(Svn::Core::PROP_IGNORE, file, dir_path)    ctx.commit(@wc_path)    ctx.add(dir_path, true, true, false)    ctx.commit(@wc_path)    assert_raise(Svn::Error::FS_NOT_FOUND) do      ctx.cat(uri)    end        ctx.add(dir_path, true, true, true)    ctx.commit(@wc_path)    assert_equal(src, ctx.cat(uri))  end  def test_mkdir    log = "sample log"    dir = "dir"    deep_dir = ["d", "e", "e", "p"]    dir2 = "dir2"    dir_uri = "#{@repos_uri}/#{dir}"    deep_dir_uri = "#{@repos_uri}/#{deep_dir.join('/')}"    dir2_uri = "#{@repos_uri}/#{dir2}"    dir_path = File.join(@wc_path, dir)    deep_dir_path = File.join(@wc_path, *deep_dir)    dir2_path = File.join(@wc_path, dir2)    ctx = make_context(log)    assert(!File.exist?(dir_path))    ctx.mkdir(dir_path)    assert(File.exist?(dir_path))    assert_raises(Svn::Error::ENTRY_EXISTS) do      ctx.add(dir_path)    end    old_rev = ctx.commit(@wc_path).revision    new_rev = ctx.mkdir(dir2_uri).revision    assert_equal(old_rev + 1, new_rev)    assert_raises(Svn::Error::FS_ALREADY_EXISTS) do      ctx.mkdir(dir2_uri)    end    assert(!File.exist?(dir2_path))    ctx.update(@wc_path)    assert(File.exist?(dir2_path))    assert_raises(Svn::Error) do      ctx.mkdir(deep_dir_path)    end  end  def test_mkdir_multiple    log = "sample log"    dir = "dir"    dir2 = "dir2"    dirs = [dir, dir2]    dirs_path = dirs.collect{|d| File.join(@wc_path, d)}    dirs_uri = dirs.collect{|d| "#{@repos_uri}/#{d}"}    ctx = make_context(log)    infos = []    ctx.set_notify_func do |notify|      infos << [notify.path, notify]    end        dirs_path.each do |path|      assert(!File.exist?(path))    end    ctx.mkdir(dirs_path)    assert_equal(dirs_path.sort,                 infos.collect{|path, notify| path}.sort)    assert_equal(dirs_path.collect{true},                 infos.collect{|path, notify| notify.add?})    dirs_path.each do |path|      assert(File.exist?(path))    end    infos.clear    ctx.commit(@wc_path)    assert_equal(dirs_path.sort,                 infos.collect{|path, notify| path}.sort)    assert_equal(dirs_path.collect{true},                 infos.collect{|path, notify| notify.commit_added?})  end  def test_mkdir_multiple2    log = "sample log"    dir = "dir"    dir2 = "dir2"    dirs = [dir, dir2]    dirs_path = dirs.collect{|d| File.join(@wc_path, d)}    dirs_uri = dirs.collect{|d| "#{@repos_uri}/#{d}"}    ctx = make_context(log)    infos = []    ctx.set_notify_func do |notify|      infos << [notify.path, notify]    end        dirs_path.each do |path|      assert(!File.exist?(path))    end    ctx.mkdir(*dirs_path)    assert_equal(dirs_path.sort,                 infos.collect{|path, notify| path}.sort)    assert_equal(dirs_path.collect{true},                 infos.collect{|path, notify| notify.add?})    dirs_path.each do |path|      assert(File.exist?(path))    end    infos.clear    ctx.commit(@wc_path)    assert_equal(dirs_path.sort,                 infos.collect{|path, notify| path}.sort)    assert_equal(dirs_path.collect{true},                 infos.collect{|path, notify| notify.commit_added?})  end  def test_delete    log = "sample log"    src = "sample source\n"    file = "file.txt"    dir = "dir"    path = File.join(@wc_path, file)    dir_path = File.join(@wc_path, dir)    ctx = make_context(log)    File.open(path, "w") {|f| f.print(src)}    ctx.add(path)    ctx.mkdir(dir_path)    ctx.commit(@wc_path)    ctx.delete([path, dir_path])    ctx.commit(@wc_path)    assert(!File.exist?(path))    assert(!File.exist?(dir_path))        File.open(path, "w") {|f| f.print(src)}    ctx.add(path)    ctx.commit(@wc_path)    File.open(path, "w") {|f| f.print(src * 2)}    gc_disable do      assert_raises(Svn::Error::CLIENT_MODIFIED) do        ctx.delete(path)      end      assert_raises(Svn::Error::WC_LOCKED) do        ctx.delete(path, true)      end      ctx.cleanup(@wc_path)      ctx.delete(path, true)      ctx.commit(@wc_path)    end    assert(!File.exist?(path))  end   def test_delete_alias    log = "sample log"    src = "sample source\n"    file = "file.txt"    dir = "dir"    path = File.join(@wc_path, file)    dir_path = File.join(@wc_path, dir)    ctx = make_context(log)    File.open(path, "w") {|f| f.print(src)}    ctx.add(path)    ctx.mkdir(dir_path)    ctx.commit(@wc_path)    ctx.rm([path, dir_path])    ctx.commit(@wc_path)    assert(!File.exist?(path))    assert(!File.exist?(dir_path))        File.open(path, "w") {|f| f.print(src)}    ctx.add(path)    ctx.commit(@wc_path)    File.open(path, "w") {|f| f.print(src * 2)}    gc_disable do      assert_raises(Svn::Error::CLIENT_MODIFIED) do        ctx.rm(path)      end      assert_raises(Svn::Error::WC_LOCKED) do        ctx.rm_f(path)      end      ctx.cleanup(@wc_path)      ctx.rm_f(path)      ctx.commit(@wc_path)    end    assert(!File.exist?(path))    File.open(path, "w") {|f| f.print(src)}    ctx.add(path)    ctx.mkdir(dir_path)    ctx.commit(@wc_path)    ctx.rm_f(path, dir_path)    ctx.commit(@wc_path)    assert(!File.exist?(path))    assert(!File.exist?(dir_path))  end    def test_import    src = "source\n"    log = "sample log"    deep_dir = File.join(%w(a b c d e))    file = "sample.txt"    deep_dir_path = File.join(@wc_path, deep_dir)    path = File.join(deep_dir_path, file)    tmp_deep_dir_path = File.join(@tmp_path, deep_dir)    tmp_path = File.join(tmp_deep_dir_path, file)    ctx = make_context(log)    FileUtils.mkdir_p(tmp_deep_dir_path)    File.open(tmp_path, "w") {|f| f.print(src)}    ctx.import(@tmp_path, @repos_uri)    ctx.up(@wc_path)    assert_equal(src, File.open(path){|f| f.read})  end    def test_commit    log = "sample log"    dir1 = "dir1"    dir2 = "dir2"    dir1_path = File.join(@wc_path, dir1)    dir2_path = File.join(dir1_path, dir2)        ctx = make_context(log)    assert_nil(ctx.commit(@wc_path))    ctx.mkdir(dir1_path)    assert_equal(0, youngest_rev)    assert_equal(1, ctx.commit(@wc_path).revision)    ctx.mkdir(dir2_path)    assert_nil(ctx.commit(@wc_path, false))    assert_equal(2, ctx.ci(@wc_path).revision)  end  def test_status    log = "sample log"    file1 = "sample1.txt"    file2 = "sample2.txt"    dir = "dir"    dir_path = File.join(@wc_path, dir)    path1 = File.join(@wc_path, file1)    path2 = File.join(dir_path, file2)        ctx = make_context(log)    File.open(path1, "w") {}    ctx.add(path1)    rev1 = ctx.commit(@wc_path).revision        ctx.mkdir(dir_path)    File.open(path2, "w") {}        infos = []    rev = ctx.status(@wc_path) do |path, status|      infos << [path, status]    end    assert_equal(youngest_rev, rev)    assert_equal([dir_path, path2].sort,                 infos.collect{|path, status| path}.sort)    dir_status = infos.assoc(dir_path).last    assert(dir_status.text_added?)    assert(dir_status.entry.dir?)    assert(dir_status.entry.add?)    path2_status = infos.assoc(path2).last    assert(!path2_status.text_added?)    assert_nil(path2_status.entry)    infos = []    rev = ctx.st(@wc_path, rev1, true, true) do |path, status|      infos << [path, status]    end        assert_equal(rev1, rev)    assert_equal([@wc_path, dir_path, path1, path2].sort,                 infos.collect{|path, status| path}.sort)    wc_status = infos.assoc(@wc_path).last    assert(wc_status.text_normal?)    assert(wc_status.entry.dir?)    assert(wc_status.entry.normal?)    dir_status = infos.assoc(dir_path).last    assert(dir_status.text_added?)    assert(dir_status.entry.dir?)    assert(dir_status.entry.add?)    path1_status = infos.assoc(path1).last    assert(path1_status.text_normal?)    assert(path1_status.entry.file?)    assert(path1_status.entry.normal?)    path2_status = infos.assoc(path2).last    assert(!path2_status.text_added?)    assert_nil(path2_status.entry)    ctx.prop_set(Svn::Core::PROP_IGNORE, file2, dir_path)    infos = []    rev = ctx.status(@wc_path, nil, true, true, true, false) do |path, status|      infos << [path, status]    end        assert_equal(rev1, rev)    assert_equal([@wc_path, dir_path, path1].sort,                 infos.collect{|path, status| path}.sort)    infos = []    rev = ctx.status(@wc_path, nil, true, true, true, true) do |path, status|      infos << [path, status]    end        assert_equal(rev1, rev)    assert_equal([@wc_path, dir_path, path1, path2].sort,                 infos.collect{|path, status| path}.sort)  end  def test_checkout    log = "sample log"    file = "hello.txt"    dir = "dir"    dir_path = File.join(@wc_path, dir)    path = File.join(dir_path, file)    content = "Hello"    ctx = make_context(log)    ctx.mkdir(dir_path)    File.open(path, "w"){|f| f.print(content)}    ctx.add(path)    ctx.commit(@wc_path)    FileUtils.rm_rf(@wc_path)    ctx.checkout(@repos_uri, @wc_path)    assert(File.exist?(path))    FileUtils.rm_rf(@wc_path)    ctx.co(@repos_uri, @wc_path, nil, nil, false)    assert(!File.exist?(path))  end    def test_update    log = "sample log"    file = "hello.txt"    path = File.join(@wc_path, file)    content = "Hello"    File.open(path, "w"){|f| f.print(content)}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -