##// END OF EJS Templates
scm: mercurial: add latin-1 encoding directory to test repository (#2664)....
Toshi MARUYAMA -
r4939:d5b268129c26
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
@@ -1,316 +1,316
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 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\/\.\.}, '') + '/tmp/test/mercurial_repository'
29 29 CHAR_1_HEX = "\xc3\x9c"
30 30
31 31 ruby19_non_utf8_pass = (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
32 32
33 33 def setup
34 34 @controller = RepositoriesController.new
35 35 @request = ActionController::TestRequest.new
36 36 @response = ActionController::TestResponse.new
37 37 User.current = nil
38 38 @repository = Repository::Mercurial.create(
39 39 :project => Project.find(3),
40 40 :url => REPOSITORY_PATH,
41 41 :path_encoding => 'ISO-8859-1'
42 42 )
43 43 assert @repository
44 44 @diff_c_support = true
45 45 @char_1 = CHAR_1_HEX.dup
46 46 if @char_1.respond_to?(:force_encoding)
47 47 @char_1.force_encoding('UTF-8')
48 48 end
49 49 end
50 50
51 51 if ruby19_non_utf8_pass
52 52 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
53 53 "and Encoding.default_external is not UTF-8. " +
54 54 "Current value is '#{Encoding.default_external.to_s}'"
55 55 def test_fake; assert true end
56 56 elsif File.directory?(REPOSITORY_PATH)
57 57 def test_show
58 58 get :show, :id => 3
59 59 assert_response :success
60 60 assert_template 'show'
61 61 assert_not_nil assigns(:entries)
62 62 assert_not_nil assigns(:changesets)
63 63 end
64 64
65 65 def test_show_root
66 66 get :show, :id => 3
67 67 assert_response :success
68 68 assert_template 'show'
69 69 assert_not_nil assigns(:entries)
70 70 assert_equal 4, assigns(:entries).size
71 71 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
72 72 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
73 73 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
74 74 end
75 75
76 76 def test_show_directory
77 77 get :show, :id => 3, :path => ['images']
78 78 assert_response :success
79 79 assert_template 'show'
80 80 assert_not_nil assigns(:entries)
81 81 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
82 82 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
83 83 assert_not_nil entry
84 84 assert_equal 'file', entry.kind
85 85 assert_equal 'images/edit.png', entry.path
86 86 end
87 87
88 88 def test_show_at_given_revision
89 89 [0, '0', '0885933ad4f6'].each do |r1|
90 90 get :show, :id => 3, :path => ['images'], :rev => r1
91 91 assert_response :success
92 92 assert_template 'show'
93 93 assert_not_nil assigns(:entries)
94 94 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
95 95 end
96 96 end
97 97
98 98 def test_show_directory_sql_escape_percent
99 99 [13, '13', '3a330eb32958'].each do |r1|
100 100 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
101 101 assert_response :success
102 102 assert_template 'show'
103 103
104 104 assert_not_nil assigns(:entries)
105 105 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
106 106 changesets = assigns(:changesets)
107 107
108 108 ## This is not yet implemented.
109 109 # assert_not_nil changesets
110 110 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
111 111 end
112 112 end
113 113
114 114 def test_show_directory_latin_1
115 115 @repository.fetch_changesets
116 116 @repository.reload
117 117 [21, '21', 'adf805632193'].each do |r1|
118 118 get :show, :id => 3, :path => ['latin-1-dir'], :rev => r1
119 119 assert_response :success
120 120 assert_template 'show'
121 121
122 122 assert_not_nil assigns(:entries)
123 123 assert_equal ["make-latin-1-file.rb",
124 124 "test-#{@char_1}-1.txt",
125 125 "test-#{@char_1}-2.txt",
126 126 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
127 127 changesets = assigns(:changesets)
128 128 assert_not_nil changesets
129 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
129 assert_equal %w(27 21 20 19 18 17), changesets.collect(&:revision)
130 130 end
131 131 end
132 132
133 133 def test_changes
134 134 get :changes, :id => 3, :path => ['images', 'edit.png']
135 135 assert_response :success
136 136 assert_template 'changes'
137 137 assert_tag :tag => 'h2', :content => 'edit.png'
138 138 end
139 139
140 140 def test_entry_show
141 141 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
142 142 assert_response :success
143 143 assert_template 'entry'
144 144 # Line 10
145 145 assert_tag :tag => 'th',
146 146 :content => '10',
147 147 :attributes => { :class => 'line-num' },
148 148 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
149 149 end
150 150
151 151 def test_entry_show_latin_1
152 152 [21, '21', 'adf805632193'].each do |r1|
153 153 get :entry, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
154 154 assert_response :success
155 155 assert_template 'entry'
156 156 assert_tag :tag => 'th',
157 157 :content => '1',
158 158 :attributes => { :class => 'line-num' },
159 159 :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ }
160 160 end
161 161 end
162 162
163 163 def test_entry_download
164 164 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
165 165 assert_response :success
166 166 # File content
167 167 assert @response.body.include?('WITHOUT ANY WARRANTY')
168 168 end
169 169
170 170 def test_directory_entry
171 171 get :entry, :id => 3, :path => ['sources']
172 172 assert_response :success
173 173 assert_template 'show'
174 174 assert_not_nil assigns(:entry)
175 175 assert_equal 'sources', assigns(:entry).name
176 176 end
177 177
178 178 def test_diff
179 179 @repository.fetch_changesets
180 180 @repository.reload
181 181
182 182 [4, '4', 'def6d2f1254a'].each do |r1|
183 183 # Full diff of changeset 4
184 184 get :diff, :id => 3, :rev => r1
185 185 assert_response :success
186 186 assert_template 'diff'
187 187
188 188 if @diff_c_support
189 189 # Line 22 removed
190 190 assert_tag :tag => 'th',
191 191 :content => '22',
192 192 :sibling => { :tag => 'td',
193 193 :attributes => { :class => /diff_out/ },
194 194 :content => /def remove/ }
195 195 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
196 196 end
197 197 end
198 198 end
199 199
200 200 def test_diff_two_revs
201 201 @repository.fetch_changesets
202 202 @repository.reload
203 203
204 204 [2, '400bb8672109', '400', 400].each do |r1|
205 205 [4, 'def6d2f1254a'].each do |r2|
206 206 get :diff, :id => 3, :rev => r1,
207 207 :rev_to => r2
208 208 assert_response :success
209 209 assert_template 'diff'
210 210
211 211 diff = assigns(:diff)
212 212 assert_not_nil diff
213 213 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
214 214 end
215 215 end
216 216 end
217 217
218 218 def test_diff_latin_1
219 219 [21, 'adf805632193'].each do |r1|
220 220 get :diff, :id => 3, :rev => r1
221 221 assert_response :success
222 222 assert_template 'diff'
223 223 assert_tag :tag => 'th',
224 224 :content => '2',
225 225 :sibling => { :tag => 'td',
226 226 :attributes => { :class => /diff_in/ },
227 227 :content => /It is written in Python/ }
228 228 end
229 229 end
230 230
231 231 def test_annotate
232 232 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
233 233 assert_response :success
234 234 assert_template 'annotate'
235 235 # Line 23, revision 4:def6d2f1254a
236 236 assert_tag :tag => 'th',
237 237 :content => '23',
238 238 :attributes => { :class => 'line-num' },
239 239 :sibling =>
240 240 {
241 241 :tag => 'td',
242 242 :attributes => { :class => 'revision' },
243 243 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
244 244 }
245 245 assert_tag :tag => 'th',
246 246 :content => '23',
247 247 :attributes => { :class => 'line-num' },
248 248 :sibling =>
249 249 {
250 250 :tag => 'td' ,
251 251 :content => 'jsmith' ,
252 252 :attributes => { :class => 'author' },
253 253 }
254 254 assert_tag :tag => 'th',
255 255 :content => '23',
256 256 :attributes => { :class => 'line-num' },
257 257 :sibling => { :tag => 'td', :content => /watcher =/ }
258 258 end
259 259
260 260 def test_annotate_at_given_revision
261 261 @repository.fetch_changesets
262 262 @repository.reload
263 263 [2, '400bb8672109', '400', 400].each do |r1|
264 264 get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb']
265 265 assert_response :success
266 266 assert_template 'annotate'
267 267 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
268 268 end
269 269 end
270 270
271 271 def test_annotate_latin_1
272 272 [21, '21', 'adf805632193'].each do |r1|
273 273 get :annotate, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
274 274 assert_response :success
275 275 assert_template 'annotate'
276 276 assert_tag :tag => 'th',
277 277 :content => '1',
278 278 :attributes => { :class => 'line-num' },
279 279 :sibling =>
280 280 {
281 281 :tag => 'td',
282 282 :attributes => { :class => 'revision' },
283 283 :child => { :tag => 'a', :content => '20:709858aafd1b' }
284 284 }
285 285 assert_tag :tag => 'th',
286 286 :content => '1',
287 287 :attributes => { :class => 'line-num' },
288 288 :sibling =>
289 289 {
290 290 :tag => 'td' ,
291 291 :content => 'jsmith' ,
292 292 :attributes => { :class => 'author' },
293 293
294 294 }
295 295 assert_tag :tag => 'th',
296 296 :content => '1',
297 297 :attributes => { :class => 'line-num' },
298 298 :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ }
299 299
300 300 end
301 301 end
302 302
303 303 def test_empty_revision
304 304 @repository.fetch_changesets
305 305 @repository.reload
306 306 ['', ' ', nil].each do |r|
307 307 get :revision, :id => 3, :rev => r
308 308 assert_response 404
309 309 assert_error_tag :content => /was not found/
310 310 end
311 311 end
312 312 else
313 313 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
314 314 def test_fake; assert true end
315 315 end
316 316 end
@@ -1,299 +1,303
1 1 require File.expand_path('../../../../../../test_helper', __FILE__)
2 2 begin
3 3 require 'mocha'
4 4
5 5 class MercurialAdapterTest < ActiveSupport::TestCase
6 6
7 7 HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR
8 8 TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME
9 9 TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
10 10
11 11 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
12 12
13 13 CHAR_1_HEX = "\xc3\x9c"
14 14
15 15 if File.directory?(REPOSITORY_PATH)
16 16 def setup
17 17 @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH)
18 18 @diff_c_support = true
19 19
20 20 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
21 @branch_char_1 = "branch-#{CHAR_1_HEX}-00"
21 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
22 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
22 23 if @tag_char_1.respond_to?(:force_encoding)
23 24 @tag_char_1.force_encoding('UTF-8')
25 @branch_char_0.force_encoding('UTF-8')
24 26 @branch_char_1.force_encoding('UTF-8')
25 27 end
26 28 end
27 29
28 30 def test_hgversion
29 31 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
30 32 "Mercurial Distributed SCM (1.0)\n" => [1,0],
31 33 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
32 34 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
33 35 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
34 36 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
35 37 "(1.6)\n(1.7)\n(1.8)" => [1,6],
36 38 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
37 39
38 40 to_test.each do |s, v|
39 41 test_hgversion_for(s, v)
40 42 end
41 43 end
42 44
43 45 def test_template_path
44 46 to_test = { [0,9,5] => "0.9.5",
45 47 [1,0] => "1.0",
46 48 [] => "1.0",
47 49 [1,0,1] => "1.0",
48 50 [1,7] => "1.0",
49 51 [1,7,1] => "1.0" }
50 52 to_test.each do |v, template|
51 53 test_template_path_for(v, template)
52 54 end
53 55 end
54 56
55 57 def test_info
56 58 [REPOSITORY_PATH, REPOSITORY_PATH + "/",
57 59 REPOSITORY_PATH + "//"].each do |repo|
58 60 adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
59 61 repo_path = adp.info.root_url.gsub(/\\/, "/")
60 62 assert_equal REPOSITORY_PATH, repo_path
61 assert_equal '26', adp.info.lastrev.revision
63 assert_equal '28', adp.info.lastrev.revision
62 64 assert_equal '3ae45e2d177d',adp.info.lastrev.scmid
63 65 end
64 66 end
65 67
66 68 def test_revisions
67 69 revisions = @adapter.revisions(nil, 2, 4)
68 70 assert_equal 3, revisions.size
69 71 assert_equal '2', revisions[0].revision
70 72 assert_equal '400bb8672109', revisions[0].scmid
71 73 assert_equal '4', revisions[2].revision
72 74 assert_equal 'def6d2f1254a', revisions[2].scmid
73 75
74 76 revisions = @adapter.revisions(nil, 2, 4, {:limit => 2})
75 77 assert_equal 2, revisions.size
76 78 assert_equal '2', revisions[0].revision
77 79 assert_equal '400bb8672109', revisions[0].scmid
78 80 end
79 81
80 82 def test_diff
81 83 if @adapter.class.client_version_above?([1, 2])
82 84 assert_nil @adapter.diff(nil, '100000')
83 85 end
84 86 assert_nil @adapter.diff(nil, '100000', '200000')
85 87 [2, '400bb8672109', '400', 400].each do |r1|
86 88 diff1 = @adapter.diff(nil, r1)
87 89 if @diff_c_support
88 90 assert_equal 28, diff1.size
89 91 buf = diff1[24].gsub(/\r\n|\r|\n/, "")
90 92 assert_equal "+ return true unless klass.respond_to?('watched_by')", buf
91 93 else
92 94 assert_equal 0, diff1.size
93 95 end
94 96 [4, 'def6d2f1254a'].each do |r2|
95 97 diff2 = @adapter.diff(nil,r1,r2)
96 98 assert_equal 49, diff2.size
97 99 buf = diff2[41].gsub(/\r\n|\r|\n/, "")
98 100 assert_equal "+class WelcomeController < ApplicationController", buf
99 101 diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
100 102 assert_equal 20, diff3.size
101 103 buf = diff3[12].gsub(/\r\n|\r|\n/, "")
102 104 assert_equal "+ @watched.remove_watcher(user)", buf
103 105 end
104 106 end
105 107 end
106 108
107 109 def test_diff_made_by_revision
108 110 if @diff_c_support
109 111 [24, '24', '4cddb4e45f52'].each do |r1|
110 112 diff1 = @adapter.diff(nil, r1)
111 113 assert_equal 5, diff1.size
112 114 buf = diff1[4].gsub(/\r\n|\r|\n/, "")
113 115 assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf
114 116 end
115 117 end
116 118 end
117 119
118 120 def test_cat
119 121 [2, '400bb8672109', '400', 400].each do |r|
120 122 buf = @adapter.cat('sources/welcome_controller.rb', r)
121 123 assert buf
122 124 lines = buf.split("\r\n")
123 125 assert_equal 25, lines.length
124 126 assert_equal 'class WelcomeController < ApplicationController', lines[17]
125 127 end
126 128 assert_nil @adapter.cat('sources/welcome_controller.rb')
127 129 end
128 130
129 131 def test_annotate
130 132 assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
131 133 [2, '400bb8672109', '400', 400].each do |r|
132 134 ann = @adapter.annotate('sources/welcome_controller.rb', r)
133 135 assert ann
134 136 assert_equal '1', ann.revisions[17].revision
135 137 assert_equal '9d5b5b004199', ann.revisions[17].identifier
136 138 assert_equal 'jsmith', ann.revisions[0].author
137 139 assert_equal 25, ann.lines.length
138 140 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
139 141 end
140 142 end
141 143
142 144 def test_entries
143 145 assert_nil @adapter.entries(nil, '100000')
144 146
145 147 assert_equal 1, @adapter.entries("sources", 3).size
146 148 assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size
147 149
148 150 [2, '400bb8672109', '400', 400].each do |r|
149 151 entries1 = @adapter.entries(nil, r)
150 152 assert entries1
151 153 assert_equal 3, entries1.size
152 154 assert_equal 'sources', entries1[1].name
153 155 assert_equal 'sources', entries1[1].path
154 156 assert_equal 'dir', entries1[1].kind
155 157 readme = entries1[2]
156 158 assert_equal 'README', readme.name
157 159 assert_equal 'README', readme.path
158 160 assert_equal 'file', readme.kind
159 161 assert_equal 27, readme.size
160 162 assert_equal '1', readme.lastrev.revision
161 163 assert_equal '9d5b5b004199', readme.lastrev.identifier
162 164 # 2007-12-14 10:24:01 +0100
163 165 assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
164 166
165 167 entries2 = @adapter.entries('sources', r)
166 168 assert entries2
167 169 assert_equal 2, entries2.size
168 170 assert_equal 'watchers_controller.rb', entries2[0].name
169 171 assert_equal 'sources/watchers_controller.rb', entries2[0].path
170 172 assert_equal 'file', entries2[0].kind
171 173 assert_equal 'welcome_controller.rb', entries2[1].name
172 174 assert_equal 'sources/welcome_controller.rb', entries2[1].path
173 175 assert_equal 'file', entries2[1].kind
174 176 end
175 177 end
176 178
177 179 def test_entries_tag
178 180 entries1 = @adapter.entries(nil, 'tag_test.00')
179 181 assert entries1
180 182 assert_equal 3, entries1.size
181 183 assert_equal 'sources', entries1[1].name
182 184 assert_equal 'sources', entries1[1].path
183 185 assert_equal 'dir', entries1[1].kind
184 186 readme = entries1[2]
185 187 assert_equal 'README', readme.name
186 188 assert_equal 'README', readme.path
187 189 assert_equal 'file', readme.kind
188 190 assert_equal 21, readme.size
189 191 assert_equal '0', readme.lastrev.revision
190 192 assert_equal '0885933ad4f6', readme.lastrev.identifier
191 193 # 2007-12-14 10:22:52 +0100
192 194 assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time
193 195 end
194 196
195 197 def test_entries_branch
196 198 entries1 = @adapter.entries(nil, 'test-branch-00')
197 199 assert entries1
198 200 assert_equal 5, entries1.size
199 201 assert_equal 'sql_escape', entries1[2].name
200 202 assert_equal 'sql_escape', entries1[2].path
201 203 assert_equal 'dir', entries1[2].kind
202 204 readme = entries1[4]
203 205 assert_equal 'README', readme.name
204 206 assert_equal 'README', readme.path
205 207 assert_equal 'file', readme.kind
206 208 assert_equal 365, readme.size
207 209 assert_equal '8', readme.lastrev.revision
208 210 assert_equal 'c51f5bb613cd', readme.lastrev.identifier
209 211 # 2001-02-01 00:00:00 -0900
210 212 assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time
211 213 end
212 214
213 215 def test_locate_on_outdated_repository
214 216 assert_equal 1, @adapter.entries("images", 0).size
215 217 assert_equal 2, @adapter.entries("images").size
216 218 assert_equal 2, @adapter.entries("images", 2).size
217 219 end
218 220
219 221 def test_access_by_nodeid
220 222 path = 'sources/welcome_controller.rb'
221 223 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
222 224 end
223 225
224 226 def test_access_by_fuzzy_nodeid
225 227 path = 'sources/welcome_controller.rb'
226 228 # falls back to nodeid
227 229 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
228 230 end
229 231
230 232 def test_tags
231 233 assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags
232 234 end
233 235
234 236 def test_tagmap
235 237 tm = {
236 238 @tag_char_1 => 'adf805632193',
237 239 'tag_test.00' => '6987191f453a',
238 240 'tag-init-revision' => '0885933ad4f6',
239 241 }
240 242 assert_equal tm, @adapter.tagmap
241 243 end
242 244
243 245 def test_branches
244 246 assert_equal [
245 247 'default',
246 'branch (1)[2]&,%.-3_4',
247 248 @branch_char_1,
249 'branch (1)[2]&,%.-3_4',
250 @branch_char_0,
248 251 'test_branch.latin-1',
249 252 'test-branch-00',
250 253 ], @adapter.branches
251 254 end
252 255
253 256 def test_branchmap
254 257 bm = {
255 258 'default' => '3ae45e2d177d',
256 259 'test_branch.latin-1' => 'c2ffe7da686a',
257 260 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7',
258 261 'test-branch-00' => '3a330eb32958',
259 @branch_char_1 => 'c8d3e4887474',
262 @branch_char_0 => 'c8d3e4887474',
263 @branch_char_1 => '7bbf4c738e71',
260 264 }
261 265 assert_equal bm, @adapter.branchmap
262 266 end
263 267
264 268 def test_path_space
265 269 p = 'README (1)[2]&,%.-3_4'
266 270 [15, '933ca60293d7'].each do |r1|
267 271 assert @adapter.diff(p, r1)
268 272 assert @adapter.cat(p, r1)
269 273 assert_equal 1, @adapter.annotate(p, r1).lines.length
270 274 [25, 'afc61e85bde7'].each do |r2|
271 275 assert @adapter.diff(p, r1, r2)
272 276 end
273 277 end
274 278 end
275 279
276 280 private
277 281
278 282 def test_hgversion_for(hgversion, version)
279 283 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
280 284 assert_equal version, @adapter.class.hgversion
281 285 end
282 286
283 287 def test_template_path_for(version, template)
284 288 assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
285 289 @adapter.class.template_path_for(version)
286 290 assert File.exist?(@adapter.class.template_path_for(version))
287 291 end
288 292 else
289 293 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
290 294 def test_fake; assert true end
291 295 end
292 296 end
293 297
294 298 rescue LoadError
295 299 class MercurialMochaFake < ActiveSupport::TestCase
296 300 def test_fake; assert(false, "Requires mocha to run those tests") end
297 301 end
298 302 end
299 303
@@ -1,259 +1,259
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 # No '..' in the repository path
24 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
25 25
26 26 CHAR_1_HEX = "\xc3\x9c"
27 27
28 28 def setup
29 29 @project = Project.find(3)
30 30 @repository = Repository::Mercurial.create(
31 31 :project => @project,
32 32 :url => REPOSITORY_PATH,
33 33 :path_encoding => 'ISO-8859-1'
34 34 )
35 35 assert @repository
36 36 @char_1 = CHAR_1_HEX.dup
37 37 if @char_1.respond_to?(:force_encoding)
38 38 @char_1.force_encoding('UTF-8')
39 39 end
40 40 end
41 41
42 42 if File.directory?(REPOSITORY_PATH)
43 43 def test_fetch_changesets_from_scratch
44 44 @repository.fetch_changesets
45 45 @repository.reload
46 assert_equal 27, @repository.changesets.count
47 assert_equal 34, @repository.changes.count
46 assert_equal 29, @repository.changesets.count
47 assert_equal 37, @repository.changes.count
48 48 assert_equal "Initial import.\nThe repository contains 3 files.",
49 49 @repository.changesets.find_by_revision('0').comments
50 50 end
51 51
52 52 def test_fetch_changesets_incremental
53 53 @repository.fetch_changesets
54 54 # Remove changesets with revision > 2
55 55 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
56 56 @repository.reload
57 57 assert_equal 3, @repository.changesets.count
58 58
59 59 @repository.fetch_changesets
60 assert_equal 27, @repository.changesets.count
60 assert_equal 29, @repository.changesets.count
61 61 end
62 62
63 63 def test_isodatesec
64 64 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
65 65 if @repository.scm.class.client_version_above?([1, 0])
66 66 @repository.fetch_changesets
67 67 @repository.reload
68 68 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
69 69 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
70 70 end
71 71 end
72 72
73 73 def test_changeset_order_by_revision
74 74 @repository.fetch_changesets
75 75 @repository.reload
76 76
77 77 c0 = @repository.latest_changeset
78 78 c1 = @repository.changesets.find_by_revision('0')
79 79 # sorted by revision (id), not by date
80 80 assert c0.revision.to_i > c1.revision.to_i
81 81 assert c0.committed_on < c1.committed_on
82 82 end
83 83
84 84 def test_latest_changesets
85 85 @repository.fetch_changesets
86 86 @repository.reload
87 87
88 88 # with_limit
89 89 changesets = @repository.latest_changesets('', nil, 2)
90 90 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
91 91
92 92 # with_filepath
93 93 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil)
94 94 assert_equal %w|11 10 9|, changesets.collect(&:revision)
95 95
96 96 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil)
97 97 assert_equal %w|12 9|, changesets.collect(&:revision)
98 98 end
99 99
100 100 def test_copied_files
101 101 @repository.fetch_changesets
102 102 @repository.reload
103 103
104 104 cs1 = @repository.changesets.find_by_revision('13')
105 105 assert_not_nil cs1
106 106 c1 = cs1.changes.sort_by(&:path)
107 107 assert_equal 2, c1.size
108 108
109 109 assert_equal 'A', c1[0].action
110 110 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
111 111 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
112 112
113 113 assert_equal 'A', c1[1].action
114 114 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
115 115 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
116 116
117 117 cs2 = @repository.changesets.find_by_revision('15')
118 118 c2 = cs2.changes
119 119 assert_equal 1, c2.size
120 120
121 121 assert_equal 'A', c2[0].action
122 122 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
123 123 assert_equal '/README', c2[0].from_path
124 124
125 125 cs3 = @repository.changesets.find_by_revision('19')
126 126 c3 = cs3.changes
127 127 assert_equal 1, c3.size
128 128 assert_equal 'A', c3[0].action
129 129 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
130 130 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
131 131 end
132 132
133 133 def test_find_changeset_by_name
134 134 @repository.fetch_changesets
135 135 @repository.reload
136 136 %w|2 400bb8672109 400|.each do |r|
137 137 assert_equal '2', @repository.find_changeset_by_name(r).revision
138 138 end
139 139 end
140 140
141 141 def test_find_changeset_by_invalid_name
142 142 @repository.fetch_changesets
143 143 @repository.reload
144 144 assert_nil @repository.find_changeset_by_name('100000')
145 145 end
146 146
147 147 def test_identifier
148 148 @repository.fetch_changesets
149 149 @repository.reload
150 150 c = @repository.changesets.find_by_revision('2')
151 151 assert_equal c.scmid, c.identifier
152 152 end
153 153
154 154 def test_format_identifier
155 155 @repository.fetch_changesets
156 156 @repository.reload
157 157 c = @repository.changesets.find_by_revision('2')
158 158 assert_equal '2:400bb8672109', c.format_identifier
159 159 end
160 160
161 161 def test_find_changeset_by_empty_name
162 162 @repository.fetch_changesets
163 163 @repository.reload
164 164 ['', ' ', nil].each do |r|
165 165 assert_nil @repository.find_changeset_by_name(r)
166 166 end
167 167 end
168 168
169 169 def test_activities
170 170 c = Changeset.new(:repository => @repository,
171 171 :committed_on => Time.now,
172 172 :revision => '123',
173 173 :scmid => 'abc400bb8672',
174 174 :comments => 'test')
175 175 assert c.event_title.include?('123:abc400bb8672:')
176 176 assert_equal 'abc400bb8672', c.event_url[:rev]
177 177 end
178 178
179 179 def test_latest_changesets_with_limit
180 180 @repository.fetch_changesets
181 181 @repository.reload
182 182 changesets = @repository.latest_changesets('', nil, 2)
183 183 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
184 184 end
185 185
186 186 def test_latest_changesets_with_filepath
187 187 @repository.fetch_changesets
188 188 @repository.reload
189 189 changesets = @repository.latest_changesets('README', nil)
190 assert_equal %w|26 17 8 6 1 0|, changesets.collect(&:revision)
190 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision)
191 191
192 192 path = 'sql_escape/percent%dir/percent%file1.txt'
193 193 changesets = @repository.latest_changesets(path, nil)
194 194 assert_equal %w|11 10 9|, changesets.collect(&:revision)
195 195
196 196 path = 'sql_escape/underscore_dir/understrike_file.txt'
197 197 changesets = @repository.latest_changesets(path, nil)
198 198 assert_equal %w|12 9|, changesets.collect(&:revision)
199 199 end
200 200
201 201 def test_latest_changesets_with_dirpath
202 202 @repository.fetch_changesets
203 203 @repository.reload
204 204 changesets = @repository.latest_changesets('images', nil)
205 205 assert_equal %w|1 0|, changesets.collect(&:revision)
206 206
207 207 path = 'sql_escape/percent%dir'
208 208 changesets = @repository.latest_changesets(path, nil)
209 209 assert_equal %w|13 11 10 9|, changesets.collect(&:revision)
210 210
211 211 path = 'sql_escape/underscore_dir'
212 212 changesets = @repository.latest_changesets(path, nil)
213 213 assert_equal %w|13 12 9|, changesets.collect(&:revision)
214 214 end
215 215
216 216 def test_previous
217 217 @repository.fetch_changesets
218 218 @repository.reload
219 %w|26 3ae45e2d177d 3ae4|.each do |r1|
219 %w|28 3ae45e2d177d 3ae45|.each do |r1|
220 220 changeset = @repository.find_changeset_by_name(r1)
221 %w|25 afc61e85bde7 afc6|.each do |r2|
221 %w|27 7bbf4c738e71 7bbf|.each do |r2|
222 222 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
223 223 end
224 224 end
225 225 end
226 226
227 227 def test_previous_nil
228 228 @repository.fetch_changesets
229 229 @repository.reload
230 230 %w|0 0885933ad4f6 0885|.each do |r1|
231 231 changeset = @repository.find_changeset_by_name(r1)
232 232 assert_nil changeset.previous
233 233 end
234 234 end
235 235
236 236 def test_next
237 237 @repository.fetch_changesets
238 238 @repository.reload
239 %w|25 afc61e85bde7 afc6|.each do |r2|
239 %w|27 7bbf4c738e71 7bbf|.each do |r2|
240 240 changeset = @repository.find_changeset_by_name(r2)
241 %w|26 3ae45e2d177d 3ae4|.each do |r1|
241 %w|28 3ae45e2d177d 3ae45|.each do |r1|
242 242 assert_equal @repository.find_changeset_by_name(r1), changeset.next
243 243 end
244 244 end
245 245 end
246 246
247 247 def test_next_nil
248 248 @repository.fetch_changesets
249 249 @repository.reload
250 %w|26 3ae45e2d177d 3ae4|.each do |r1|
250 %w|28 3ae45e2d177d 3ae45|.each do |r1|
251 251 changeset = @repository.find_changeset_by_name(r1)
252 252 assert_nil changeset.next
253 253 end
254 254 end
255 255 else
256 256 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
257 257 def test_fake; assert true end
258 258 end
259 259 end
General Comments 0
You need to be logged in to leave comments. Login now