* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
[svn.git] / subversion / bindings / swig / ruby / test / test_info.rb
blob03d17cb2e5fade88ef93e166ad86e4d5c83c4f86
1 require "util"
3 require "svn/info"
5 class SvnInfoTest < Test::Unit::TestCase
6   include SvnTestUtil
8   def setup
9     setup_basic
10   end
12   def teardown
13     teardown_basic
14   end
16   def test_info
17     file = "hello.txt"
18     path = File.join(@wc_path, file)
19     log = "test commit\nnew line"
20     FileUtils.touch(path)
22     ctx = make_context(log)
23     ctx.add(path)
24     commit_info = ctx.commit([@wc_path])
26     info = make_info(commit_info.revision)
27     assert_equal(@author, info.author)
28     assert_equal(commit_info.date, info.date)
29     assert_equal(commit_info.revision, info.revision)
30     assert_equal(log, info.log)
31   end
33   def test_dirs_changed
34     dir = "new_dir"
35     file = "new.txt"
36     dir_path = File.join(@wc_path, dir)
37     file_path = File.join(dir_path, file)
38     log = "added dir"
40     ctx = make_context(log)
41     ctx.mkdir(dir_path)
42     FileUtils.touch(file_path)
43     ctx.add(file_path)
44     commit_info = ctx.commit(@wc_path)
46     info = make_info(commit_info.revision)
47     assert_equal(["/", "#{dir}/"], info.changed_dirs)
48     assert_equal(commit_info.revision, info.revision)
49     assert_equal(log, info.log)
50   end
52   def test_changed
53     dir = "changed_dir"
54     tmp_dir = "changed_tmp_dir"
55     dir_path = File.join(@wc_path, dir)
56     tmp_dir_path = File.join(@wc_path, tmp_dir)
57     dir_svn_path = dir
58     tmp_dir_svn_path = tmp_dir
60     log = "added 2 dirs\nanded 5 files"
61     ctx = make_context(log)
63     ctx.mkdir([dir_path, tmp_dir_path])
65     file1 = "changed1.txt"
66     file2 = "changed2.txt"
67     file3 = "changed3.txt"
68     file4 = "changed4.txt"
69     file5 = "changed5.txt"
70     file1_path = File.join(@wc_path, file1)
71     file2_path = File.join(dir_path, file2)
72     file3_path = File.join(@wc_path, file3)
73     file4_path = File.join(dir_path, file4)
74     file5_path = File.join(@wc_path, file5)
75     file1_svn_path = file1
76     file2_svn_path = [dir_svn_path, file2].join("/")
77     file3_svn_path = file3
78     file4_svn_path = [dir_svn_path, file4].join("/")
79     file5_svn_path = file5
80     FileUtils.touch(file1_path)
81     FileUtils.touch(file2_path)
82     FileUtils.touch(file3_path)
83     FileUtils.touch(file4_path)
84     FileUtils.touch(file5_path)
85     ctx.add(file1_path)
86     ctx.add(file2_path)
87     ctx.add(file3_path)
88     ctx.add(file4_path)
89     ctx.add(file5_path)
91     commit_info = ctx.commit(@wc_path)
92     first_rev = commit_info.revision
94     info = make_info(commit_info.revision)
95     assert_equal([].sort, info.updated_dirs)
96     assert_equal([].sort, info.deleted_dirs)
97     assert_equal(["#{dir_svn_path}/", "#{tmp_dir_svn_path}/"].sort,
98                  info.added_dirs)
101     file6 = "changed6.txt"
102     file7 = "changed7.txt"
103     file8 = "changed8.txt"
104     file9 = "changed9.txt"
105     file6_path = File.join(dir_path, file6)
106     file7_path = File.join(@wc_path, file7)
107     file8_path = File.join(dir_path, file8)
108     file9_path = File.join(dir_path, file9)
109     file6_svn_path = [dir_svn_path, file6].join("/")
110     file7_svn_path = file7
111     file8_svn_path = [dir_svn_path, file8].join("/")
112     file9_svn_path = [dir_svn_path, file9].join("/")
113     File.open(file1_path, "w") {|f| f.puts "changed"}
114     File.open(file2_path, "w") {|f| f.puts "changed"}
115     File.open(file3_path, "w") {|f| f.puts "changed"}
117     log = "changed 3 files\ndeleted 2 files\nadded 3 files"
118     ctx = make_context(log)
119     ctx.rm_f([file4_path, file5_path])
120     FileUtils.touch(file6_path)
121     FileUtils.touch(file7_path)
122     FileUtils.touch(file8_path)
123     ctx.add(file6_path)
124     ctx.add(file7_path)
125     ctx.add(file8_path)
126     ctx.cp(file1_path, file9_path)
127     ctx.rm(tmp_dir_path)
129     commit_info = ctx.commit(@wc_path)
130     second_rev = commit_info.revision
132     info = make_info(commit_info.revision)
133     assert_equal([file1_svn_path, file2_svn_path, file3_svn_path].sort,
134                  info.updated_files)
135     assert_equal([file4_svn_path, file5_svn_path].sort,
136                  info.deleted_files)
137     assert_equal([file6_svn_path, file7_svn_path, file8_svn_path].sort,
138                  info.added_files)
139     assert_equal([].sort, info.updated_dirs)
140     assert_equal([
141                    [file9_svn_path, file1_svn_path, first_rev]
142                  ].sort_by{|x| x[0]},
143                  info.copied_files)
144     assert_equal([], info.copied_dirs)
145     assert_equal(["#{tmp_dir_svn_path}/"].sort, info.deleted_dirs)
146     assert_equal([].sort, info.added_dirs)
147   end
149   def test_diff
150     log = "diff"
151     ctx = make_context(log)
153     file1 = "diff1.txt"
154     file2 = "diff2.txt"
155     file3 = "diff3.txt"
156     file1_path = File.join(@wc_path, "diff1.txt")
157     file2_path = File.join(@wc_path, "diff2.txt")
158     file3_path = File.join(@wc_path, "diff3.txt")
159     file1_prop_key = "AAA"
160     file1_prop_value = "BBB"
161     FileUtils.touch(file1_path)
162     File.open(file2_path, "w") {|f| f.puts "changed"}
163     FileUtils.touch(file3_path)
165     ctx.add(file1_path)
166     ctx.add(file2_path)
167     ctx.add(file3_path)
168     ctx.propset(file1_prop_key, file1_prop_value, file1_path)
170     ctx.commit(@wc_path)
172     file4 = "diff4.txt"
173     file5 = "diff5.txt"
174     file4_path = File.join(@wc_path, file4)
175     file5_path = File.join(@wc_path, file5)
176     file4_prop_key = "XXX"
177     file4_prop_value = "YYY"
178     File.open(file1_path, "w") {|f| f.puts "changed"}
179     File.open(file2_path, "wb") {|f| f.puts "removed\nadded"}
180     FileUtils.touch(file4_path)
181     ctx.add(file4_path)
182     ctx.propdel(file1_prop_key, file1_path)
183     ctx.propset(file4_prop_key, file4_prop_value, file4_path)
184     ctx.cp(file3_path, file5_path)
186     commit_info = ctx.commit(@wc_path)
188     info = make_info(commit_info.revision)
189     keys = info.diffs.keys.sort
190     file5_key = keys.last
191     assert_equal(4, info.diffs.size)
192     assert_equal([file1, file2, file4].sort, keys[0..-2])
193     assert_match(/\A#{file5}/, file5_key)
194     assert(info.diffs[file1].has_key?(:modified))
195     assert(info.diffs[file1].has_key?(:property_changed))
196     assert(info.diffs[file2].has_key?(:modified))
197     assert(info.diffs[file4].has_key?(:added))
198     assert(info.diffs[file4].has_key?(:property_changed))
199     assert(info.diffs[file5_key].has_key?(:copied))
200     assert_equal(1, info.diffs[file1][:modified].added_line)
201     assert_equal(0, info.diffs[file1][:modified].deleted_line)
202     assert_equal(2, info.diffs[file2][:modified].added_line)
203     assert_equal(1, info.diffs[file2][:modified].deleted_line)
204     assert_equal(0, info.diffs[file4][:added].added_line)
205     assert_equal(0, info.diffs[file4][:added].deleted_line)
206     assert_equal(0, info.diffs[file5_key][:copied].added_line)
207     assert_equal(0, info.diffs[file5_key][:copied].deleted_line)
208     assert_equal("Name: #{file1_prop_key}\n   - #{file1_prop_value}\n",
209                  info.diffs[file1][:property_changed].body)
210     assert_equal("Name: #{file4_prop_key}\n   + #{file4_prop_value}\n",
211                  info.diffs[file4][:property_changed].body)
212     assert_equal(commit_info.revision, info.revision)
213     assert_equal(log, info.log)
214   end
216   def test_diff_path
217     log = "diff path"
218     ctx = make_context(log)
220     parent_dir = "parent_dir"
221     child_dir = "child_dir"
222     parent_dir_path = File.join(@wc_path, parent_dir)
223     child_dir_path = File.join(parent_dir_path, child_dir)
224     parent_dir_svn_path = parent_dir
225     child_dir_svn_path = [parent_dir, child_dir].join("/")
227     ctx.mkdir([parent_dir_path, child_dir_path])
229     file1 = "diff1.txt"
230     file2 = "diff2.txt"
231     file1_path = File.join(@wc_path, file1)
232     file2_path = File.join(child_dir_path, file2)
233     file1_svn_path = file1
234     file2_svn_path = [child_dir_svn_path, file2].join("/")
235     File.open(file1_path, "w") {|f| f.puts "new"}
236     File.open(file2_path, "w") {|f| f.puts "deep"}
237     ctx.add(file1_path)
238     ctx.add(file2_path)
240     commit_info = ctx.commit(@wc_path)
242     info = make_info(commit_info.revision)
243     assert_equal(2, info.diffs.size)
244     assert(info.diffs.has_key?(file1_svn_path))
245     assert(info.diffs.has_key?(file2_svn_path))
246     assert(info.diffs[file1_svn_path].has_key?(:added))
247     assert(info.diffs[file2_svn_path].has_key?(:added))
248     assert_equal(1, info.diffs[file1_svn_path][:added].added_line)
249     assert_equal(0, info.diffs[file1_svn_path][:added].deleted_line)
250     assert_equal(1, info.diffs[file2_svn_path][:added].added_line)
251     assert_equal(0, info.diffs[file2_svn_path][:added].deleted_line)
254     file3 = "diff3.txt"
255     file4 = "diff4.txt"
256     file3_path = File.join(parent_dir_path, file3)
257     file4_path = File.join(child_dir_path, file4)
258     file3_svn_path = [parent_dir_svn_path, file3].join("/")
259     file4_svn_path = [child_dir_svn_path, file4].join("/")
261     ctx.mv(file2_path, file3_path)
262     ctx.mv(file1_path, file4_path)
264     commit_info = ctx.commit(@wc_path)
266     info = make_info(commit_info.revision)
267     assert_equal([
268                    file1_svn_path,
269                    file2_svn_path,
270                    file3_svn_path,
271                    file4_svn_path,
272                  ].sort,
273                  info.diffs.keys.sort)
274     assert(info.diffs[file1_svn_path].has_key?(:deleted))
275     assert(info.diffs[file2_svn_path].has_key?(:deleted))
276     assert(info.diffs[file3_svn_path].has_key?(:copied))
277     assert(info.diffs[file4_svn_path].has_key?(:copied))
278   end
280   def test_sha256
281     log = "sha256"
282     ctx = make_context(log)
284     file1 = "diff1.txt"
285     file2 = "diff2.txt"
286     file3 = "diff3.txt"
287     file1_path = File.join(@wc_path, "diff1.txt")
288     file2_path = File.join(@wc_path, "diff2.txt")
289     file3_path = File.join(@wc_path, "diff3.txt")
290     file1_content = file1
291     file2_content = file2
292     file3_content = file3
293     all_content = [file1, file2, file3].sort.join("")
294     File.open(file1_path, "w") {|f| f.print file1_content}
295     File.open(file2_path, "w") {|f| f.print file2_content}
296     File.open(file3_path, "w") {|f| f.print file3_content}
298     ctx.add(file1_path)
299     ctx.add(file2_path)
300     ctx.add(file3_path)
302     commit_info = ctx.commit(@wc_path)
304     info = make_info(commit_info.revision)
305     assert_equal(3, info.sha256.size)
306     assert_equal(Digest::SHA256.hexdigest(file1_content),
307                  info.sha256[file1][:sha256])
308     assert_equal(Digest::SHA256.hexdigest(file2_content),
309                  info.sha256[file2][:sha256])
310     assert_equal(Digest::SHA256.hexdigest(file3_content),
311                  info.sha256[file3][:sha256])
312     assert_equal(Digest::SHA256.hexdigest(all_content),
313                  info.entire_sha256)
314     assert_equal(commit_info.revision, info.revision)
315     assert_equal(log, info.log)
316   end
318   def make_info(rev=nil)
319     Svn::Info.new(@repos_path, rev || @fs.youngest_rev)
320   end