##// END OF EJS Templates
scm: mercurial: use scmid_for_assert in assert_entry (#14361)...
Toshi MARUYAMA -
r12498:642f13605ecb
parent child
Show More
@@ -1,528 +1,530
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoryMercurialTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
26 26 NUM_REV = 32
27 27 CHAR_1_HEX = "\xc3\x9c"
28 28
29 29 def setup
30 30 @project = Project.find(3)
31 31 @repository = Repository::Mercurial.create(
32 32 :project => @project,
33 33 :url => REPOSITORY_PATH,
34 34 :path_encoding => 'ISO-8859-1'
35 35 )
36 36 assert @repository
37 37 @char_1 = CHAR_1_HEX.dup
38 38 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
39 39 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
40 40 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
41 41 if @char_1.respond_to?(:force_encoding)
42 42 @char_1.force_encoding('UTF-8')
43 43 @tag_char_1.force_encoding('UTF-8')
44 44 @branch_char_0.force_encoding('UTF-8')
45 45 @branch_char_1.force_encoding('UTF-8')
46 46 end
47 47 end
48 48
49 49 def test_blank_path_to_repository_error_message
50 50 set_language_if_valid 'en'
51 51 repo = Repository::Mercurial.new(
52 52 :project => @project,
53 53 :identifier => 'test'
54 54 )
55 55 assert !repo.save
56 56 assert_include "Path to repository can't be blank",
57 57 repo.errors.full_messages
58 58 end
59 59
60 60 def test_blank_path_to_repository_error_message_fr
61 61 set_language_if_valid 'fr'
62 62 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
63 63 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
64 64 repo = Repository::Mercurial.new(
65 65 :project => @project,
66 66 :url => "",
67 67 :identifier => 'test',
68 68 :path_encoding => ''
69 69 )
70 70 assert !repo.save
71 71 assert_include str, repo.errors.full_messages
72 72 end
73 73
74 74 if File.directory?(REPOSITORY_PATH)
75 75 def test_scm_available
76 76 klass = Repository::Mercurial
77 77 assert_equal "Mercurial", klass.scm_name
78 78 assert klass.scm_adapter_class
79 79 assert_not_equal "", klass.scm_command
80 80 assert_equal true, klass.scm_available
81 81 end
82 82
83 83 def test_entries_on_tip
84 84 entries = @repository.entries
85 85 assert_kind_of Redmine::Scm::Adapters::Entries, entries
86 86 end
87 87
88 88 def assert_entries
89 89 [2, '400bb8672109', '400', 400].each do |r|
90 90 entries1 = @repository.entries(nil, r)
91 91 assert entries1
92 92 assert_kind_of Redmine::Scm::Adapters::Entries, entries1
93 93 assert_equal 3, entries1.size
94 94 readme = entries1[2]
95 95 assert_equal '1', readme.lastrev.revision
96 96 assert_equal '9d5b5b004199', readme.lastrev.identifier
97 97 assert_equal '1', readme.changeset.revision
98 98 assert_equal '9d5b5b004199', readme.changeset.scmid
99 99 end
100 100 end
101 101 private :assert_entries
102 102
103 103 def test_entries_short_id
104 104 assert_equal 0, @repository.changesets.count
105 105 @repository.fetch_changesets
106 106 @project.reload
107 107 assert_equal NUM_REV, @repository.changesets.count
108 108 assert_entries
109 109 end
110 110
111 111 def test_entry_on_tip
112 112 entry = @repository.entry
113 113 assert_kind_of Redmine::Scm::Adapters::Entry, entry
114 114 assert_equal "", entry.path
115 115 assert_equal 'dir', entry.kind
116 116 end
117 117
118 def assert_entry
118 def assert_entry(is_short_scmid=true)
119 hex = "0885933ad4f68d77c2649cd11f8311276e7ef7ce"
120 scmid = scmid_for_assert(hex, is_short_scmid)
119 121 ["README", "/README"].each do |path|
120 122 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
121 123 entry = @repository.entry(path, rev)
122 124 assert_kind_of Redmine::Scm::Adapters::Entry, entry
123 125 assert_equal "README", entry.path
124 126 assert_equal "file", entry.kind
125 127 assert_equal '0', entry.lastrev.revision
126 assert_equal '0885933ad4f6', entry.lastrev.identifier
128 assert_equal scmid, entry.lastrev.identifier
127 129 end
128 130 end
129 131 ["sources", "/sources", "/sources/"].each do |path|
130 132 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
131 133 entry = @repository.entry(path, rev)
132 134 assert_kind_of Redmine::Scm::Adapters::Entry, entry
133 135 assert_equal "sources", entry.path
134 136 assert_equal "dir", entry.kind
135 137 end
136 138 end
137 139 ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
138 140 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
139 141 entry = @repository.entry(path, rev)
140 142 assert_kind_of Redmine::Scm::Adapters::Entry, entry
141 143 assert_equal "sources/watchers_controller.rb", entry.path
142 144 assert_equal "file", entry.kind
143 145 assert_equal '0', entry.lastrev.revision
144 assert_equal '0885933ad4f6', entry.lastrev.identifier
146 assert_equal scmid, entry.lastrev.identifier
145 147 end
146 148 end
147 149 end
148 150 private :assert_entry
149 151
150 152 def test_entry_short_id
151 assert_entry
153 assert_entry(true)
152 154 end
153 155
154 156 def test_fetch_changesets_from_scratch
155 157 assert_equal 0, @repository.changesets.count
156 158 @repository.fetch_changesets
157 159 @project.reload
158 160 assert_equal NUM_REV, @repository.changesets.count
159 161 assert_equal 46, @repository.filechanges.count
160 162 rev0 = @repository.changesets.find_by_revision('0')
161 163 assert_equal "Initial import.\nThe repository contains 3 files.",
162 164 rev0.comments
163 165 assert_equal "0885933ad4f6", rev0.scmid
164 166 end
165 167
166 168 def test_fetch_changesets_incremental
167 169 assert_equal 0, @repository.changesets.count
168 170 @repository.fetch_changesets
169 171 @project.reload
170 172 assert_equal NUM_REV, @repository.changesets.count
171 173 # Remove changesets with revision > 2
172 174 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
173 175 @project.reload
174 176 @repository.reload
175 177 assert_equal 3, @repository.changesets.count
176 178
177 179 @repository.fetch_changesets
178 180 @project.reload
179 181 assert_equal NUM_REV, @repository.changesets.count
180 182 end
181 183
182 184 def test_isodatesec
183 185 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
184 186 if @repository.scm.class.client_version_above?([1, 0])
185 187 assert_equal 0, @repository.changesets.count
186 188 @repository.fetch_changesets
187 189 @project.reload
188 190 assert_equal NUM_REV, @repository.changesets.count
189 191 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
190 192 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
191 193 end
192 194 end
193 195
194 196 def test_changeset_order_by_revision
195 197 assert_equal 0, @repository.changesets.count
196 198 @repository.fetch_changesets
197 199 @project.reload
198 200 assert_equal NUM_REV, @repository.changesets.count
199 201
200 202 c0 = @repository.latest_changeset
201 203 c1 = @repository.changesets.find_by_revision('0')
202 204 # sorted by revision (id), not by date
203 205 assert c0.revision.to_i > c1.revision.to_i
204 206 assert c0.committed_on < c1.committed_on
205 207 end
206 208
207 209 def test_latest_changesets
208 210 assert_equal 0, @repository.changesets.count
209 211 @repository.fetch_changesets
210 212 @project.reload
211 213 assert_equal NUM_REV, @repository.changesets.count
212 214
213 215 # with_limit
214 216 changesets = @repository.latest_changesets('', nil, 2)
215 217 assert_equal %w|31 30|, changesets.collect(&:revision)
216 218
217 219 # with_filepath
218 220 changesets = @repository.latest_changesets(
219 221 '/sql_escape/percent%dir/percent%file1.txt', nil)
220 222 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
221 223
222 224 changesets = @repository.latest_changesets(
223 225 '/sql_escape/underscore_dir/understrike_file.txt', nil)
224 226 assert_equal %w|30 12 9|, changesets.collect(&:revision)
225 227
226 228 changesets = @repository.latest_changesets('README', nil)
227 229 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
228 230
229 231 changesets = @repository.latest_changesets('README','8')
230 232 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
231 233
232 234 changesets = @repository.latest_changesets('README','8', 2)
233 235 assert_equal %w|8 6|, changesets.collect(&:revision)
234 236
235 237 # with_dirpath
236 238 changesets = @repository.latest_changesets('images', nil)
237 239 assert_equal %w|1 0|, changesets.collect(&:revision)
238 240
239 241 path = 'sql_escape/percent%dir'
240 242 changesets = @repository.latest_changesets(path, nil)
241 243 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
242 244
243 245 changesets = @repository.latest_changesets(path, '11')
244 246 assert_equal %w|11 10 9|, changesets.collect(&:revision)
245 247
246 248 changesets = @repository.latest_changesets(path, '11', 2)
247 249 assert_equal %w|11 10|, changesets.collect(&:revision)
248 250
249 251 path = 'sql_escape/underscore_dir'
250 252 changesets = @repository.latest_changesets(path, nil)
251 253 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
252 254
253 255 changesets = @repository.latest_changesets(path, '12')
254 256 assert_equal %w|12 9|, changesets.collect(&:revision)
255 257
256 258 changesets = @repository.latest_changesets(path, '12', 1)
257 259 assert_equal %w|12|, changesets.collect(&:revision)
258 260 end
259 261
260 262 def assert_latest_changesets_tag
261 263 changesets = @repository.latest_changesets('', 'tag_test.00')
262 264 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
263 265 end
264 266 private :assert_latest_changesets_tag
265 267
266 268 def test_latest_changesets_tag
267 269 assert_equal 0, @repository.changesets.count
268 270 @repository.fetch_changesets
269 271 @project.reload
270 272 assert_equal NUM_REV, @repository.changesets.count
271 273 assert_latest_changesets_tag
272 274 end
273 275
274 276 def test_latest_changesets_tag_with_path
275 277 assert_equal 0, @repository.changesets.count
276 278 @repository.fetch_changesets
277 279 @project.reload
278 280 assert_equal NUM_REV, @repository.changesets.count
279 281
280 282 changesets = @repository.latest_changesets('sources', 'tag_test.00')
281 283 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
282 284 end
283 285
284 286 def test_latest_changesets_tag_with_limit
285 287 assert_equal 0, @repository.changesets.count
286 288 @repository.fetch_changesets
287 289 @project.reload
288 290 assert_equal NUM_REV, @repository.changesets.count
289 291
290 292 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
291 293 assert_equal %w|5 4|, changesets.collect(&:revision)
292 294
293 295 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
294 296 assert_equal %w|4 3|, changesets.collect(&:revision)
295 297 end
296 298
297 299 def test_latest_changesets_branch
298 300 assert_equal 0, @repository.changesets.count
299 301 @repository.fetch_changesets
300 302 @project.reload
301 303 assert_equal NUM_REV, @repository.changesets.count
302 304
303 305 if @repository.scm.class.client_version_above?([1, 6])
304 306 changesets = @repository.latest_changesets('', @branch_char_1)
305 307 assert_equal %w|27 26|, changesets.collect(&:revision)
306 308 end
307 309
308 310 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
309 311 assert_equal %w|27|, changesets.collect(&:revision)
310 312 end
311 313
312 314 def assert_latest_changesets_default_branch
313 315 changesets = @repository.latest_changesets('', 'default')
314 316 assert_equal %w|31 28 24 6 4 3 2 1 0|, changesets.collect(&:revision)
315 317 end
316 318 private :assert_latest_changesets_default_branch
317 319
318 320 def test_latest_changesets_default_branch
319 321 assert_equal 0, @repository.changesets.count
320 322 @repository.fetch_changesets
321 323 @project.reload
322 324 assert_equal NUM_REV, @repository.changesets.count
323 325 assert_latest_changesets_default_branch
324 326 end
325 327
326 328 def assert_copied_files(is_short_scmid=true)
327 329 cs1 = @repository.changesets.find_by_revision('13')
328 330 assert_not_nil cs1
329 331 c1 = cs1.filechanges.sort_by(&:path)
330 332 assert_equal 2, c1.size
331 333
332 334 hex1 = "3a330eb329586ea2adb3f83237c23310e744ebe9"
333 335 scmid1 = scmid_for_assert(hex1, is_short_scmid)
334 336 assert_equal 'A', c1[0].action
335 337 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
336 338 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
337 339 assert_equal scmid1, c1[0].from_revision
338 340
339 341 assert_equal 'A', c1[1].action
340 342 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
341 343 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
342 344
343 345 cs2 = @repository.changesets.find_by_revision('15')
344 346 c2 = cs2.filechanges
345 347 assert_equal 1, c2.size
346 348
347 349 hex2 = "933ca60293d78f7c7979dd123cc0c02431683575"
348 350 scmid2 = scmid_for_assert(hex2, is_short_scmid)
349 351 assert_equal 'A', c2[0].action
350 352 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
351 353 assert_equal '/README', c2[0].from_path
352 354 assert_equal scmid2, c2[0].from_revision
353 355
354 356 cs3 = @repository.changesets.find_by_revision('19')
355 357 c3 = cs3.filechanges
356 358
357 359 hex3 = "5d9891a1b4258ea256552aa856e388f2da28256a"
358 360 scmid3 = scmid_for_assert(hex3, is_short_scmid)
359 361 assert_equal 1, c3.size
360 362 assert_equal 'A', c3[0].action
361 363 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
362 364 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
363 365 assert_equal scmid3, c3[0].from_revision
364 366 end
365 367 private :assert_copied_files
366 368
367 369 def test_copied_files_short_id
368 370 assert_equal 0, @repository.changesets.count
369 371 @repository.fetch_changesets
370 372 @project.reload
371 373 assert_equal NUM_REV, @repository.changesets.count
372 374 assert_copied_files(true)
373 375 end
374 376
375 377 def test_find_changeset_by_name
376 378 assert_equal 0, @repository.changesets.count
377 379 @repository.fetch_changesets
378 380 @project.reload
379 381 assert_equal NUM_REV, @repository.changesets.count
380 382 %w|2 400bb8672109 400|.each do |r|
381 383 assert_equal '2', @repository.find_changeset_by_name(r).revision
382 384 end
383 385 end
384 386
385 387 def test_find_changeset_by_invalid_name
386 388 assert_equal 0, @repository.changesets.count
387 389 @repository.fetch_changesets
388 390 @project.reload
389 391 assert_equal NUM_REV, @repository.changesets.count
390 392 assert_nil @repository.find_changeset_by_name('100000')
391 393 end
392 394
393 395 def test_identifier
394 396 assert_equal 0, @repository.changesets.count
395 397 @repository.fetch_changesets
396 398 @project.reload
397 399 assert_equal NUM_REV, @repository.changesets.count
398 400 c = @repository.changesets.find_by_revision('2')
399 401 assert_equal c.scmid, c.identifier
400 402 end
401 403
402 404 def test_format_identifier
403 405 assert_equal 0, @repository.changesets.count
404 406 @repository.fetch_changesets
405 407 @project.reload
406 408 assert_equal NUM_REV, @repository.changesets.count
407 409 c = @repository.changesets.find_by_revision('2')
408 410 assert_equal '2:400bb8672109', c.format_identifier
409 411 end
410 412
411 413 def test_format_identifier_long_id
412 414 assert_equal 0, @repository.changesets.count
413 415 Changeset.create!(:repository => @repository,
414 416 :committed_on => Time.now,
415 417 :revision => '0',
416 418 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
417 419 :comments => 'test')
418 420 c = @repository.changesets.find_by_revision('0')
419 421 assert_equal '0:0885933ad4f6', c.format_identifier
420 422 end
421 423
422 424 def test_find_changeset_by_empty_name
423 425 assert_equal 0, @repository.changesets.count
424 426 @repository.fetch_changesets
425 427 @project.reload
426 428 assert_equal NUM_REV, @repository.changesets.count
427 429 ['', ' ', nil].each do |r|
428 430 assert_nil @repository.find_changeset_by_name(r)
429 431 end
430 432 end
431 433
432 434 def assert_parents
433 435 r1 = @repository.changesets.find_by_revision('0')
434 436 assert_equal [], r1.parents
435 437 r2 = @repository.changesets.find_by_revision('1')
436 438 assert_equal 1, r2.parents.length
437 439 assert_equal "0885933ad4f6",
438 440 r2.parents[0].identifier
439 441 r3 = @repository.changesets.find_by_revision('30')
440 442 assert_equal 2, r3.parents.length
441 443 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
442 444 assert_equal "3a330eb32958", r4[0]
443 445 assert_equal "a94b0528f24f", r4[1]
444 446 end
445 447 private :assert_parents
446 448
447 449 def test_parents_short_id
448 450 assert_equal 0, @repository.changesets.count
449 451 @repository.fetch_changesets
450 452 @project.reload
451 453 assert_equal NUM_REV, @repository.changesets.count
452 454 assert_parents
453 455 end
454 456
455 457 def test_activities
456 458 c = Changeset.new(:repository => @repository,
457 459 :committed_on => Time.now,
458 460 :revision => '123',
459 461 :scmid => 'abc400bb8672',
460 462 :comments => 'test')
461 463 assert c.event_title.include?('123:abc400bb8672:')
462 464 assert_equal 'abc400bb8672', c.event_url[:rev]
463 465 end
464 466
465 467 def test_previous
466 468 assert_equal 0, @repository.changesets.count
467 469 @repository.fetch_changesets
468 470 @project.reload
469 471 assert_equal NUM_REV, @repository.changesets.count
470 472 %w|28 3ae45e2d177d 3ae45|.each do |r1|
471 473 changeset = @repository.find_changeset_by_name(r1)
472 474 %w|27 7bbf4c738e71 7bbf|.each do |r2|
473 475 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
474 476 end
475 477 end
476 478 end
477 479
478 480 def test_previous_nil
479 481 assert_equal 0, @repository.changesets.count
480 482 @repository.fetch_changesets
481 483 @project.reload
482 484 assert_equal NUM_REV, @repository.changesets.count
483 485 %w|0 0885933ad4f6 0885|.each do |r1|
484 486 changeset = @repository.find_changeset_by_name(r1)
485 487 assert_nil changeset.previous
486 488 end
487 489 end
488 490
489 491 def test_next
490 492 assert_equal 0, @repository.changesets.count
491 493 @repository.fetch_changesets
492 494 @project.reload
493 495 assert_equal NUM_REV, @repository.changesets.count
494 496 %w|27 7bbf4c738e71 7bbf|.each do |r2|
495 497 changeset = @repository.find_changeset_by_name(r2)
496 498 %w|28 3ae45e2d177d 3ae45|.each do |r1|
497 499 assert_equal @repository.find_changeset_by_name(r1), changeset.next
498 500 end
499 501 end
500 502 end
501 503
502 504 def test_next_nil
503 505 assert_equal 0, @repository.changesets.count
504 506 @repository.fetch_changesets
505 507 @project.reload
506 508 assert_equal NUM_REV, @repository.changesets.count
507 509 %w|31 31eeee7395c8 31eee|.each do |r1|
508 510 changeset = @repository.find_changeset_by_name(r1)
509 511 assert_nil changeset.next
510 512 end
511 513 end
512 514
513 515 def test_scmid_for_assert
514 516 rev = "0123456789012345678901234567890123456789"
515 517 assert_equal rev, scmid_for_assert(rev, false)
516 518 assert_equal "012345678901", scmid_for_assert(rev, true)
517 519 end
518 520
519 521 private
520 522
521 523 def scmid_for_assert(hex, is_short=true)
522 524 is_short ? hex[0, 12] : hex
523 525 end
524 526 else
525 527 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
526 528 def test_fake; assert true end
527 529 end
528 530 end
General Comments 0
You need to be logged in to leave comments. Login now