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