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