📄 test_client.rb
字号:
ctx = make_context(log) assert_nothing_raised do ctx.update(File.join(@wc_path, "non-exist"), youngest_rev) end ctx.add(path) commit_info = ctx.commit(@wc_path) FileUtils.rm(path) assert(!File.exist?(path)) assert_equal(commit_info.revision, ctx.update(path, commit_info.revision)) assert_equal(content, File.read(path)) FileUtils.rm(path) assert(!File.exist?(path)) assert_equal([commit_info.revision], ctx.update([path], commit_info.revision)) assert_equal(content, File.read(path)) assert_raise(Svn::Error::FS_NO_SUCH_REVISION) do begin ctx.update(path, commit_info.revision + 1) ensure ctx.cleanup(@wc_path) end end assert_nothing_raised do ctx.update(path + "non-exist", commit_info.revision) end end def test_revert log = "sample log" file1 = "hello1.txt" file2 = "hello2.txt" file3 = "hello3.txt" dir = "dir" dir_path = File.join(@wc_path, dir) path1 = File.join(@wc_path, file1) path2 = File.join(@wc_path, file2) path3 = File.join(dir_path, file3) content = "Hello" ctx = make_context(log) File.open(path1, "w"){|f| f.print(content)} File.open(path2, "w"){|f| f.print(content)} ctx.add(path1) ctx.add(path2) ctx.mkdir(dir_path) File.open(path3, "w"){|f| f.print(content)} ctx.add(path3) commit_info = ctx.commit(@wc_path) File.open(path1, "w"){} assert_equal("", File.open(path1){|f| f.read}) ctx.revert(path1) assert_equal(content, File.open(path1){|f| f.read}) File.open(path1, "w"){} File.open(path2, "w"){} assert_equal("", File.open(path1){|f| f.read}) assert_equal("", File.open(path2){|f| f.read}) ctx.revert([path1, path2]) assert_equal(content, File.open(path1){|f| f.read}) assert_equal(content, File.open(path2){|f| f.read}) File.open(path1, "w"){} File.open(path2, "w"){} File.open(path3, "w"){} assert_equal("", File.open(path1){|f| f.read}) assert_equal("", File.open(path2){|f| f.read}) assert_equal("", File.open(path3){|f| f.read}) ctx.revert(@wc_path) assert_equal(content, File.open(path1){|f| f.read}) assert_equal(content, File.open(path2){|f| f.read}) assert_equal(content, File.open(path3){|f| f.read}) File.open(path1, "w"){} File.open(path2, "w"){} File.open(path3, "w"){} assert_equal("", File.open(path1){|f| f.read}) assert_equal("", File.open(path2){|f| f.read}) assert_equal("", File.open(path3){|f| f.read}) ctx.revert(@wc_path, false) assert_equal("", File.open(path1){|f| f.read}) assert_equal("", File.open(path2){|f| f.read}) assert_equal("", File.open(path3){|f| f.read}) File.open(path1, "w"){} File.open(path2, "w"){} File.open(path3, "w"){} assert_equal("", File.open(path1){|f| f.read}) assert_equal("", File.open(path2){|f| f.read}) assert_equal("", File.open(path3){|f| f.read}) ctx.revert(dir_path) assert_equal("", File.open(path1){|f| f.read}) assert_equal("", File.open(path2){|f| f.read}) assert_equal(content, File.open(path3){|f| f.read}) end def test_log log1 = "sample log1" log2 = "sample log2" log3 = "sample log3" src1 = "source1\n" src2 = "source2\n" src3 = "source3\n" file1 = "sample1.txt" file2 = "sample2.txt" file3 = "sample3.txt" path1 = File.join(@wc_path, file1) path2 = File.join(@wc_path, file2) path3 = File.join(@wc_path, file3) abs_path1 = File.join('', file1) abs_path2 = File.join('', file2) abs_path3 = File.join('', file3) ctx = make_context(log1) File.open(path1, "w") {|f| f.print(src1)} ctx.add(path1) rev1 = ctx.ci(@wc_path).revision ctx = make_context(log2) ctx.cp(path1, path2) rev2 = ctx.ci(@wc_path).revision ctx = make_context(log3) ctx.cp(path1, path3) File.open(path1, "w") {|f| f.print(src2)} File.open(path3, "w") {|f| f.print(src3)} rev3 = ctx.ci(@wc_path).revision changed_paths_lists = {} revs = {} messages = {} keys = [@wc_path, path1, path2, path3] keys.each do |key| revs[key] = [] changed_paths_lists[key] = [] messages[key] = [] args = [key, 1, "HEAD", 0, true, nil] ctx.log(*args) do |changed_paths, rev, author, date, message| revs[key] << rev changed_paths_lists[key] << changed_paths messages[key] << message end end changed_paths_list = changed_paths_lists[@wc_path] assert_equal([rev1, rev2, rev3], revs[@wc_path]) assert_equal([rev1, rev3], revs[path1]) assert_equal([rev1, rev2], revs[path2]) assert_equal([rev1, rev3], revs[path3]) assert_equal([log1, log2, log3], messages[@wc_path]) expected = [[abs_path1], [abs_path2], [abs_path1, abs_path3]] actual = changed_paths_list.collect {|changed_paths| changed_paths.keys} assert_nested_sorted_array(expected, actual) assert_equal('A', changed_paths_list[0][abs_path1].action) assert_false(changed_paths_list[0][abs_path1].copied?) assert_equal('A', changed_paths_list[1][abs_path2].action) assert_true(changed_paths_list[1][abs_path2].copied?) assert_equal(abs_path1, changed_paths_list[1][abs_path2].copyfrom_path) assert_equal(rev1, changed_paths_list[1][abs_path2].copyfrom_rev) assert_equal('M', changed_paths_list[2][abs_path1].action) assert_equal('A', changed_paths_list[2][abs_path3].action) end def test_log_message log = "sample log" file = "hello.txt" path = File.join(@wc_path, file) FileUtils.touch(path) ctx = make_context(log) ctx.add(path) commit_info = ctx.commit(@wc_path) rev = commit_info.revision assert_equal(log, ctx.log_message(path, rev)) end def test_blame log = "sample log" file = "hello.txt" srcs = %w(first second third) infos = [] path = File.join(@wc_path, file) ctx = make_context(log) File.open(path, "w") {|f| f.puts(srcs[0])} ctx.add(path) commit_info = ctx.commit(@wc_path) infos << [0, commit_info.revision, @author, commit_info.date, srcs[0]] File.open(path, "a") {|f| f.puts(srcs[1])} commit_info = ctx.commit(@wc_path) infos << [1, commit_info.revision, @author, commit_info.date, srcs[1]] File.open(path, "a") {|f| f.puts(srcs[2])} commit_info = ctx.commit(@wc_path) infos << [2, commit_info.revision, @author, commit_info.date, srcs[2]] result = [] ctx.blame(path) do |line_no, revision, author, date, line| result << [line_no, revision, author, date, line] end assert_equal(infos, result) ctx.prop_set(Svn::Core::PROP_MIME_TYPE, "image/DUMMY", path) ctx.commit(@wc_path) assert_raise(Svn::Error::CLIENT_IS_BINARY_FILE) do ctx.ann(path) {} end end def test_diff log = "sample log" before = "before\n" after = "after\n" file = "hello.txt" path = File.join(@wc_path, file) File.open(path, "w") {|f| f.print(before)} ctx = make_context(log) ctx.add(path) commit_info = ctx.commit(@wc_path) rev1 = commit_info.revision File.open(path, "w") {|f| f.print(after)} out_file = Tempfile.new("svn") err_file = Tempfile.new("svn") ctx.diff([], path, rev1, path, "WORKING", out_file.path, err_file.path) out_file.open assert_match(/-#{before}\+#{after}\z/, out_file.read) commit_info = ctx.commit(@wc_path) rev2 = commit_info.revision out_file = Tempfile.new("svn") ctx.diff([], path, rev1, path, rev2, out_file.path, err_file.path) out_file.open assert_match(/-#{before}\+#{after}\z/, out_file.read) end def test_diff_peg log = "sample log" before = "before\n" after = "after\n" file = "hello.txt" path = File.join(@wc_path, file) File.open(path, "w") {|f| f.print(before)} ctx = make_context(log) ctx.add(path) commit_info = ctx.commit(@wc_path) rev1 = commit_info.revision File.open(path, "w") {|f| f.print(after)} out_file = Tempfile.new("svn") err_file = Tempfile.new("svn") ctx.diff_peg([], path, rev1, "WORKING", out_file.path, err_file.path) out_file.open assert_match(/-#{before}\+#{after}\z/, out_file.read) commit_info = ctx.commit(@wc_path) rev2 = commit_info.revision out_file = Tempfile.new("svn") ctx.diff_peg([], path, rev1, rev2, out_file.path, err_file.path) out_file.open assert_match(/-#{before}\+#{after}\z/, out_file.read) end def test_diff_summarize log = "sample log" before = "before\n" after = "after\n" file = "hello.txt" path = File.join(@wc_path, file) File.open(path, "w") {|f| f.print(before)} ctx = make_context(log) ctx.add(path) commit_info = ctx.commit(@wc_path) rev1 = commit_info.revision File.open(path, "w") {|f| f.print(after)} commit_info = ctx.commit(@wc_path) rev2 = commit_info.revision diffs = [] ctx.diff_summarize(path, rev1, path, rev2) do |diff| diffs << diff end assert_equal([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 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) after_uri = "#{@repos_uri}/#{after_file}" File.open(before_path, "w") {|f| f.print(before)} ctx = make_context(log) 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(after_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 def test_merge log = "sample log" file = "sample.txt" src = "sample\n" trunk = File.join(@wc_path, "trunk") branch = File.join(@wc_path, "branch") trunk_path = File.join(trunk, file) branch_path = File.join(branch, file) ctx = make_context(log) 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 ctx.merge(branch, rev1, branch, rev2, trunk) rev3 = ctx.commit(@wc_path).revision assert_equal(src, ctx.cat(trunk_path, rev3)) ctx.rm(branch_path) rev4 = ctx.commit(@wc_path).revision ctx.merge(branch, rev3, branch, rev4, trunk) assert(!File.exist?(trunk_path)) ctx.revert(trunk_path) File.open(trunk_path, "a") {|f| f.print(src)} ctx.merge(branch, rev3, branch, rev4, trunk) assert(File.exist?(trunk_path)) rev5 = ctx.commit(@wc_path).revision File.open(trunk_path, "a") {|f| f.print(src)} ctx.merge(branch, rev3, branch, rev4, trunk, true, false, true, true) assert(File.exist?(trunk_path)) ctx.merge(branch, rev3, branch, rev4, trunk, true, false, true) rev6 = ctx.commit(@wc_path).revision assert(!File.exist?(trunk_path)) end def test_merge_peg log = "sample log" file = "sample.txt" src = "sample\n" trunk = File.join(@wc_path, "trunk") branch = File.join(@wc_path, "branch") trunk_path = File.join(trunk, file) branch_path = File.join(branch, file) ctx = make_context(log) 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 ctx.merge_peg(branch, rev1, rev2, trunk) rev3 = ctx.commit(@wc_path).revision assert_equal(src, ctx.cat(trunk_path, rev3)) ctx.rm(branch_path) rev4 = ctx.commit(@wc_path).revision ctx.merge_peg(branch, rev3, rev4, trunk) assert(!File.exist?(trunk_path)) ctx.revert(trunk_path) File.open(trunk_path, "a") {|f| f.print(src)} ctx.merge_peg(branch, rev3, rev4, trunk) assert(File.exist?(trunk_path)) rev5 = ctx.commit(@wc_path).revision File.open(trunk_path, "a") {|f| f.print(src)}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -