~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/bindings/swig/ruby/test/test_delta.rb

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require "util"
 
2
 
 
3
require "svn/info"
 
4
 
 
5
class SvnDeltaTest < Test::Unit::TestCase
 
6
  include SvnTestUtil
 
7
  
 
8
  def setup
 
9
    setup_basic
 
10
  end
 
11
 
 
12
  def teardown
 
13
    teardown_basic
 
14
  end
 
15
  
 
16
  def test_changed
 
17
    dir = "changed_dir"
 
18
    tmp_dir1 = "changed_tmp_dir1"
 
19
    tmp_dir2 = "changed_tmp_dir2"
 
20
    tmp_dir3 = "changed_tmp_dir3"
 
21
    dir_path = File.join(@wc_path, dir)
 
22
    tmp_dir1_path = File.join(@wc_path, tmp_dir1)
 
23
    tmp_dir2_path = File.join(@wc_path, tmp_dir2)
 
24
    tmp_dir3_path = File.join(dir_path, tmp_dir3)
 
25
    dir_svn_path = dir
 
26
    tmp_dir1_svn_path = tmp_dir1
 
27
    tmp_dir2_svn_path = tmp_dir2
 
28
    tmp_dir3_svn_path = [dir_svn_path, tmp_dir3].join("/")
 
29
 
 
30
    log = "added 3 dirs\nanded 5 files"
 
31
    ctx = make_context(log)
 
32
 
 
33
    ctx.mkdir([dir_path, tmp_dir1_path, tmp_dir2_path])
 
34
 
 
35
    file1 = "changed1.txt"
 
36
    file2 = "changed2.txt"
 
37
    file3 = "changed3.txt"
 
38
    file4 = "changed4.txt"
 
39
    file5 = "changed5.txt"
 
40
    file1_path = File.join(@wc_path, file1)
 
41
    file2_path = File.join(dir_path, file2)
 
42
    file3_path = File.join(@wc_path, file3)
 
43
    file4_path = File.join(dir_path, file4)
 
44
    file5_path = File.join(@wc_path, file5)
 
45
    file1_svn_path = file1
 
46
    file2_svn_path = [dir_svn_path, file2].join("/")
 
47
    file3_svn_path = file3
 
48
    file4_svn_path = [dir_svn_path, file4].join("/")
 
49
    file5_svn_path = file5
 
50
    FileUtils.touch(file1_path)
 
51
    FileUtils.touch(file2_path)
 
52
    FileUtils.touch(file3_path)
 
53
    FileUtils.touch(file4_path)
 
54
    FileUtils.touch(file5_path)
 
55
    ctx.add(file1_path)
 
56
    ctx.add(file2_path)
 
57
    ctx.add(file3_path)
 
58
    ctx.add(file4_path)
 
59
    ctx.add(file5_path)
 
60
 
 
61
    commit_info = ctx.commit(@wc_path)
 
62
    first_rev = commit_info.revision
 
63
 
 
64
    editor = traverse(Svn::Delta::ChangedEditor, commit_info.revision, true)
 
65
    assert_equal([
 
66
                   file1_svn_path, file2_svn_path,
 
67
                   file3_svn_path, file4_svn_path,
 
68
                   file5_svn_path,
 
69
                 ].sort,
 
70
                 editor.added_files)
 
71
    assert_equal([], editor.updated_files)
 
72
    assert_equal([], editor.deleted_files)
 
73
    assert_equal([].sort, editor.updated_dirs)
 
74
    assert_equal([].sort, editor.deleted_dirs)
 
75
    assert_equal([
 
76
                   "#{dir_svn_path}/",
 
77
                   "#{tmp_dir1_svn_path}/",
 
78
                   "#{tmp_dir2_svn_path}/"
 
79
                 ].sort,
 
80
                 editor.added_dirs)
 
81
 
 
82
    
 
83
    log = "deleted 2 dirs\nchanged 3 files\ndeleted 2 files\nadded 3 files"
 
84
    ctx = make_context(log)
 
85
    
 
86
    file6 = "changed6.txt"
 
87
    file7 = "changed7.txt"
 
88
    file8 = "changed8.txt"
 
89
    file9 = "changed9.txt"
 
90
    file6_path = File.join(dir_path, file6)
 
91
    file7_path = File.join(@wc_path, file7)
 
92
    file8_path = File.join(dir_path, file8)
 
93
    file9_path = File.join(dir_path, file9)
 
94
    file6_svn_path = [dir_svn_path, file6].join("/")
 
95
    file7_svn_path = file7
 
96
    file8_svn_path = [dir_svn_path, file8].join("/")
 
97
    file9_svn_path = [dir_svn_path, file9].join("/")
 
98
    
 
99
    File.open(file1_path, "w") {|f| f.puts "changed"}
 
100
    File.open(file2_path, "w") {|f| f.puts "changed"}
 
101
    File.open(file3_path, "w") {|f| f.puts "changed"}
 
102
    ctx.rm_f([file4_path, file5_path])
 
103
    FileUtils.touch(file6_path)
 
104
    FileUtils.touch(file7_path)
 
