To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / d8 / d85492482f3555bd4792888f6e64bcab52480eca.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (12.5 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or |
| 5 |
# modify it under the terms of the GNU General Public License |
| 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 |
# of the License, or (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
| 19 |
|
| 20 |
class RepositoryMercurialTest < ActiveSupport::TestCase |
| 21 |
fixtures :projects |
| 22 |
|
| 23 |
REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
|
| 24 |
NUM_REV = 32 |
| 25 |
CHAR_1_HEX = "\xc3\x9c" |
| 26 |
|
| 27 |
if File.directory?(REPOSITORY_PATH) |
| 28 |
def setup |
| 29 |
klass = Repository::Mercurial |
| 30 |
assert_equal "Mercurial", klass.scm_name |
| 31 |
assert klass.scm_adapter_class |
| 32 |
assert_not_equal "", klass.scm_command |
| 33 |
assert_equal true, klass.scm_available |
| 34 |
|
| 35 |
@project = Project.find(3) |
| 36 |
@repository = Repository::Mercurial.create( |
| 37 |
:project => @project, |
| 38 |
:url => REPOSITORY_PATH, |
| 39 |
:path_encoding => 'ISO-8859-1' |
| 40 |
) |
| 41 |
assert @repository |
| 42 |
@char_1 = CHAR_1_HEX.dup |
| 43 |
@tag_char_1 = "tag-#{CHAR_1_HEX}-00"
|
| 44 |
@branch_char_0 = "branch-#{CHAR_1_HEX}-00"
|
| 45 |
@branch_char_1 = "branch-#{CHAR_1_HEX}-01"
|
| 46 |
if @char_1.respond_to?(:force_encoding) |
| 47 |
@char_1.force_encoding('UTF-8')
|
| 48 |
@tag_char_1.force_encoding('UTF-8')
|
| 49 |
@branch_char_0.force_encoding('UTF-8')
|
| 50 |
@branch_char_1.force_encoding('UTF-8')
|
| 51 |
end |
| 52 |
end |
| 53 |
|
| 54 |
def test_fetch_changesets_from_scratch |
| 55 |
assert_equal 0, @repository.changesets.count |
| 56 |
@repository.fetch_changesets |
| 57 |
@project.reload |
| 58 |
assert_equal NUM_REV, @repository.changesets.count |
| 59 |
assert_equal 46, @repository.changes.count |
| 60 |
assert_equal "Initial import.\nThe repository contains 3 files.", |
| 61 |
@repository.changesets.find_by_revision('0').comments
|
| 62 |
end |
| 63 |
|
| 64 |
def test_fetch_changesets_incremental |
| 65 |
assert_equal 0, @repository.changesets.count |
| 66 |
@repository.fetch_changesets |
| 67 |
@project.reload |
| 68 |
assert_equal NUM_REV, @repository.changesets.count |
| 69 |
# Remove changesets with revision > 2 |
| 70 |
@repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
|
| 71 |
@project.reload |
| 72 |
assert_equal 3, @repository.changesets.count |
| 73 |
|
| 74 |
@repository.fetch_changesets |
| 75 |
@project.reload |
| 76 |
assert_equal NUM_REV, @repository.changesets.count |
| 77 |
end |
| 78 |
|
| 79 |
def test_isodatesec |
| 80 |
# Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
| 81 |
if @repository.scm.class.client_version_above?([1, 0]) |
| 82 |
assert_equal 0, @repository.changesets.count |
| 83 |
@repository.fetch_changesets |
| 84 |
@project.reload |
| 85 |
assert_equal NUM_REV, @repository.changesets.count |
| 86 |
rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) |
| 87 |
assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
|
| 88 |
end |
| 89 |
end |
| 90 |
|
| 91 |
def test_changeset_order_by_revision |
| 92 |
assert_equal 0, @repository.changesets.count |
| 93 |
@repository.fetch_changesets |
| 94 |
@project.reload |
| 95 |
assert_equal NUM_REV, @repository.changesets.count |
| 96 |
|
| 97 |
c0 = @repository.latest_changeset |
| 98 |
c1 = @repository.changesets.find_by_revision('0')
|
| 99 |
# sorted by revision (id), not by date |
| 100 |
assert c0.revision.to_i > c1.revision.to_i |
| 101 |
assert c0.committed_on < c1.committed_on |
| 102 |
end |
| 103 |
|
| 104 |
def test_latest_changesets |
| 105 |
assert_equal 0, @repository.changesets.count |
| 106 |
@repository.fetch_changesets |
| 107 |
@project.reload |
| 108 |
assert_equal NUM_REV, @repository.changesets.count |
| 109 |
|
| 110 |
# with_limit |
| 111 |
changesets = @repository.latest_changesets('', nil, 2)
|
| 112 |
assert_equal %w|31 30|, changesets.collect(&:revision) |
| 113 |
|
| 114 |
# with_filepath |
| 115 |
changesets = @repository.latest_changesets( |
| 116 |
'/sql_escape/percent%dir/percent%file1.txt', nil) |
| 117 |
assert_equal %w|30 11 10 9|, changesets.collect(&:revision) |
| 118 |
|
| 119 |
changesets = @repository.latest_changesets( |
| 120 |
'/sql_escape/underscore_dir/understrike_file.txt', nil) |
| 121 |
assert_equal %w|30 12 9|, changesets.collect(&:revision) |
| 122 |
|
| 123 |
changesets = @repository.latest_changesets('README', nil)
|
| 124 |
assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision) |
| 125 |
|
| 126 |
changesets = @repository.latest_changesets('README','8')
|
| 127 |
assert_equal %w|8 6 1 0|, changesets.collect(&:revision) |
| 128 |
|
| 129 |
changesets = @repository.latest_changesets('README','8', 2)
|
| 130 |
assert_equal %w|8 6|, changesets.collect(&:revision) |
| 131 |
|
| 132 |
# with_dirpath |
| 133 |
changesets = @repository.latest_changesets('images', nil)
|
| 134 |
assert_equal %w|1 0|, changesets.collect(&:revision) |
| 135 |
|
| 136 |
path = 'sql_escape/percent%dir' |
| 137 |
changesets = @repository.latest_changesets(path, nil) |
| 138 |
assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision) |
| 139 |
|
| 140 |
changesets = @repository.latest_changesets(path, '11') |
| 141 |
assert_equal %w|11 10 9|, changesets.collect(&:revision) |
| 142 |
|
| 143 |
changesets = @repository.latest_changesets(path, '11', 2) |
| 144 |
assert_equal %w|11 10|, changesets.collect(&:revision) |
| 145 |
|
| 146 |
path = 'sql_escape/underscore_dir' |
| 147 |
changesets = @repository.latest_changesets(path, nil) |
| 148 |
assert_equal %w|30 13 12 9|, changesets.collect(&:revision) |
| 149 |
|
| 150 |
changesets = @repository.latest_changesets(path, '12') |
| 151 |
assert_equal %w|12 9|, changesets.collect(&:revision) |
| 152 |
|
| 153 |
changesets = @repository.latest_changesets(path, '12', 1) |
| 154 |
assert_equal %w|12|, changesets.collect(&:revision) |
| 155 |
|
| 156 |
# tag |
| 157 |
changesets = @repository.latest_changesets('', 'tag_test.00')
|
| 158 |
assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision) |
| 159 |
|
| 160 |
changesets = @repository.latest_changesets('', 'tag_test.00', 2)
|
| 161 |
assert_equal %w|5 4|, changesets.collect(&:revision) |
| 162 |
|
| 163 |
changesets = @repository.latest_changesets('sources', 'tag_test.00')
|
| 164 |
assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision) |
| 165 |
|
| 166 |
changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
|
| 167 |
assert_equal %w|4 3|, changesets.collect(&:revision) |
| 168 |
|
| 169 |
# named branch |
| 170 |
if @repository.scm.class.client_version_above?([1, 6]) |
| 171 |
changesets = @repository.latest_changesets('', @branch_char_1)
|
| 172 |
assert_equal %w|27 26|, changesets.collect(&:revision) |
| 173 |
end |
| 174 |
|
| 175 |
changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
|
| 176 |
assert_equal %w|27|, changesets.collect(&:revision) |
| 177 |
end |
| 178 |
|
| 179 |
def test_copied_files |
| 180 |
assert_equal 0, @repository.changesets.count |
| 181 |
@repository.fetch_changesets |
| 182 |
@project.reload |
| 183 |
assert_equal NUM_REV, @repository.changesets.count |
| 184 |
|
| 185 |
cs1 = @repository.changesets.find_by_revision('13')
|
| 186 |
assert_not_nil cs1 |
| 187 |
c1 = cs1.changes.sort_by(&:path) |
| 188 |
assert_equal 2, c1.size |
| 189 |
|
| 190 |
assert_equal 'A', c1[0].action |
| 191 |
assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path |
| 192 |
assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path |
| 193 |
assert_equal '3a330eb32958', c1[0].from_revision |
| 194 |
|
| 195 |
assert_equal 'A', c1[1].action |
| 196 |
assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path |
| 197 |
assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path |
| 198 |
|
| 199 |
cs2 = @repository.changesets.find_by_revision('15')
|
| 200 |
c2 = cs2.changes |
| 201 |
assert_equal 1, c2.size |
| 202 |
|
| 203 |
assert_equal 'A', c2[0].action |
| 204 |
assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
| 205 |
assert_equal '/README', c2[0].from_path |
| 206 |
assert_equal '933ca60293d7', c2[0].from_revision |
| 207 |
|
| 208 |
cs3 = @repository.changesets.find_by_revision('19')
|
| 209 |
c3 = cs3.changes |
| 210 |
assert_equal 1, c3.size |
| 211 |
assert_equal 'A', c3[0].action |
| 212 |
assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
|
| 213 |
assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
|
| 214 |
assert_equal '5d9891a1b425', c3[0].from_revision |
| 215 |
end |
| 216 |
|
| 217 |
def test_find_changeset_by_name |
| 218 |
assert_equal 0, @repository.changesets.count |
| 219 |
@repository.fetch_changesets |
| 220 |
@project.reload |
| 221 |
assert_equal NUM_REV, @repository.changesets.count |
| 222 |
%w|2 400bb8672109 400|.each do |r| |
| 223 |
assert_equal '2', @repository.find_changeset_by_name(r).revision |
| 224 |
end |
| 225 |
end |
| 226 |
|
| 227 |
def test_find_changeset_by_invalid_name |
| 228 |
assert_equal 0, @repository.changesets.count |
| 229 |
@repository.fetch_changesets |
| 230 |
@project.reload |
| 231 |
assert_equal NUM_REV, @repository.changesets.count |
| 232 |
assert_nil @repository.find_changeset_by_name('100000')
|
| 233 |
end |
| 234 |
|
| 235 |
def test_identifier |
| 236 |
assert_equal 0, @repository.changesets.count |
| 237 |
@repository.fetch_changesets |
| 238 |
@project.reload |
| 239 |
assert_equal NUM_REV, @repository.changesets.count |
| 240 |
c = @repository.changesets.find_by_revision('2')
|
| 241 |
assert_equal c.scmid, c.identifier |
| 242 |
end |
| 243 |
|
| 244 |
def test_format_identifier |
| 245 |
assert_equal 0, @repository.changesets.count |
| 246 |
@repository.fetch_changesets |
| 247 |
@project.reload |
| 248 |
assert_equal NUM_REV, @repository.changesets.count |
| 249 |
c = @repository.changesets.find_by_revision('2')
|
| 250 |
assert_equal '2:400bb8672109', c.format_identifier |
| 251 |
end |
| 252 |
|
| 253 |
def test_find_changeset_by_empty_name |
| 254 |
assert_equal 0, @repository.changesets.count |
| 255 |
@repository.fetch_changesets |
| 256 |
@project.reload |
| 257 |
assert_equal NUM_REV, @repository.changesets.count |
| 258 |
['', ' ', nil].each do |r| |
| 259 |
assert_nil @repository.find_changeset_by_name(r) |
| 260 |
end |
| 261 |
end |
| 262 |
|
| 263 |
def test_parents |
| 264 |
assert_equal 0, @repository.changesets.count |
| 265 |
@repository.fetch_changesets |
| 266 |
@project.reload |
| 267 |
assert_equal NUM_REV, @repository.changesets.count |
| 268 |
r1 = @repository.changesets.find_by_revision('0')
|
| 269 |
assert_equal [], r1.parents |
| 270 |
r2 = @repository.changesets.find_by_revision('1')
|
| 271 |
assert_equal 1, r2.parents.length |
| 272 |
assert_equal "0885933ad4f6", |
| 273 |
r2.parents[0].identifier |
| 274 |
r3 = @repository.changesets.find_by_revision('30')
|
| 275 |
assert_equal 2, r3.parents.length |
| 276 |
r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort |
| 277 |
assert_equal "3a330eb32958", r4[0] |
| 278 |
assert_equal "a94b0528f24f", r4[1] |
| 279 |
end |
| 280 |
|
| 281 |
def test_activities |
| 282 |
c = Changeset.new(:repository => @repository, |
| 283 |
:committed_on => Time.now, |
| 284 |
:revision => '123', |
| 285 |
:scmid => 'abc400bb8672', |
| 286 |
:comments => 'test') |
| 287 |
assert c.event_title.include?('123:abc400bb8672:')
|
| 288 |
assert_equal 'abc400bb8672', c.event_url[:rev] |
| 289 |
end |
| 290 |
|
| 291 |
def test_previous |
| 292 |
assert_equal 0, @repository.changesets.count |
| 293 |
@repository.fetch_changesets |
| 294 |
@project.reload |
| 295 |
assert_equal NUM_REV, @repository.changesets.count |
| 296 |
%w|28 3ae45e2d177d 3ae45|.each do |r1| |
| 297 |
changeset = @repository.find_changeset_by_name(r1) |
| 298 |
%w|27 7bbf4c738e71 7bbf|.each do |r2| |
| 299 |
assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
| 300 |
end |
| 301 |
end |
| 302 |
end |
| 303 |
|
| 304 |
def test_previous_nil |
| 305 |
assert_equal 0, @repository.changesets.count |
| 306 |
@repository.fetch_changesets |
| 307 |
@project.reload |
| 308 |
assert_equal NUM_REV, @repository.changesets.count |
| 309 |
%w|0 0885933ad4f6 0885|.each do |r1| |
| 310 |
changeset = @repository.find_changeset_by_name(r1) |
| 311 |
assert_nil changeset.previous |
| 312 |
end |
| 313 |
end |
| 314 |
|
| 315 |
def test_next |
| 316 |
assert_equal 0, @repository.changesets.count |
| 317 |
@repository.fetch_changesets |
| 318 |
@project.reload |
| 319 |
assert_equal NUM_REV, @repository.changesets.count |
| 320 |
%w|27 7bbf4c738e71 7bbf|.each do |r2| |
| 321 |
changeset = @repository.find_changeset_by_name(r2) |
| 322 |
%w|28 3ae45e2d177d 3ae45|.each do |r1| |
| 323 |
assert_equal @repository.find_changeset_by_name(r1), changeset.next |
| 324 |
end |
| 325 |
end |
| 326 |
end |
| 327 |
|
| 328 |
def test_next_nil |
| 329 |
assert_equal 0, @repository.changesets.count |
| 330 |
@repository.fetch_changesets |
| 331 |
@project.reload |
| 332 |
assert_equal NUM_REV, @repository.changesets.count |
| 333 |
%w|31 31eeee7395c8 31eee|.each do |r1| |
| 334 |
changeset = @repository.find_changeset_by_name(r1) |
| 335 |
assert_nil changeset.next |
| 336 |
end |
| 337 |
end |
| 338 |
else |
| 339 |
puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
| 340 |
def test_fake; assert true end |
| 341 |
end |
| 342 |
end |