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