105
    FileUtils.touch(file8_path)
 
106
    ctx.add(file6_path)
 
107
    ctx.add(file7_path)
 
108
    ctx.add(file8_path)
 
109
    ctx.cp(file1_path, file9_path)
 
110
    ctx.rm(tmp_dir1_path)
 
111
    ctx.mv(tmp_dir2_path, tmp_dir3_path)
 
112
 
 
113
    commit_info = ctx.commit(@wc_path)
 
114
    second_rev = commit_info.revision
 
115
    
 
116
    editor = traverse(Svn::Delta::ChangedEditor, commit_info.revision, true)
 
117
    assert_equal([file1_svn_path, file2_svn_path, file3_svn_path].sort,
 
118
                 editor.updated_files)
 
119
    assert_equal([file4_svn_path, file5_svn_path].sort,
 
120
                 editor.deleted_files)
 
121
    assert_equal([file6_svn_path, file7_svn_path, file8_svn_path].sort,
 
122
                 editor.added_files)
 
123
    assert_equal([].sort, editor.updated_dirs)
 
124
    assert_equal([
 
125
                   [file9_svn_path, file1_svn_path, first_rev]
 
126
                 ].sort_by{|x| x[0]},
 
127
                 editor.copied_files)
 
128
    assert_equal([
 
129
                   ["#{tmp_dir3_svn_path}/", "#{tmp_dir2_svn_path}/", first_rev]
 
130
                 ].sort_by{|x| x[0]},
 
131
                 editor.copied_dirs)
 
132
    assert_equal(["#{tmp_dir1_svn_path}/", "#{tmp_dir2_svn_path}/"].sort,
 
133
                 editor.deleted_dirs)
 
134
    assert_equal([].sort, editor.added_dirs)
 
135
  end
 
136
 
 
137
  def test_change_prop
 
138
    prop_name = "prop"
 
139
    prop_value = "value"
 
140
    
 
141
    dir = "dir"
 
142
    dir_path = File.join(@wc_path, dir)
 
143
    dir_svn_path = dir
 
144
 
 
145
    log = "added 1 dirs\nanded 2 files"
 
146
    ctx = make_context(log)
 
147
 
 
148
    ctx.mkdir([dir_path])
 
149
 
 
150
    file1 = "file1.txt"
 
151
    file2 = "file2.txt"
 
152
    file1_path = File.join(@wc_path, file1)
 
153
    file2_path = File.join(dir_path, file2)
 
154
    file1_svn_path = file1
 
155
    file2_svn_path = [dir_svn_path, file2].join("/")
 
156
    FileUtils.touch(file1_path)
 
157
    FileUtils.touch(file2_path)
 
158
    ctx.add(file1_path)
 
159
    ctx.add(file2_path)
 
160
 
 
161
    ctx.propset(prop_name, prop_value, dir_path)
 
162
 
 
163
    commit_info = ctx.commit(@wc_path)
 
164
 
 
165
    editor = traverse(Svn::Delta::ChangedDirsEditor, commit_info.revision)
 
166
    assert_equal(["", dir_svn_path].collect{|path| "#{path}/"}.sort,
 
167
                 editor.changed_dirs)
 
168
 
 
169
    
 
170
    log = "prop changed"
 
171
    ctx = make_context(log)
 
172
    
 
173
    ctx.propdel(prop_name, dir_path)
 
174
 
 
175
    commit_info = ctx.commit(@wc_path)
 
176
 
 
177
    editor = traverse(Svn::Delta::ChangedDirsEditor, commit_info.revision)
 
178
    assert_equal([dir_svn_path].collect{|path| "#{path}/"}.sort,
 
179
                 editor.changed_dirs)
 
180
 
 
181
    
 
182
    ctx.propset(prop_name, prop_value, file1_path)
 
183
 
 
184
    commit_info = ctx.commit(@wc_path)
 
185
 
 
186
    editor = traverse(Svn::Delta::ChangedDirsEditor, commit_info.revision)
 
187
    assert_equal([""].collect{|path| "#{path}/"}.sort,
 
188
                 editor.changed_dirs)
 
189
 
 
190
 
 
191
    ctx.propdel(prop_name, file1_path)
 
192
    ctx.propset(prop_name, prop_value, file2_path)
 
193
 
 
194
    commit_info = ctx.commit(@wc_path)
 
195
 
 
196
    editor = traverse(Svn::Delta::ChangedDirsEditor, commit_info.revision)
 
197
    assert_equal(["", dir_svn_path].collect{|path| "#{path}/"}.sort,
 
198
                 editor.changed_dirs)
 
199
  end
 
200
  
 
201
  private
 
202
  def traverse(editor_class, rev, pass_root=false)
 
203
    root = @fs.root
 
204
    base_rev = rev - 1
 
205
    base_root = @fs.root(base_rev)
 
206
    if pass_root
 
207
      editor = editor_class.new(root, base_root)
 
208
    else
 
209
      editor = editor_class.new
 
210
    end
 
211
    base_root.editor = editor
 
212
    base_root.dir_delta("", "", root, "")
 
213
    editor
 
214
  end
 
215
end