##// END OF EJS Templates
scm: mercurial: add latest changesets supporting tag test in unit model test (#1981)....
Toshi MARUYAMA -
r5006:59c791b2e180
parent child
Show More
@@ -1,263 +1,276
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
140 # tag
141 changesets = @repository.latest_changesets('', 'tag_test.00')
142 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
143
144 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
145 assert_equal %w|5 4|, changesets.collect(&:revision)
146
147 changesets = @repository.latest_changesets('sources', 'tag_test.00')
148 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
149
150 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
151 assert_equal %w|4 3|, changesets.collect(&:revision)
139 152 end
140 153
141 154 def test_copied_files
142 155 @repository.fetch_changesets
143 156 @repository.reload
144 157
145 158 cs1 = @repository.changesets.find_by_revision('13')
146 159 assert_not_nil cs1
147 160 c1 = cs1.changes.sort_by(&:path)
148 161 assert_equal 2, c1.size
149 162
150 163 assert_equal 'A', c1[0].action
151 164 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
152 165 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
153 166
154 167 assert_equal 'A', c1[1].action
155 168 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
156 169 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
157 170
158 171 cs2 = @repository.changesets.find_by_revision('15')
159 172 c2 = cs2.changes
160 173 assert_equal 1, c2.size
161 174
162 175 assert_equal 'A', c2[0].action
163 176 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
164 177 assert_equal '/README', c2[0].from_path
165 178
166 179 cs3 = @repository.changesets.find_by_revision('19')
167 180 c3 = cs3.changes
168 181 assert_equal 1, c3.size
169 182 assert_equal 'A', c3[0].action
170 183 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
171 184 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
172 185 end
173 186
174 187 def test_find_changeset_by_name
175 188 @repository.fetch_changesets
176 189 @repository.reload
177 190 %w|2 400bb8672109 400|.each do |r|
178 191 assert_equal '2', @repository.find_changeset_by_name(r).revision
179 192 end
180 193 end
181 194
182 195 def test_find_changeset_by_invalid_name
183 196 @repository.fetch_changesets
184 197 @repository.reload
185 198 assert_nil @repository.find_changeset_by_name('100000')
186 199 end
187 200
188 201 def test_identifier
189 202 @repository.fetch_changesets
190 203 @repository.reload
191 204 c = @repository.changesets.find_by_revision('2')
192 205 assert_equal c.scmid, c.identifier
193 206 end
194 207
195 208 def test_format_identifier
196 209 @repository.fetch_changesets
197 210 @repository.reload
198 211 c = @repository.changesets.find_by_revision('2')
199 212 assert_equal '2:400bb8672109', c.format_identifier
200 213 end
201 214
202 215 def test_find_changeset_by_empty_name
203 216 @repository.fetch_changesets
204 217 @repository.reload
205 218 ['', ' ', nil].each do |r|
206 219 assert_nil @repository.find_changeset_by_name(r)
207 220 end
208 221 end
209 222
210 223 def test_activities
211 224 c = Changeset.new(:repository => @repository,
212 225 :committed_on => Time.now,
213 226 :revision => '123',
214 227 :scmid => 'abc400bb8672',
215 228 :comments => 'test')
216 229 assert c.event_title.include?('123:abc400bb8672:')
217 230 assert_equal 'abc400bb8672', c.event_url[:rev]
218 231 end
219 232
220 233 def test_previous
221 234 @repository.fetch_changesets
222 235 @repository.reload
223 236 %w|28 3ae45e2d177d 3ae45|.each do |r1|
224 237 changeset = @repository.find_changeset_by_name(r1)
225 238 %w|27 7bbf4c738e71 7bbf|.each do |r2|
226 239 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
227 240 end
228 241 end
229 242 end
230 243
231 244 def test_previous_nil
232 245 @repository.fetch_changesets
233 246 @repository.reload
234 247 %w|0 0885933ad4f6 0885|.each do |r1|
235 248 changeset = @repository.find_changeset_by_name(r1)
236 249 assert_nil changeset.previous
237 250 end
238 251 end
239 252
240 253 def test_next
241 254 @repository.fetch_changesets
242 255 @repository.reload
243 256 %w|27 7bbf4c738e71 7bbf|.each do |r2|
244 257 changeset = @repository.find_changeset_by_name(r2)
245 258 %w|28 3ae45e2d177d 3ae45|.each do |r1|
246 259 assert_equal @repository.find_changeset_by_name(r1), changeset.next
247 260 end
248 261 end
249 262 end
250 263
251 264 def test_next_nil
252 265 @repository.fetch_changesets
253 266 @repository.reload
254 267 %w|28 3ae45e2d177d 3ae45|.each do |r1|
255 268 changeset = @repository.find_changeset_by_name(r1)
256 269 assert_nil changeset.next
257 270 end
258 271 end
259 272 else
260 273 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
261 274 def test_fake; assert true end
262 275 end
263 276 end
General Comments 0
You need to be logged in to leave comments. Login now