@@ -1,373 +1,372 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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 | |
|
50 | 50 | def test_blank_path_to_repository_error_message |
|
51 | 51 | set_language_if_valid 'en' |
|
52 | 52 | repo = Repository::Mercurial.new( |
|
53 | 53 | :project => @project, |
|
54 |
:identifier => 'test' |
|
|
55 | :log_encoding => 'UTF-8' | |
|
54 | :identifier => 'test' | |
|
56 | 55 | ) |
|
57 | 56 | assert !repo.save |
|
58 | 57 | assert_include "Path to repository can't be blank", |
|
59 | 58 | repo.errors.full_messages |
|
60 | 59 | end |
|
61 | 60 | |
|
62 | 61 | def test_blank_path_to_repository_error_message_fr |
|
63 | 62 | set_language_if_valid 'fr' |
|
64 | 63 | str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)" |
|
65 | 64 | str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) |
|
66 | 65 | repo = Repository::Mercurial.new( |
|
67 | 66 | :project => @project, |
|
68 | 67 | :url => "", |
|
69 | 68 | :identifier => 'test', |
|
70 |
: |
|
|
69 | :path_encoding => '' | |
|
71 | 70 | ) |
|
72 | 71 | assert !repo.save |
|
73 | 72 | assert_include str, repo.errors.full_messages |
|
74 | 73 | end |
|
75 | 74 | |
|
76 | 75 | if File.directory?(REPOSITORY_PATH) |
|
77 | 76 | def test_scm_available |
|
78 | 77 | klass = Repository::Mercurial |
|
79 | 78 | assert_equal "Mercurial", klass.scm_name |
|
80 | 79 | assert klass.scm_adapter_class |
|
81 | 80 | assert_not_equal "", klass.scm_command |
|
82 | 81 | assert_equal true, klass.scm_available |
|
83 | 82 | end |
|
84 | 83 | |
|
85 | 84 | def test_fetch_changesets_from_scratch |
|
86 | 85 | assert_equal 0, @repository.changesets.count |
|
87 | 86 | @repository.fetch_changesets |
|
88 | 87 | @project.reload |
|
89 | 88 | assert_equal NUM_REV, @repository.changesets.count |
|
90 | 89 | assert_equal 46, @repository.changes.count |
|
91 | 90 | assert_equal "Initial import.\nThe repository contains 3 files.", |
|
92 | 91 | @repository.changesets.find_by_revision('0').comments |
|
93 | 92 | end |
|
94 | 93 | |
|
95 | 94 | def test_fetch_changesets_incremental |
|
96 | 95 | assert_equal 0, @repository.changesets.count |
|
97 | 96 | @repository.fetch_changesets |
|
98 | 97 | @project.reload |
|
99 | 98 | assert_equal NUM_REV, @repository.changesets.count |
|
100 | 99 | # Remove changesets with revision > 2 |
|
101 | 100 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} |
|
102 | 101 | @project.reload |
|
103 | 102 | assert_equal 3, @repository.changesets.count |
|
104 | 103 | |
|
105 | 104 | @repository.fetch_changesets |
|
106 | 105 | @project.reload |
|
107 | 106 | assert_equal NUM_REV, @repository.changesets.count |
|
108 | 107 | end |
|
109 | 108 | |
|
110 | 109 | def test_isodatesec |
|
111 | 110 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
|
112 | 111 | if @repository.scm.class.client_version_above?([1, 0]) |
|
113 | 112 | assert_equal 0, @repository.changesets.count |
|
114 | 113 | @repository.fetch_changesets |
|
115 | 114 | @project.reload |
|
116 | 115 | assert_equal NUM_REV, @repository.changesets.count |
|
117 | 116 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) |
|
118 | 117 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on |
|
119 | 118 | end |
|
120 | 119 | end |
|
121 | 120 | |
|
122 | 121 | def test_changeset_order_by_revision |
|
123 | 122 | assert_equal 0, @repository.changesets.count |
|
124 | 123 | @repository.fetch_changesets |
|
125 | 124 | @project.reload |
|
126 | 125 | assert_equal NUM_REV, @repository.changesets.count |
|
127 | 126 | |
|
128 | 127 | c0 = @repository.latest_changeset |
|
129 | 128 | c1 = @repository.changesets.find_by_revision('0') |
|
130 | 129 | # sorted by revision (id), not by date |
|
131 | 130 | assert c0.revision.to_i > c1.revision.to_i |
|
132 | 131 | assert c0.committed_on < c1.committed_on |
|
133 | 132 | end |
|
134 | 133 | |
|
135 | 134 | def test_latest_changesets |
|
136 | 135 | assert_equal 0, @repository.changesets.count |
|
137 | 136 | @repository.fetch_changesets |
|
138 | 137 | @project.reload |
|
139 | 138 | assert_equal NUM_REV, @repository.changesets.count |
|
140 | 139 | |
|
141 | 140 | # with_limit |
|
142 | 141 | changesets = @repository.latest_changesets('', nil, 2) |
|
143 | 142 | assert_equal %w|31 30|, changesets.collect(&:revision) |
|
144 | 143 | |
|
145 | 144 | # with_filepath |
|
146 | 145 | changesets = @repository.latest_changesets( |
|
147 | 146 | '/sql_escape/percent%dir/percent%file1.txt', nil) |
|
148 | 147 | assert_equal %w|30 11 10 9|, changesets.collect(&:revision) |
|
149 | 148 | |
|
150 | 149 | changesets = @repository.latest_changesets( |
|
151 | 150 | '/sql_escape/underscore_dir/understrike_file.txt', nil) |
|
152 | 151 | assert_equal %w|30 12 9|, changesets.collect(&:revision) |
|
153 | 152 | |
|
154 | 153 | changesets = @repository.latest_changesets('README', nil) |
|
155 | 154 | assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision) |
|
156 | 155 | |
|
157 | 156 | changesets = @repository.latest_changesets('README','8') |
|
158 | 157 | assert_equal %w|8 6 1 0|, changesets.collect(&:revision) |
|
159 | 158 | |
|
160 | 159 | changesets = @repository.latest_changesets('README','8', 2) |
|
161 | 160 | assert_equal %w|8 6|, changesets.collect(&:revision) |
|
162 | 161 | |
|
163 | 162 | # with_dirpath |
|
164 | 163 | changesets = @repository.latest_changesets('images', nil) |
|
165 | 164 | assert_equal %w|1 0|, changesets.collect(&:revision) |
|
166 | 165 | |
|
167 | 166 | path = 'sql_escape/percent%dir' |
|
168 | 167 | changesets = @repository.latest_changesets(path, nil) |
|
169 | 168 | assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision) |
|
170 | 169 | |
|
171 | 170 | changesets = @repository.latest_changesets(path, '11') |
|
172 | 171 | assert_equal %w|11 10 9|, changesets.collect(&:revision) |
|
173 | 172 | |
|
174 | 173 | changesets = @repository.latest_changesets(path, '11', 2) |
|
175 | 174 | assert_equal %w|11 10|, changesets.collect(&:revision) |
|
176 | 175 | |
|
177 | 176 | path = 'sql_escape/underscore_dir' |
|
178 | 177 | changesets = @repository.latest_changesets(path, nil) |
|
179 | 178 | assert_equal %w|30 13 12 9|, changesets.collect(&:revision) |
|
180 | 179 | |
|
181 | 180 | changesets = @repository.latest_changesets(path, '12') |
|
182 | 181 | assert_equal %w|12 9|, changesets.collect(&:revision) |
|
183 | 182 | |
|
184 | 183 | changesets = @repository.latest_changesets(path, '12', 1) |
|
185 | 184 | assert_equal %w|12|, changesets.collect(&:revision) |
|
186 | 185 | |
|
187 | 186 | # tag |
|
188 | 187 | changesets = @repository.latest_changesets('', 'tag_test.00') |
|
189 | 188 | assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision) |
|
190 | 189 | |
|
191 | 190 | changesets = @repository.latest_changesets('', 'tag_test.00', 2) |
|
192 | 191 | assert_equal %w|5 4|, changesets.collect(&:revision) |
|
193 | 192 | |
|
194 | 193 | changesets = @repository.latest_changesets('sources', 'tag_test.00') |
|
195 | 194 | assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision) |
|
196 | 195 | |
|
197 | 196 | changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) |
|
198 | 197 | assert_equal %w|4 3|, changesets.collect(&:revision) |
|
199 | 198 | |
|
200 | 199 | # named branch |
|
201 | 200 | if @repository.scm.class.client_version_above?([1, 6]) |
|
202 | 201 | changesets = @repository.latest_changesets('', @branch_char_1) |
|
203 | 202 | assert_equal %w|27 26|, changesets.collect(&:revision) |
|
204 | 203 | end |
|
205 | 204 | |
|
206 | 205 | changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) |
|
207 | 206 | assert_equal %w|27|, changesets.collect(&:revision) |
|
208 | 207 | end |
|
209 | 208 | |
|
210 | 209 | def test_copied_files |
|
211 | 210 | assert_equal 0, @repository.changesets.count |
|
212 | 211 | @repository.fetch_changesets |
|
213 | 212 | @project.reload |
|
214 | 213 | assert_equal NUM_REV, @repository.changesets.count |
|
215 | 214 | |
|
216 | 215 | cs1 = @repository.changesets.find_by_revision('13') |
|
217 | 216 | assert_not_nil cs1 |
|
218 | 217 | c1 = cs1.changes.sort_by(&:path) |
|
219 | 218 | assert_equal 2, c1.size |
|
220 | 219 | |
|
221 | 220 | assert_equal 'A', c1[0].action |
|
222 | 221 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path |
|
223 | 222 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path |
|
224 | 223 | assert_equal '3a330eb32958', c1[0].from_revision |
|
225 | 224 | |
|
226 | 225 | assert_equal 'A', c1[1].action |
|
227 | 226 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path |
|
228 | 227 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path |
|
229 | 228 | |
|
230 | 229 | cs2 = @repository.changesets.find_by_revision('15') |
|
231 | 230 | c2 = cs2.changes |
|
232 | 231 | assert_equal 1, c2.size |
|
233 | 232 | |
|
234 | 233 | assert_equal 'A', c2[0].action |
|
235 | 234 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
|
236 | 235 | assert_equal '/README', c2[0].from_path |
|
237 | 236 | assert_equal '933ca60293d7', c2[0].from_revision |
|
238 | 237 | |
|
239 | 238 | cs3 = @repository.changesets.find_by_revision('19') |
|
240 | 239 | c3 = cs3.changes |
|
241 | 240 | assert_equal 1, c3.size |
|
242 | 241 | assert_equal 'A', c3[0].action |
|
243 | 242 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path |
|
244 | 243 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path |
|
245 | 244 | assert_equal '5d9891a1b425', c3[0].from_revision |
|
246 | 245 | end |
|
247 | 246 | |
|
248 | 247 | def test_find_changeset_by_name |
|
249 | 248 | assert_equal 0, @repository.changesets.count |
|
250 | 249 | @repository.fetch_changesets |
|
251 | 250 | @project.reload |
|
252 | 251 | assert_equal NUM_REV, @repository.changesets.count |
|
253 | 252 | %w|2 400bb8672109 400|.each do |r| |
|
254 | 253 | assert_equal '2', @repository.find_changeset_by_name(r).revision |
|
255 | 254 | end |
|
256 | 255 | end |
|
257 | 256 | |
|
258 | 257 | def test_find_changeset_by_invalid_name |
|
259 | 258 | assert_equal 0, @repository.changesets.count |
|
260 | 259 | @repository.fetch_changesets |
|
261 | 260 | @project.reload |
|
262 | 261 | assert_equal NUM_REV, @repository.changesets.count |
|
263 | 262 | assert_nil @repository.find_changeset_by_name('100000') |
|
264 | 263 | end |
|
265 | 264 | |
|
266 | 265 | def test_identifier |
|
267 | 266 | assert_equal 0, @repository.changesets.count |
|
268 | 267 | @repository.fetch_changesets |
|
269 | 268 | @project.reload |
|
270 | 269 | assert_equal NUM_REV, @repository.changesets.count |
|
271 | 270 | c = @repository.changesets.find_by_revision('2') |
|
272 | 271 | assert_equal c.scmid, c.identifier |
|
273 | 272 | end |
|
274 | 273 | |
|
275 | 274 | def test_format_identifier |
|
276 | 275 | assert_equal 0, @repository.changesets.count |
|
277 | 276 | @repository.fetch_changesets |
|
278 | 277 | @project.reload |
|
279 | 278 | assert_equal NUM_REV, @repository.changesets.count |
|
280 | 279 | c = @repository.changesets.find_by_revision('2') |
|
281 | 280 | assert_equal '2:400bb8672109', c.format_identifier |
|
282 | 281 | end |
|
283 | 282 | |
|
284 | 283 | def test_find_changeset_by_empty_name |
|
285 | 284 | assert_equal 0, @repository.changesets.count |
|
286 | 285 | @repository.fetch_changesets |
|
287 | 286 | @project.reload |
|
288 | 287 | assert_equal NUM_REV, @repository.changesets.count |
|
289 | 288 | ['', ' ', nil].each do |r| |
|
290 | 289 | assert_nil @repository.find_changeset_by_name(r) |
|
291 | 290 | end |
|
292 | 291 | end |
|
293 | 292 | |
|
294 | 293 | def test_parents |
|
295 | 294 | assert_equal 0, @repository.changesets.count |
|
296 | 295 | @repository.fetch_changesets |
|
297 | 296 | @project.reload |
|
298 | 297 | assert_equal NUM_REV, @repository.changesets.count |
|
299 | 298 | r1 = @repository.changesets.find_by_revision('0') |
|
300 | 299 | assert_equal [], r1.parents |
|
301 | 300 | r2 = @repository.changesets.find_by_revision('1') |
|
302 | 301 | assert_equal 1, r2.parents.length |
|
303 | 302 | assert_equal "0885933ad4f6", |
|
304 | 303 | r2.parents[0].identifier |
|
305 | 304 | r3 = @repository.changesets.find_by_revision('30') |
|
306 | 305 | assert_equal 2, r3.parents.length |
|
307 | 306 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort |
|
308 | 307 | assert_equal "3a330eb32958", r4[0] |
|
309 | 308 | assert_equal "a94b0528f24f", r4[1] |
|
310 | 309 | end |
|
311 | 310 | |
|
312 | 311 | def test_activities |
|
313 | 312 | c = Changeset.new(:repository => @repository, |
|
314 | 313 | :committed_on => Time.now, |
|
315 | 314 | :revision => '123', |
|
316 | 315 | :scmid => 'abc400bb8672', |
|
317 | 316 | :comments => 'test') |
|
318 | 317 | assert c.event_title.include?('123:abc400bb8672:') |
|
319 | 318 | assert_equal 'abc400bb8672', c.event_url[:rev] |
|
320 | 319 | end |
|
321 | 320 | |
|
322 | 321 | def test_previous |
|
323 | 322 | assert_equal 0, @repository.changesets.count |
|
324 | 323 | @repository.fetch_changesets |
|
325 | 324 | @project.reload |
|
326 | 325 | assert_equal NUM_REV, @repository.changesets.count |
|
327 | 326 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
328 | 327 | changeset = @repository.find_changeset_by_name(r1) |
|
329 | 328 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
330 | 329 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
331 | 330 | end |
|
332 | 331 | end |
|
333 | 332 | end |
|
334 | 333 | |
|
335 | 334 | def test_previous_nil |
|
336 | 335 | assert_equal 0, @repository.changesets.count |
|
337 | 336 | @repository.fetch_changesets |
|
338 | 337 | @project.reload |
|
339 | 338 | assert_equal NUM_REV, @repository.changesets.count |
|
340 | 339 | %w|0 0885933ad4f6 0885|.each do |r1| |
|
341 | 340 | changeset = @repository.find_changeset_by_name(r1) |
|
342 | 341 | assert_nil changeset.previous |
|
343 | 342 | end |
|
344 | 343 | end |
|
345 | 344 | |
|
346 | 345 | def test_next |
|
347 | 346 | assert_equal 0, @repository.changesets.count |
|
348 | 347 | @repository.fetch_changesets |
|
349 | 348 | @project.reload |
|
350 | 349 | assert_equal NUM_REV, @repository.changesets.count |
|
351 | 350 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
352 | 351 | changeset = @repository.find_changeset_by_name(r2) |
|
353 | 352 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
354 | 353 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
355 | 354 | end |
|
356 | 355 | end |
|
357 | 356 | end |
|
358 | 357 | |
|
359 | 358 | def test_next_nil |
|
360 | 359 | assert_equal 0, @repository.changesets.count |
|
361 | 360 | @repository.fetch_changesets |
|
362 | 361 | @project.reload |
|
363 | 362 | assert_equal NUM_REV, @repository.changesets.count |
|
364 | 363 | %w|31 31eeee7395c8 31eee|.each do |r1| |
|
365 | 364 | changeset = @repository.find_changeset_by_name(r1) |
|
366 | 365 | assert_nil changeset.next |
|
367 | 366 | end |
|
368 | 367 | end |
|
369 | 368 | else |
|
370 | 369 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
371 | 370 | def test_fake; assert true end |
|
372 | 371 | end |
|
373 | 372 | end |
General Comments 0
You need to be logged in to leave comments.
Login now