@@ -1,352 +1,353 | |||
|
1 | 1 | require File.expand_path('../../../../../../test_helper', __FILE__) |
|
2 | 2 | begin |
|
3 | 3 | require 'mocha' |
|
4 | 4 | |
|
5 | 5 | class MercurialAdapterTest < ActiveSupport::TestCase |
|
6 | 6 | |
|
7 | 7 | HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR |
|
8 | 8 | TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME |
|
9 | 9 | TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION |
|
10 | 10 | |
|
11 |
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + |
|
|
11 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + | |
|
12 | '/tmp/test/mercurial_repository' | |
|
12 | 13 | |
|
13 | 14 | CHAR_1_HEX = "\xc3\x9c" |
|
14 | 15 | |
|
15 | 16 | if File.directory?(REPOSITORY_PATH) |
|
16 | 17 | def setup |
|
17 | 18 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new( |
|
18 | 19 | REPOSITORY_PATH, |
|
19 | 20 | nil, |
|
20 | 21 | nil, |
|
21 | 22 | nil, |
|
22 | 23 | 'ISO-8859-1') |
|
23 | 24 | @diff_c_support = true |
|
24 | 25 | |
|
25 | 26 | @char_1 = CHAR_1_HEX.dup |
|
26 | 27 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
27 | 28 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
28 | 29 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
29 | 30 | if @tag_char_1.respond_to?(:force_encoding) |
|
30 | 31 | @char_1.force_encoding('UTF-8') |
|
31 | 32 | @tag_char_1.force_encoding('UTF-8') |
|
32 | 33 | @branch_char_0.force_encoding('UTF-8') |
|
33 | 34 | @branch_char_1.force_encoding('UTF-8') |
|
34 | 35 | end |
|
35 | 36 | end |
|
36 | 37 | |
|
37 | 38 | def test_hgversion |
|
38 | 39 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], |
|
39 | 40 | "Mercurial Distributed SCM (1.0)\n" => [1,0], |
|
40 | 41 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, |
|
41 | 42 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], |
|
42 | 43 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, |
|
43 | 44 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], |
|
44 | 45 | "(1.6)\n(1.7)\n(1.8)" => [1,6], |
|
45 | 46 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} |
|
46 | 47 | |
|
47 | 48 | to_test.each do |s, v| |
|
48 | 49 | test_hgversion_for(s, v) |
|
49 | 50 | end |
|
50 | 51 | end |
|
51 | 52 | |
|
52 | 53 | def test_template_path |
|
53 | 54 | to_test = { [0,9,5] => "0.9.5", |
|
54 | 55 | [1,0] => "1.0", |
|
55 | 56 | [] => "1.0", |
|
56 | 57 | [1,0,1] => "1.0", |
|
57 | 58 | [1,7] => "1.0", |
|
58 | 59 | [1,7,1] => "1.0" } |
|
59 | 60 | to_test.each do |v, template| |
|
60 | 61 | test_template_path_for(v, template) |
|
61 | 62 | end |
|
62 | 63 | end |
|
63 | 64 | |
|
64 | 65 | def test_info |
|
65 | 66 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", |
|
66 | 67 | REPOSITORY_PATH + "//"].each do |repo| |
|
67 | 68 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) |
|
68 | 69 | repo_path = adp.info.root_url.gsub(/\\/, "/") |
|
69 | 70 | assert_equal REPOSITORY_PATH, repo_path |
|
70 | 71 | assert_equal '28', adp.info.lastrev.revision |
|
71 | 72 | assert_equal '3ae45e2d177d',adp.info.lastrev.scmid |
|
72 | 73 | end |
|
73 | 74 | end |
|
74 | 75 | |
|
75 | 76 | def test_revisions |
|
76 | 77 | revisions = @adapter.revisions(nil, 2, 4) |
|
77 | 78 | assert_equal 3, revisions.size |
|
78 | 79 | assert_equal '2', revisions[0].revision |
|
79 | 80 | assert_equal '400bb8672109', revisions[0].scmid |
|
80 | 81 | assert_equal '4', revisions[2].revision |
|
81 | 82 | assert_equal 'def6d2f1254a', revisions[2].scmid |
|
82 | 83 | |
|
83 | 84 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) |
|
84 | 85 | assert_equal 2, revisions.size |
|
85 | 86 | assert_equal '2', revisions[0].revision |
|
86 | 87 | assert_equal '400bb8672109', revisions[0].scmid |
|
87 | 88 | end |
|
88 | 89 | |
|
89 | 90 | def test_diff |
|
90 | 91 | if @adapter.class.client_version_above?([1, 2]) |
|
91 | 92 | assert_nil @adapter.diff(nil, '100000') |
|
92 | 93 | end |
|
93 | 94 | assert_nil @adapter.diff(nil, '100000', '200000') |
|
94 | 95 | [2, '400bb8672109', '400', 400].each do |r1| |
|
95 | 96 | diff1 = @adapter.diff(nil, r1) |
|
96 | 97 | if @diff_c_support |
|
97 | 98 | assert_equal 28, diff1.size |
|
98 | 99 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") |
|
99 | 100 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf |
|
100 | 101 | else |
|
101 | 102 | assert_equal 0, diff1.size |
|
102 | 103 | end |
|
103 | 104 | [4, 'def6d2f1254a'].each do |r2| |
|
104 | 105 | diff2 = @adapter.diff(nil,r1,r2) |
|
105 | 106 | assert_equal 49, diff2.size |
|
106 | 107 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") |
|
107 | 108 | assert_equal "+class WelcomeController < ApplicationController", buf |
|
108 | 109 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) |
|
109 | 110 | assert_equal 20, diff3.size |
|
110 | 111 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") |
|
111 | 112 | assert_equal "+ @watched.remove_watcher(user)", buf |
|
112 | 113 | end |
|
113 | 114 | end |
|
114 | 115 | end |
|
115 | 116 | |
|
116 | 117 | def test_diff_made_by_revision |
|
117 | 118 | if @diff_c_support |
|
118 | 119 | [24, '24', '4cddb4e45f52'].each do |r1| |
|
119 | 120 | diff1 = @adapter.diff(nil, r1) |
|
120 | 121 | assert_equal 5, diff1.size |
|
121 | 122 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") |
|
122 | 123 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf |
|
123 | 124 | end |
|
124 | 125 | end |
|
125 | 126 | end |
|
126 | 127 | |
|
127 | 128 | def test_cat |
|
128 | 129 | [2, '400bb8672109', '400', 400].each do |r| |
|
129 | 130 | buf = @adapter.cat('sources/welcome_controller.rb', r) |
|
130 | 131 | assert buf |
|
131 | 132 | lines = buf.split("\r\n") |
|
132 | 133 | assert_equal 25, lines.length |
|
133 | 134 | assert_equal 'class WelcomeController < ApplicationController', lines[17] |
|
134 | 135 | end |
|
135 | 136 | assert_nil @adapter.cat('sources/welcome_controller.rb') |
|
136 | 137 | end |
|
137 | 138 | |
|
138 | 139 | def test_annotate |
|
139 | 140 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines |
|
140 | 141 | [2, '400bb8672109', '400', 400].each do |r| |
|
141 | 142 | ann = @adapter.annotate('sources/welcome_controller.rb', r) |
|
142 | 143 | assert ann |
|
143 | 144 | assert_equal '1', ann.revisions[17].revision |
|
144 | 145 | assert_equal '9d5b5b004199', ann.revisions[17].identifier |
|
145 | 146 | assert_equal 'jsmith', ann.revisions[0].author |
|
146 | 147 | assert_equal 25, ann.lines.length |
|
147 | 148 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] |
|
148 | 149 | end |
|
149 | 150 | end |
|
150 | 151 | |
|
151 | 152 | def test_entries |
|
152 | 153 | assert_nil @adapter.entries(nil, '100000') |
|
153 | 154 | |
|
154 | 155 | assert_equal 1, @adapter.entries("sources", 3).size |
|
155 | 156 | assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size |
|
156 | 157 | |
|
157 | 158 | [2, '400bb8672109', '400', 400].each do |r| |
|
158 | 159 | entries1 = @adapter.entries(nil, r) |
|
159 | 160 | assert entries1 |
|
160 | 161 | assert_equal 3, entries1.size |
|
161 | 162 | assert_equal 'sources', entries1[1].name |
|
162 | 163 | assert_equal 'sources', entries1[1].path |
|
163 | 164 | assert_equal 'dir', entries1[1].kind |
|
164 | 165 | readme = entries1[2] |
|
165 | 166 | assert_equal 'README', readme.name |
|
166 | 167 | assert_equal 'README', readme.path |
|
167 | 168 | assert_equal 'file', readme.kind |
|
168 | 169 | assert_equal 27, readme.size |
|
169 | 170 | assert_equal '1', readme.lastrev.revision |
|
170 | 171 | assert_equal '9d5b5b004199', readme.lastrev.identifier |
|
171 | 172 | # 2007-12-14 10:24:01 +0100 |
|
172 | 173 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time |
|
173 | 174 | |
|
174 | 175 | entries2 = @adapter.entries('sources', r) |
|
175 | 176 | assert entries2 |
|
176 | 177 | assert_equal 2, entries2.size |
|
177 | 178 | assert_equal 'watchers_controller.rb', entries2[0].name |
|
178 | 179 | assert_equal 'sources/watchers_controller.rb', entries2[0].path |
|
179 | 180 | assert_equal 'file', entries2[0].kind |
|
180 | 181 | assert_equal 'welcome_controller.rb', entries2[1].name |
|
181 | 182 | assert_equal 'sources/welcome_controller.rb', entries2[1].path |
|
182 | 183 | assert_equal 'file', entries2[1].kind |
|
183 | 184 | end |
|
184 | 185 | end |
|
185 | 186 | |
|
186 | 187 | def test_entries_tag |
|
187 | 188 | entries1 = @adapter.entries(nil, 'tag_test.00') |
|
188 | 189 | assert entries1 |
|
189 | 190 | assert_equal 3, entries1.size |
|
190 | 191 | assert_equal 'sources', entries1[1].name |
|
191 | 192 | assert_equal 'sources', entries1[1].path |
|
192 | 193 | assert_equal 'dir', entries1[1].kind |
|
193 | 194 | readme = entries1[2] |
|
194 | 195 | assert_equal 'README', readme.name |
|
195 | 196 | assert_equal 'README', readme.path |
|
196 | 197 | assert_equal 'file', readme.kind |
|
197 | 198 | assert_equal 21, readme.size |
|
198 | 199 | assert_equal '0', readme.lastrev.revision |
|
199 | 200 | assert_equal '0885933ad4f6', readme.lastrev.identifier |
|
200 | 201 | # 2007-12-14 10:22:52 +0100 |
|
201 | 202 | assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time |
|
202 | 203 | end |
|
203 | 204 | |
|
204 | 205 | def test_entries_branch |
|
205 | 206 | entries1 = @adapter.entries(nil, 'test-branch-00') |
|
206 | 207 | assert entries1 |
|
207 | 208 | assert_equal 5, entries1.size |
|
208 | 209 | assert_equal 'sql_escape', entries1[2].name |
|
209 | 210 | assert_equal 'sql_escape', entries1[2].path |
|
210 | 211 | assert_equal 'dir', entries1[2].kind |
|
211 | 212 | readme = entries1[4] |
|
212 | 213 | assert_equal 'README', readme.name |
|
213 | 214 | assert_equal 'README', readme.path |
|
214 | 215 | assert_equal 'file', readme.kind |
|
215 | 216 | assert_equal 365, readme.size |
|
216 | 217 | assert_equal '8', readme.lastrev.revision |
|
217 | 218 | assert_equal 'c51f5bb613cd', readme.lastrev.identifier |
|
218 | 219 | # 2001-02-01 00:00:00 -0900 |
|
219 | 220 | assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time |
|
220 | 221 | end |
|
221 | 222 | |
|
222 | 223 | def test_locate_on_outdated_repository |
|
223 | 224 | assert_equal 1, @adapter.entries("images", 0).size |
|
224 | 225 | assert_equal 2, @adapter.entries("images").size |
|
225 | 226 | assert_equal 2, @adapter.entries("images", 2).size |
|
226 | 227 | end |
|
227 | 228 | |
|
228 | 229 | def test_access_by_nodeid |
|
229 | 230 | path = 'sources/welcome_controller.rb' |
|
230 | 231 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') |
|
231 | 232 | end |
|
232 | 233 | |
|
233 | 234 | def test_access_by_fuzzy_nodeid |
|
234 | 235 | path = 'sources/welcome_controller.rb' |
|
235 | 236 | # falls back to nodeid |
|
236 | 237 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') |
|
237 | 238 | end |
|
238 | 239 | |
|
239 | 240 | def test_tags |
|
240 | 241 | assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags |
|
241 | 242 | end |
|
242 | 243 | |
|
243 | 244 | def test_tagmap |
|
244 | 245 | tm = { |
|
245 | 246 | @tag_char_1 => 'adf805632193', |
|
246 | 247 | 'tag_test.00' => '6987191f453a', |
|
247 | 248 | 'tag-init-revision' => '0885933ad4f6', |
|
248 | 249 | } |
|
249 | 250 | assert_equal tm, @adapter.tagmap |
|
250 | 251 | end |
|
251 | 252 | |
|
252 | 253 | def test_branches |
|
253 | 254 | assert_equal [ |
|
254 | 255 | 'default', |
|
255 | 256 | @branch_char_1, |
|
256 | 257 | 'branch (1)[2]&,%.-3_4', |
|
257 | 258 | @branch_char_0, |
|
258 | 259 | 'test_branch.latin-1', |
|
259 | 260 | 'test-branch-00', |
|
260 | 261 | ], @adapter.branches |
|
261 | 262 | end |
|
262 | 263 | |
|
263 | 264 | def test_branchmap |
|
264 | 265 | bm = { |
|
265 | 266 | 'default' => '3ae45e2d177d', |
|
266 | 267 | 'test_branch.latin-1' => 'c2ffe7da686a', |
|
267 | 268 | 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7', |
|
268 | 269 | 'test-branch-00' => '3a330eb32958', |
|
269 | 270 | @branch_char_0 => 'c8d3e4887474', |
|
270 | 271 | @branch_char_1 => '7bbf4c738e71', |
|
271 | 272 | } |
|
272 | 273 | assert_equal bm, @adapter.branchmap |
|
273 | 274 | end |
|
274 | 275 | |
|
275 | 276 | def test_path_space |
|
276 | 277 | p = 'README (1)[2]&,%.-3_4' |
|
277 | 278 | [15, '933ca60293d7'].each do |r1| |
|
278 | 279 | assert @adapter.diff(p, r1) |
|
279 | 280 | assert @adapter.cat(p, r1) |
|
280 | 281 | assert_equal 1, @adapter.annotate(p, r1).lines.length |
|
281 | 282 | [25, 'afc61e85bde7'].each do |r2| |
|
282 | 283 | assert @adapter.diff(p, r1, r2) |
|
283 | 284 | end |
|
284 | 285 | end |
|
285 | 286 | end |
|
286 | 287 | |
|
287 | 288 | def test_tag_non_ascii |
|
288 | 289 | p = "latin-1-dir/test-#{@char_1}-1.txt" |
|
289 | 290 | assert @adapter.cat(p, @tag_char_1) |
|
290 | 291 | assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length |
|
291 | 292 | end |
|
292 | 293 | |
|
293 | 294 | def test_branch_non_ascii |
|
294 | 295 | p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt" |
|
295 | 296 | assert @adapter.cat(p, @branch_char_1) |
|
296 | 297 | assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length |
|
297 | 298 | end |
|
298 | 299 | |
|
299 | 300 | def test_nodes_in_branch |
|
300 | 301 | [ |
|
301 | 302 | 'default', |
|
302 | 303 | @branch_char_1, |
|
303 | 304 | 'branch (1)[2]&,%.-3_4', |
|
304 | 305 | @branch_char_0, |
|
305 | 306 | 'test_branch.latin-1', |
|
306 | 307 | 'test-branch-00', |
|
307 | 308 | ].each do |bra| |
|
308 | 309 | nib0 = @adapter.nodes_in_branch(bra) |
|
309 | 310 | assert nib0 |
|
310 | 311 | nib1 = @adapter.nodes_in_branch(bra, :limit => 1) |
|
311 | 312 | assert_equal 1, nib1.size |
|
312 | 313 | case bra |
|
313 | 314 | when 'branch (1)[2]&,%.-3_4' |
|
314 | 315 | assert_equal 3, nib0.size |
|
315 | 316 | assert_equal nib0[0], 'afc61e85bde7' |
|
316 | 317 | nib2 = @adapter.nodes_in_branch(bra, :limit => 2) |
|
317 | 318 | assert_equal 2, nib2.size |
|
318 | 319 | assert_equal nib2[1], '933ca60293d7' |
|
319 | 320 | when @branch_char_1 |
|
320 | 321 | assert_equal 2, nib0.size |
|
321 | 322 | assert_equal nib0[1], '08ff3227303e' |
|
322 | 323 | nib2 = @adapter.nodes_in_branch(bra, :limit => 1) |
|
323 | 324 | assert_equal 1, nib2.size |
|
324 | 325 | assert_equal nib2[0], '7bbf4c738e71' |
|
325 | 326 | end |
|
326 | 327 | end |
|
327 | 328 | end |
|
328 | 329 | |
|
329 | 330 | private |
|
330 | 331 | |
|
331 | 332 | def test_hgversion_for(hgversion, version) |
|
332 | 333 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) |
|
333 | 334 | assert_equal version, @adapter.class.hgversion |
|
334 | 335 | end |
|
335 | 336 | |
|
336 | 337 | def test_template_path_for(version, template) |
|
337 | 338 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", |
|
338 | 339 | @adapter.class.template_path_for(version) |
|
339 | 340 | assert File.exist?(@adapter.class.template_path_for(version)) |
|
340 | 341 | end |
|
341 | 342 | else |
|
342 | 343 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
343 | 344 | def test_fake; assert true end |
|
344 | 345 | end |
|
345 | 346 | end |
|
346 | 347 | |
|
347 | 348 | rescue LoadError |
|
348 | 349 | class MercurialMochaFake < ActiveSupport::TestCase |
|
349 | 350 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
350 | 351 | end |
|
351 | 352 | end |
|
352 | 353 |
General Comments 0
You need to be logged in to leave comments.
Login now