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