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