##// END OF EJS Templates
scm: mercurial: run both of "inline" and "side by side" diff in functional test_diff test....
Toshi MARUYAMA -
r5863:bc8b1c0b22d2
parent child
Show More
@@ -1,420 +1,422
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 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesMercurialControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') +
29 29 '/tmp/test/mercurial_repository'
30 30 CHAR_1_HEX = "\xc3\x9c"
31 31 PRJ_ID = 3
32 32
33 33 ruby19_non_utf8_pass =
34 34 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
35 35
36 36 def setup
37 37 @controller = RepositoriesController.new
38 38 @request = ActionController::TestRequest.new
39 39 @response = ActionController::TestResponse.new
40 40 User.current = nil
41 41 @repository = Repository::Mercurial.create(
42 42 :project => Project.find(PRJ_ID),
43 43 :url => REPOSITORY_PATH,
44 44 :path_encoding => 'ISO-8859-1'
45 45 )
46 46 assert @repository
47 47 @diff_c_support = true
48 48 @char_1 = CHAR_1_HEX.dup
49 49 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
50 50 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
51 51 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
52 52 if @char_1.respond_to?(:force_encoding)
53 53 @char_1.force_encoding('UTF-8')
54 54 @tag_char_1.force_encoding('UTF-8')
55 55 @branch_char_0.force_encoding('UTF-8')
56 56 @branch_char_1.force_encoding('UTF-8')
57 57 end
58 58 end
59 59
60 60 if ruby19_non_utf8_pass
61 61 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
62 62 "and Encoding.default_external is not UTF-8. " +
63 63 "Current value is '#{Encoding.default_external.to_s}'"
64 64 def test_fake; assert true end
65 65 elsif File.directory?(REPOSITORY_PATH)
66 66 def test_show_root
67 67 @repository.fetch_changesets
68 68 @repository.reload
69 69 get :show, :id => PRJ_ID
70 70 assert_response :success
71 71 assert_template 'show'
72 72 assert_not_nil assigns(:entries)
73 73 assert_equal 4, assigns(:entries).size
74 74 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
75 75 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
76 76 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
77 77 assert_not_nil assigns(:changesets)
78 78 assigns(:changesets).size > 0
79 79 end
80 80
81 81 def test_show_directory
82 82 @repository.fetch_changesets
83 83 @repository.reload
84 84 get :show, :id => PRJ_ID, :path => ['images']
85 85 assert_response :success
86 86 assert_template 'show'
87 87 assert_not_nil assigns(:entries)
88 88 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
89 89 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
90 90 assert_not_nil entry
91 91 assert_equal 'file', entry.kind
92 92 assert_equal 'images/edit.png', entry.path
93 93 assert_not_nil assigns(:changesets)
94 94 assigns(:changesets).size > 0
95 95 end
96 96
97 97 def test_show_at_given_revision
98 98 @repository.fetch_changesets
99 99 @repository.reload
100 100 [0, '0', '0885933ad4f6'].each do |r1|
101 101 get :show, :id => PRJ_ID, :path => ['images'], :rev => r1
102 102 assert_response :success
103 103 assert_template 'show'
104 104 assert_not_nil assigns(:entries)
105 105 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
106 106 assert_not_nil assigns(:changesets)
107 107 assigns(:changesets).size > 0
108 108 end
109 109 end
110 110
111 111 def test_show_directory_sql_escape_percent
112 112 @repository.fetch_changesets
113 113 @repository.reload
114 114 [13, '13', '3a330eb32958'].each do |r1|
115 115 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'],
116 116 :rev => r1
117 117 assert_response :success
118 118 assert_template 'show'
119 119
120 120 assert_not_nil assigns(:entries)
121 121 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
122 122 assigns(:entries).collect(&:name)
123 123 changesets = assigns(:changesets)
124 124 assert_not_nil changesets
125 125 assigns(:changesets).size > 0
126 126 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
127 127 end
128 128 end
129 129
130 130 def test_show_directory_latin_1_path
131 131 @repository.fetch_changesets
132 132 @repository.reload
133 133 [21, '21', 'adf805632193'].each do |r1|
134 134 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
135 135 assert_response :success
136 136 assert_template 'show'
137 137
138 138 assert_not_nil assigns(:entries)
139 139 assert_equal ["make-latin-1-file.rb",
140 140 "test-#{@char_1}-1.txt",
141 141 "test-#{@char_1}-2.txt",
142 142 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
143 143 changesets = assigns(:changesets)
144 144 assert_not_nil changesets
145 145 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
146 146 end
147 147 end
148 148
149 149 def test_show_branch
150 150 @repository.fetch_changesets
151 151 @repository.reload
152 152 [
153 153 'default',
154 154 @branch_char_1,
155 155 'branch (1)[2]&,%.-3_4',
156 156 @branch_char_0,
157 157 'test_branch.latin-1',
158 158 'test-branch-00',
159 159 ].each do |bra|
160 160 get :show, :id => PRJ_ID, :rev => bra
161 161 assert_response :success
162 162 assert_template 'show'
163 163 assert_not_nil assigns(:entries)
164 164 assert assigns(:entries).size > 0
165 165 assert_not_nil assigns(:changesets)
166 166 assigns(:changesets).size > 0
167 167 end
168 168 end
169 169
170 170 def test_show_tag
171 171 @repository.fetch_changesets
172 172 @repository.reload
173 173 [
174 174 @tag_char_1,
175 175 'tag_test.00',
176 176 'tag-init-revision'
177 177 ].each do |tag|
178 178 get :show, :id => PRJ_ID, :rev => tag
179 179 assert_response :success
180 180 assert_template 'show'
181 181 assert_not_nil assigns(:entries)
182 182 assert assigns(:entries).size > 0
183 183 assert_not_nil assigns(:changesets)
184 184 assigns(:changesets).size > 0
185 185 end
186 186 end
187 187
188 188 def test_changes
189 189 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
190 190 assert_response :success
191 191 assert_template 'changes'
192 192 assert_tag :tag => 'h2', :content => 'edit.png'
193 193 end
194 194
195 195 def test_entry_show
196 196 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
197 197 assert_response :success
198 198 assert_template 'entry'
199 199 # Line 10
200 200 assert_tag :tag => 'th',
201 201 :content => '10',
202 202 :attributes => { :class => 'line-num' },
203 203 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
204 204 end
205 205
206 206 def test_entry_show_latin_1_path
207 207 [21, '21', 'adf805632193'].each do |r1|
208 208 get :entry, :id => PRJ_ID,
209 209 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
210 210 assert_response :success
211 211 assert_template 'entry'
212 212 assert_tag :tag => 'th',
213 213 :content => '1',
214 214 :attributes => { :class => 'line-num' },
215 215 :sibling => { :tag => 'td',
216 216 :content => /Mercurial is a distributed version control system/ }
217 217 end
218 218 end
219 219
220 220 def test_entry_show_latin_1_contents
221 221 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
222 222 [27, '27', '7bbf4c738e71'].each do |r1|
223 223 get :entry, :id => PRJ_ID,
224 224 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
225 225 assert_response :success
226 226 assert_template 'entry'
227 227 assert_tag :tag => 'th',
228 228 :content => '1',
229 229 :attributes => { :class => 'line-num' },
230 230 :sibling => { :tag => 'td',
231 231 :content => /test-#{@char_1}.txt/ }
232 232 end
233 233 end
234 234 end
235 235
236 236 def test_entry_download
237 237 get :entry, :id => PRJ_ID,
238 238 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
239 239 assert_response :success
240 240 # File content
241 241 assert @response.body.include?('WITHOUT ANY WARRANTY')
242 242 end
243 243
244 244 def test_entry_binary_force_download
245 245 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
246 246 assert_response :success
247 247 assert_equal 'image/png', @response.content_type
248 248 end
249 249
250 250 def test_directory_entry
251 251 get :entry, :id => PRJ_ID, :path => ['sources']
252 252 assert_response :success
253 253 assert_template 'show'
254 254 assert_not_nil assigns(:entry)
255 255 assert_equal 'sources', assigns(:entry).name
256 256 end
257 257
258 258 def test_diff
259 259 @repository.fetch_changesets
260 260 @repository.reload
261 261 [4, '4', 'def6d2f1254a'].each do |r1|
262 262 # Full diff of changeset 4
263 get :diff, :id => PRJ_ID, :rev => r1
264 assert_response :success
265 assert_template 'diff'
266 if @diff_c_support
267 # Line 22 removed
268 assert_tag :tag => 'th',
269 :content => '22',
270 :sibling => { :tag => 'td',
271 :attributes => { :class => /diff_out/ },
272 :content => /def remove/ }
273 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
263 ['inline', 'sbs'].each do |dt|
264 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
265 assert_response :success
266 assert_template 'diff'
267 if @diff_c_support
268 # Line 22 removed
269 assert_tag :tag => 'th',
270 :content => '22',
271 :sibling => { :tag => 'td',
272 :attributes => { :class => /diff_out/ },
273 :content => /def remove/ }
274 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
275 end
274 276 end
275 277 end
276 278 end
277 279
278 280 def test_diff_two_revs
279 281 @repository.fetch_changesets
280 282 @repository.reload
281 283 [2, '400bb8672109', '400', 400].each do |r1|
282 284 [4, 'def6d2f1254a'].each do |r2|
283 285 get :diff, :id => PRJ_ID, :rev => r1,
284 286 :rev_to => r2
285 287 assert_response :success
286 288 assert_template 'diff'
287 289
288 290 diff = assigns(:diff)
289 291 assert_not_nil diff
290 292 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
291 293 end
292 294 end
293 295 end
294 296
295 297 def test_diff_latin_1_path
296 298 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
297 299 [21, 'adf805632193'].each do |r1|
298 300 get :diff, :id => PRJ_ID, :rev => r1
299 301 assert_response :success
300 302 assert_template 'diff'
301 303 assert_tag :tag => 'thead',
302 304 :descendant => {
303 305 :tag => 'th',
304 306 :attributes => { :class => 'filename' } ,
305 307 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
306 308 },
307 309 :sibling => {
308 310 :tag => 'tbody',
309 311 :descendant => {
310 312 :tag => 'td',
311 313 :attributes => { :class => /diff_in/ },
312 314 :content => /It is written in Python/
313 315 }
314 316 }
315 317 end
316 318 end
317 319 end
318 320
319 321 def test_annotate
320 322 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
321 323 assert_response :success
322 324 assert_template 'annotate'
323 325 # Line 23, revision 4:def6d2f1254a
324 326 assert_tag :tag => 'th',
325 327 :content => '23',
326 328 :attributes => { :class => 'line-num' },
327 329 :sibling =>
328 330 {
329 331 :tag => 'td',
330 332 :attributes => { :class => 'revision' },
331 333 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
332 334 }
333 335 assert_tag :tag => 'th',
334 336 :content => '23',
335 337 :attributes => { :class => 'line-num' },
336 338 :sibling =>
337 339 {
338 340 :tag => 'td' ,
339 341 :content => 'jsmith' ,
340 342 :attributes => { :class => 'author' },
341 343 }
342 344 assert_tag :tag => 'th',
343 345 :content => '23',
344 346 :attributes => { :class => 'line-num' },
345 347 :sibling => { :tag => 'td', :content => /watcher =/ }
346 348 end
347 349
348 350 def test_annotate_at_given_revision
349 351 @repository.fetch_changesets
350 352 @repository.reload
351 353 [2, '400bb8672109', '400', 400].each do |r1|
352 354 get :annotate, :id => PRJ_ID, :rev => r1,
353 355 :path => ['sources', 'watchers_controller.rb']
354 356 assert_response :success
355 357 assert_template 'annotate'
356 358 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
357 359 end
358 360 end
359 361
360 362 def test_annotate_latin_1_path
361 363 [21, '21', 'adf805632193'].each do |r1|
362 364 get :annotate, :id => PRJ_ID,
363 365 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
364 366 assert_response :success
365 367 assert_template 'annotate'
366 368 assert_tag :tag => 'th',
367 369 :content => '1',
368 370 :attributes => { :class => 'line-num' },
369 371 :sibling =>
370 372 {
371 373 :tag => 'td',
372 374 :attributes => { :class => 'revision' },
373 375 :child => { :tag => 'a', :content => '20:709858aafd1b' }
374 376 }
375 377 assert_tag :tag => 'th',
376 378 :content => '1',
377 379 :attributes => { :class => 'line-num' },
378 380 :sibling =>
379 381 {
380 382 :tag => 'td' ,
381 383 :content => 'jsmith' ,
382 384 :attributes => { :class => 'author' },
383 385 }
384 386 assert_tag :tag => 'th',
385 387 :content => '1',
386 388 :attributes => { :class => 'line-num' },
387 389 :sibling => { :tag => 'td',
388 390 :content => /Mercurial is a distributed version control system/ }
389 391
390 392 end
391 393 end
392 394
393 395 def test_annotate_latin_1_contents
394 396 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
395 397 [27, '7bbf4c738e71'].each do |r1|
396 398 get :annotate, :id => PRJ_ID,
397 399 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
398 400 assert_tag :tag => 'th',
399 401 :content => '1',
400 402 :attributes => { :class => 'line-num' },
401 403 :sibling => { :tag => 'td',
402 404 :content => /test-#{@char_1}.txt/ }
403 405 end
404 406 end
405 407 end
406 408
407 409 def test_empty_revision
408 410 @repository.fetch_changesets
409 411 @repository.reload
410 412 ['', ' ', nil].each do |r|
411 413 get :revision, :id => PRJ_ID, :rev => r
412 414 assert_response 404
413 415 assert_error_tag :content => /was not found/
414 416 end
415 417 end
416 418 else
417 419 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
418 420 def test_fake; assert true end
419 421 end
420 422 end
General Comments 0
You need to be logged in to leave comments. Login now