##// END OF EJS Templates
Merged r7643 from trunk...
Toshi MARUYAMA -
r7527:4104741383e1
parent child
Show More
@@ -1,293 +1,295
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositoryMercurialTest < ActiveSupport::TestCase
20 class RepositoryMercurialTest < ActiveSupport::TestCase
21 fixtures :projects
21 fixtures :projects
22
22
23 # No '..' in the repository path
23 # No '..' in the repository path
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
25
25
26 CHAR_1_HEX = "\xc3\x9c"
26 CHAR_1_HEX = "\xc3\x9c"
27
27
28 if File.directory?(REPOSITORY_PATH)
28 if File.directory?(REPOSITORY_PATH)
29
29
30 def setup
30 def setup
31 klass = Repository::Mercurial
31 klass = Repository::Mercurial
32 assert_equal "Mercurial", klass.scm_name
32 assert_equal "Mercurial", klass.scm_name
33 assert klass.scm_adapter_class
33 assert klass.scm_adapter_class
34 assert_not_equal "", klass.scm_command
34 assert_not_equal "", klass.scm_command
35 assert_equal true, klass.scm_available
35 assert_equal true, klass.scm_available
36
36
37 @project = Project.find(3)
37 @project = Project.find(3)
38 @repository = Repository::Mercurial.create(
38 @repository = Repository::Mercurial.create(
39 :project => @project,
39 :project => @project,
40 :url => REPOSITORY_PATH,
40 :url => REPOSITORY_PATH,
41 :path_encoding => 'ISO-8859-1'
41 :path_encoding => 'ISO-8859-1'
42 )
42 )
43 assert @repository
43 assert @repository
44 @char_1 = CHAR_1_HEX.dup
44 @char_1 = CHAR_1_HEX.dup
45 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
45 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
46 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
46 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
47 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
47 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
48 if @char_1.respond_to?(:force_encoding)
48 if @char_1.respond_to?(:force_encoding)
49 @char_1.force_encoding('UTF-8')
49 @char_1.force_encoding('UTF-8')
50 @tag_char_1.force_encoding('UTF-8')
50 @tag_char_1.force_encoding('UTF-8')
51 @branch_char_0.force_encoding('UTF-8')
51 @branch_char_0.force_encoding('UTF-8')
52 @branch_char_1.force_encoding('UTF-8')
52 @branch_char_1.force_encoding('UTF-8')
53 end
53 end
54 end
54 end
55
55
56 def test_fetch_changesets_from_scratch
56 def test_fetch_changesets_from_scratch
57 @repository.fetch_changesets
57 @repository.fetch_changesets
58 @repository.reload
58 @repository.reload
59 assert_equal 29, @repository.changesets.count
59 assert_equal 29, @repository.changesets.count
60 assert_equal 37, @repository.changes.count
60 assert_equal 37, @repository.changes.count
61 assert_equal "Initial import.\nThe repository contains 3 files.",
61 assert_equal "Initial import.\nThe repository contains 3 files.",
62 @repository.changesets.find_by_revision('0').comments
62 @repository.changesets.find_by_revision('0').comments
63 end
63 end
64
64
65 def test_fetch_changesets_incremental
65 def test_fetch_changesets_incremental
66 @repository.fetch_changesets
66 @repository.fetch_changesets
67 # Remove changesets with revision > 2
67 # Remove changesets with revision > 2
68 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
68 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
69 @repository.reload
69 @repository.reload
70 assert_equal 3, @repository.changesets.count
70 assert_equal 3, @repository.changesets.count
71
71
72 @repository.fetch_changesets
72 @repository.fetch_changesets
73 assert_equal 29, @repository.changesets.count
73 assert_equal 29, @repository.changesets.count
74 end
74 end
75
75
76 def test_isodatesec
76 def test_isodatesec
77 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
77 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
78 if @repository.scm.class.client_version_above?([1, 0])
78 if @repository.scm.class.client_version_above?([1, 0])
79 @repository.fetch_changesets
79 @repository.fetch_changesets
80 @repository.reload
80 @repository.reload
81 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
81 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
82 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
82 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
83 end
83 end
84 end
84 end
85
85
86 def test_changeset_order_by_revision
86 def test_changeset_order_by_revision
87 @repository.fetch_changesets
87 @repository.fetch_changesets
88 @repository.reload
88 @repository.reload
89
89
90 c0 = @repository.latest_changeset
90 c0 = @repository.latest_changeset
91 c1 = @repository.changesets.find_by_revision('0')
91 c1 = @repository.changesets.find_by_revision('0')
92 # sorted by revision (id), not by date
92 # sorted by revision (id), not by date
93 assert c0.revision.to_i > c1.revision.to_i
93 assert c0.revision.to_i > c1.revision.to_i
94 assert c0.committed_on < c1.committed_on
94 assert c0.committed_on < c1.committed_on
95 end
95 end
96
96
97 def test_latest_changesets
97 def test_latest_changesets
98 @repository.fetch_changesets
98 @repository.fetch_changesets
99 @repository.reload
99 @repository.reload
100
100
101 # with_limit
101 # with_limit
102 changesets = @repository.latest_changesets('', nil, 2)
102 changesets = @repository.latest_changesets('', nil, 2)
103 assert_equal %w|28 27|, changesets.collect(&:revision)
103 assert_equal %w|28 27|, changesets.collect(&:revision)
104
104
105 # with_filepath
105 # with_filepath
106 changesets = @repository.latest_changesets(
106 changesets = @repository.latest_changesets(
107 '/sql_escape/percent%dir/percent%file1.txt', nil)
107 '/sql_escape/percent%dir/percent%file1.txt', nil)
108 assert_equal %w|11 10 9|, changesets.collect(&:revision)
108 assert_equal %w|11 10 9|, changesets.collect(&:revision)
109
109
110 changesets = @repository.latest_changesets(
110 changesets = @repository.latest_changesets(
111 '/sql_escape/underscore_dir/understrike_file.txt', nil)
111 '/sql_escape/underscore_dir/understrike_file.txt', nil)
112 assert_equal %w|12 9|, changesets.collect(&:revision)
112 assert_equal %w|12 9|, changesets.collect(&:revision)
113
113
114 changesets = @repository.latest_changesets('README', nil)
114 changesets = @repository.latest_changesets('README', nil)
115 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision)
115 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision)
116
116
117 changesets = @repository.latest_changesets('README','8')
117 changesets = @repository.latest_changesets('README','8')
118 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
118 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
119
119
120 changesets = @repository.latest_changesets('README','8', 2)
120 changesets = @repository.latest_changesets('README','8', 2)
121 assert_equal %w|8 6|, changesets.collect(&:revision)
121 assert_equal %w|8 6|, changesets.collect(&:revision)
122
122
123 # with_dirpath
123 # with_dirpath
124 changesets = @repository.latest_changesets('images', nil)
124 changesets = @repository.latest_changesets('images', nil)
125 assert_equal %w|1 0|, changesets.collect(&:revision)
125 assert_equal %w|1 0|, changesets.collect(&:revision)
126
126
127 path = 'sql_escape/percent%dir'
127 path = 'sql_escape/percent%dir'
128 changesets = @repository.latest_changesets(path, nil)
128 changesets = @repository.latest_changesets(path, nil)
129 assert_equal %w|13 11 10 9|, changesets.collect(&:revision)
129 assert_equal %w|13 11 10 9|, changesets.collect(&:revision)
130
130
131 changesets = @repository.latest_changesets(path, '11')
131 changesets = @repository.latest_changesets(path, '11')
132 assert_equal %w|11 10 9|, changesets.collect(&:revision)
132 assert_equal %w|11 10 9|, changesets.collect(&:revision)
133
133
134 changesets = @repository.latest_changesets(path, '11', 2)
134 changesets = @repository.latest_changesets(path, '11', 2)
135 assert_equal %w|11 10|, changesets.collect(&:revision)
135 assert_equal %w|11 10|, changesets.collect(&:revision)
136
136
137 path = 'sql_escape/underscore_dir'
137 path = 'sql_escape/underscore_dir'
138 changesets = @repository.latest_changesets(path, nil)
138 changesets = @repository.latest_changesets(path, nil)
139 assert_equal %w|13 12 9|, changesets.collect(&:revision)
139 assert_equal %w|13 12 9|, changesets.collect(&:revision)
140
140
141 changesets = @repository.latest_changesets(path, '12')
141 changesets = @repository.latest_changesets(path, '12')
142 assert_equal %w|12 9|, changesets.collect(&:revision)
142 assert_equal %w|12 9|, changesets.collect(&:revision)
143
143
144 changesets = @repository.latest_changesets(path, '12', 1)
144 changesets = @repository.latest_changesets(path, '12', 1)
145 assert_equal %w|12|, changesets.collect(&:revision)
145 assert_equal %w|12|, changesets.collect(&:revision)
146
146
147 # tag
147 # tag
148 changesets = @repository.latest_changesets('', 'tag_test.00')
148 changesets = @repository.latest_changesets('', 'tag_test.00')
149 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
149 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
150
150
151 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
151 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
152 assert_equal %w|5 4|, changesets.collect(&:revision)
152 assert_equal %w|5 4|, changesets.collect(&:revision)
153
153
154 changesets = @repository.latest_changesets('sources', 'tag_test.00')
154 changesets = @repository.latest_changesets('sources', 'tag_test.00')
155 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
155 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
156
156
157 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
157 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
158 assert_equal %w|4 3|, changesets.collect(&:revision)
158 assert_equal %w|4 3|, changesets.collect(&:revision)
159
159
160 # named branch
160 # named branch
161 changesets = @repository.latest_changesets('', @branch_char_1)
161 if @repository.scm.class.client_version_above?([1, 6])
162 assert_equal %w|27 26|, changesets.collect(&:revision)
162 changesets = @repository.latest_changesets('', @branch_char_1)
163 assert_equal %w|27 26|, changesets.collect(&:revision)
164 end
163
165
164 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
166 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
165 assert_equal %w|27|, changesets.collect(&:revision)
167 assert_equal %w|27|, changesets.collect(&:revision)
166 end
168 end
167
169
168 def test_copied_files
170 def test_copied_files
169 @repository.fetch_changesets
171 @repository.fetch_changesets
170 @repository.reload
172 @repository.reload
171
173
172 cs1 = @repository.changesets.find_by_revision('13')
174 cs1 = @repository.changesets.find_by_revision('13')
173 assert_not_nil cs1
175 assert_not_nil cs1
174 c1 = cs1.changes.sort_by(&:path)
176 c1 = cs1.changes.sort_by(&:path)
175 assert_equal 2, c1.size
177 assert_equal 2, c1.size
176
178
177 assert_equal 'A', c1[0].action
179 assert_equal 'A', c1[0].action
178 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
180 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
179 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
181 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
180 assert_equal '3a330eb32958', c1[0].from_revision
182 assert_equal '3a330eb32958', c1[0].from_revision
181
183
182 assert_equal 'A', c1[1].action
184 assert_equal 'A', c1[1].action
183 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
185 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
184 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
186 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
185
187
186 cs2 = @repository.changesets.find_by_revision('15')
188 cs2 = @repository.changesets.find_by_revision('15')
187 c2 = cs2.changes
189 c2 = cs2.changes
188 assert_equal 1, c2.size
190 assert_equal 1, c2.size
189
191
190 assert_equal 'A', c2[0].action
192 assert_equal 'A', c2[0].action
191 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
193 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
192 assert_equal '/README', c2[0].from_path
194 assert_equal '/README', c2[0].from_path
193 assert_equal '933ca60293d7', c2[0].from_revision
195 assert_equal '933ca60293d7', c2[0].from_revision
194
196
195 cs3 = @repository.changesets.find_by_revision('19')
197 cs3 = @repository.changesets.find_by_revision('19')
196 c3 = cs3.changes
198 c3 = cs3.changes
197 assert_equal 1, c3.size
199 assert_equal 1, c3.size
198 assert_equal 'A', c3[0].action
200 assert_equal 'A', c3[0].action
199 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
201 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
200 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
202 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
201 assert_equal '5d9891a1b425', c3[0].from_revision
203 assert_equal '5d9891a1b425', c3[0].from_revision
202 end
204 end
203
205
204 def test_find_changeset_by_name
206 def test_find_changeset_by_name
205 @repository.fetch_changesets
207 @repository.fetch_changesets
206 @repository.reload
208 @repository.reload
207 %w|2 400bb8672109 400|.each do |r|
209 %w|2 400bb8672109 400|.each do |r|
208 assert_equal '2', @repository.find_changeset_by_name(r).revision
210 assert_equal '2', @repository.find_changeset_by_name(r).revision
209 end
211 end
210 end
212 end
211
213
212 def test_find_changeset_by_invalid_name
214 def test_find_changeset_by_invalid_name
213 @repository.fetch_changesets
215 @repository.fetch_changesets
214 @repository.reload
216 @repository.reload
215 assert_nil @repository.find_changeset_by_name('100000')
217 assert_nil @repository.find_changeset_by_name('100000')
216 end
218 end
217
219
218 def test_identifier
220 def test_identifier
219 @repository.fetch_changesets
221 @repository.fetch_changesets
220 @repository.reload
222 @repository.reload
221 c = @repository.changesets.find_by_revision('2')
223 c = @repository.changesets.find_by_revision('2')
222 assert_equal c.scmid, c.identifier
224 assert_equal c.scmid, c.identifier
223 end
225 end
224
226
225 def test_format_identifier
227 def test_format_identifier
226 @repository.fetch_changesets
228 @repository.fetch_changesets
227 @repository.reload
229 @repository.reload
228 c = @repository.changesets.find_by_revision('2')
230 c = @repository.changesets.find_by_revision('2')
229 assert_equal '2:400bb8672109', c.format_identifier
231 assert_equal '2:400bb8672109', c.format_identifier
230 end
232 end
231
233
232 def test_find_changeset_by_empty_name
234 def test_find_changeset_by_empty_name
233 @repository.fetch_changesets
235 @repository.fetch_changesets
234 @repository.reload
236 @repository.reload
235 ['', ' ', nil].each do |r|
237 ['', ' ', nil].each do |r|
236 assert_nil @repository.find_changeset_by_name(r)
238 assert_nil @repository.find_changeset_by_name(r)
237 end
239 end
238 end
240 end
239
241
240 def test_activities
242 def test_activities
241 c = Changeset.new(:repository => @repository,
243 c = Changeset.new(:repository => @repository,
242 :committed_on => Time.now,
244 :committed_on => Time.now,
243 :revision => '123',
245 :revision => '123',
244 :scmid => 'abc400bb8672',
246 :scmid => 'abc400bb8672',
245 :comments => 'test')
247 :comments => 'test')
246 assert c.event_title.include?('123:abc400bb8672:')
248 assert c.event_title.include?('123:abc400bb8672:')
247 assert_equal 'abc400bb8672', c.event_url[:rev]
249 assert_equal 'abc400bb8672', c.event_url[:rev]
248 end
250 end
249
251
250 def test_previous
252 def test_previous
251 @repository.fetch_changesets
253 @repository.fetch_changesets
252 @repository.reload
254 @repository.reload
253 %w|28 3ae45e2d177d 3ae45|.each do |r1|
255 %w|28 3ae45e2d177d 3ae45|.each do |r1|
254 changeset = @repository.find_changeset_by_name(r1)
256 changeset = @repository.find_changeset_by_name(r1)
255 %w|27 7bbf4c738e71 7bbf|.each do |r2|
257 %w|27 7bbf4c738e71 7bbf|.each do |r2|
256 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
258 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
257 end
259 end
258 end
260 end
259 end
261 end
260
262
261 def test_previous_nil
263 def test_previous_nil
262 @repository.fetch_changesets
264 @repository.fetch_changesets
263 @repository.reload
265 @repository.reload
264 %w|0 0885933ad4f6 0885|.each do |r1|
266 %w|0 0885933ad4f6 0885|.each do |r1|
265 changeset = @repository.find_changeset_by_name(r1)
267 changeset = @repository.find_changeset_by_name(r1)
266 assert_nil changeset.previous
268 assert_nil changeset.previous
267 end
269 end
268 end
270 end
269
271
270 def test_next
272 def test_next
271 @repository.fetch_changesets
273 @repository.fetch_changesets
272 @repository.reload
274 @repository.reload
273 %w|27 7bbf4c738e71 7bbf|.each do |r2|
275 %w|27 7bbf4c738e71 7bbf|.each do |r2|
274 changeset = @repository.find_changeset_by_name(r2)
276 changeset = @repository.find_changeset_by_name(r2)
275 %w|28 3ae45e2d177d 3ae45|.each do |r1|
277 %w|28 3ae45e2d177d 3ae45|.each do |r1|
276 assert_equal @repository.find_changeset_by_name(r1), changeset.next
278 assert_equal @repository.find_changeset_by_name(r1), changeset.next
277 end
279 end
278 end
280 end
279 end
281 end
280
282
281 def test_next_nil
283 def test_next_nil
282 @repository.fetch_changesets
284 @repository.fetch_changesets
283 @repository.reload
285 @repository.reload
284 %w|28 3ae45e2d177d 3ae45|.each do |r1|
286 %w|28 3ae45e2d177d 3ae45|.each do |r1|
285 changeset = @repository.find_changeset_by_name(r1)
287 changeset = @repository.find_changeset_by_name(r1)
286 assert_nil changeset.next
288 assert_nil changeset.next
287 end
289 end
288 end
290 end
289 else
291 else
290 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
292 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
291 def test_fake; assert true end
293 def test_fake; assert true end
292 end
294 end
293 end
295 end
General Comments 0
You need to be logged in to leave comments. Login now