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