5 class SvnInfoTest < Test::Unit::TestCase
18 path = File.join(@wc_path, file)
19 log = "test commit\nnew line"
22 ctx = make_context(log)
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)
36 dir_path = File.join(@wc_path, dir)
37 file_path = File.join(dir_path, file)
40 ctx = make_context(log)
42 FileUtils.touch(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)
54 tmp_dir = "changed_tmp_dir"
55 dir_path = File.join(@wc_path, dir)
56 tmp_dir_path = File.join(@wc_path, tmp_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)
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,
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)
126 ctx.cp(file1_path, file9_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,
135 assert_equal([file4_svn_path, file5_svn_path].sort,
137 assert_equal([file6_svn_path, file7_svn_path, file8_svn_path].sort,
139 assert_equal([].sort, info.updated_dirs)
141 [file9_svn_path, file1_svn_path, first_rev]
144 assert_equal([], info.copied_dirs)
145 assert_equal(["#{tmp_dir_svn_path}/"].sort, info.deleted_dirs)
146 assert_equal([].sort, info.added_dirs)
151 ctx = make_context(log)
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)
168 ctx.propset(file1_prop_key, file1_prop_value, file1_path)
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)
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)
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])
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"}
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)
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)
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))
282 ctx = make_context(log)
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}
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),
314 assert_equal(commit_info.revision, info.revision)
315 assert_equal(log, info.log)
318 def make_info(rev=nil)
319 Svn::Info.new(@repos_path, rev || @fs.youngest_rev)