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