comparison .svn/pristine/0c/0c9dc58fe829b59060fa2ba2bfeb1db760e787c2.svn-base @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents
children
comparison
equal deleted inserted replaced
1516:b450a9d58aed 1517:dffacf8a6908
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../test_helper', __FILE__)
19
20 class RepositoryBazaarTest < ActiveSupport::TestCase
21 fixtures :projects
22
23 include Redmine::I18n
24
25 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
26 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
27 NUM_REV = 4
28
29 REPOSITORY_PATH_NON_ASCII = Rails.root.join(REPOSITORY_PATH + '/' + 'non_ascii').to_s
30
31 # Bazaar core does not support xml output such as Subversion and Mercurial.
32 # "bzr" command output and command line parameter depend on locale.
33 # So, non ASCII path tests cannot run independent locale.
34 #
35 # If you want to run Bazaar non ASCII path tests on Linux *Ruby 1.9*,
36 # you need to set locale character set "ISO-8859-1".
37 # E.g. "LANG=en_US.ISO-8859-1".
38 # On Linux other platforms (e.g. Ruby 1.8, JRuby),
39 # you need to set "RUN_LATIN1_OUTPUT_TEST = true" manually.
40 #
41 # On Windows, because it is too hard to change system locale,
42 # you cannot run Bazaar non ASCII path tests.
43 #
44 RUN_LATIN1_OUTPUT_TEST = (RUBY_PLATFORM != 'java' &&
45 REPOSITORY_PATH.respond_to?(:force_encoding) &&
46 Encoding.locale_charmap == "ISO-8859-1")
47
48 CHAR_1_UTF8_HEX = "\xc3\x9c"
49 CHAR_1_LATIN1_HEX = "\xdc"
50
51 def setup
52 @project = Project.find(3)
53 @repository = Repository::Bazaar.create(
54 :project => @project, :url => REPOSITORY_PATH_TRUNK,
55 :log_encoding => 'UTF-8')
56 assert @repository
57 @char_1_utf8 = CHAR_1_UTF8_HEX.dup
58 @char_1_ascii8bit = CHAR_1_LATIN1_HEX.dup
59 if @char_1_utf8.respond_to?(:force_encoding)
60 @char_1_utf8.force_encoding('UTF-8')
61 @char_1_ascii8bit.force_encoding('ASCII-8BIT')
62 end
63 end
64
65 def test_blank_path_to_repository_error_message
66 set_language_if_valid 'en'
67 repo = Repository::Bazaar.new(
68 :project => @project,
69 :identifier => 'test',
70 :log_encoding => 'UTF-8'
71 )
72 assert !repo.save
73 assert_include "Path to repository can't be blank",
74 repo.errors.full_messages
75 end
76
77 def test_blank_path_to_repository_error_message_fr
78 set_language_if_valid 'fr'
79 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
80 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
81 repo = Repository::Bazaar.new(
82 :project => @project,
83 :url => "",
84 :identifier => 'test',
85 :log_encoding => 'UTF-8'
86 )
87 assert !repo.save
88 assert_include str, repo.errors.full_messages
89 end
90
91 if File.directory?(REPOSITORY_PATH_TRUNK)
92 def test_fetch_changesets_from_scratch
93 assert_equal 0, @repository.changesets.count
94 @repository.fetch_changesets
95 @project.reload
96
97 assert_equal NUM_REV, @repository.changesets.count
98 assert_equal 9, @repository.filechanges.count
99 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
100 end
101
102 def test_fetch_changesets_incremental
103 assert_equal 0, @repository.changesets.count
104 @repository.fetch_changesets
105 @project.reload
106 assert_equal NUM_REV, @repository.changesets.count
107 # Remove changesets with revision > 5
108 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
109 @project.reload
110 @repository.reload
111 assert_equal 2, @repository.changesets.count
112
113 @repository.fetch_changesets
114 @project.reload
115 assert_equal NUM_REV, @repository.changesets.count
116 end
117
118 def test_entries
119 entries = @repository.entries
120 assert_kind_of Redmine::Scm::Adapters::Entries, entries
121 assert_equal 2, entries.size
122
123 assert_equal 'dir', entries[0].kind
124 assert_equal 'directory', entries[0].name
125 assert_equal 'directory', entries[0].path
126
127 assert_equal 'file', entries[1].kind
128 assert_equal 'doc-mkdir.txt', entries[1].name
129 assert_equal 'doc-mkdir.txt', entries[1].path
130 end
131
132 def test_entries_in_subdirectory
133 entries = @repository.entries('directory')
134 assert_equal 3, entries.size
135
136 assert_equal 'file', entries.last.kind
137 assert_equal 'edit.png', entries.last.name
138 assert_equal 'directory/edit.png', entries.last.path
139 end
140
141 def test_previous
142 assert_equal 0, @repository.changesets.count
143 @repository.fetch_changesets
144 @project.reload
145 assert_equal NUM_REV, @repository.changesets.count
146 changeset = @repository.find_changeset_by_name('3')
147 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
148 end
149
150 def test_previous_nil
151 assert_equal 0, @repository.changesets.count
152 @repository.fetch_changesets
153 @project.reload
154 assert_equal NUM_REV, @repository.changesets.count
155 changeset = @repository.find_changeset_by_name('1')
156 assert_nil changeset.previous
157 end
158
159 def test_next
160 assert_equal 0, @repository.changesets.count
161 @repository.fetch_changesets
162 @project.reload
163 assert_equal NUM_REV, @repository.changesets.count
164 changeset = @repository.find_changeset_by_name('2')
165 assert_equal @repository.find_changeset_by_name('3'), changeset.next
166 end
167
168 def test_next_nil
169 assert_equal 0, @repository.changesets.count
170 @repository.fetch_changesets
171 @project.reload
172 assert_equal NUM_REV, @repository.changesets.count
173 changeset = @repository.find_changeset_by_name('4')
174 assert_nil changeset.next
175 end
176
177 if File.directory?(REPOSITORY_PATH_NON_ASCII) && RUN_LATIN1_OUTPUT_TEST
178 def test_cat_latin1_path
179 latin1_repo = create_latin1_repo
180 buf = latin1_repo.cat(
181 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2)
182 assert buf
183 lines = buf.split("\n")
184 assert_equal 2, lines.length
185 assert_equal 'It is written in Python.', lines[1]
186
187 buf = latin1_repo.cat(
188 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2)
189 assert buf
190 lines = buf.split("\n")
191 assert_equal 1, lines.length
192 assert_equal "test-#{@char_1_ascii8bit}.txt", lines[0]
193 end
194
195 def test_annotate_latin1_path
196 latin1_repo = create_latin1_repo
197 ann1 = latin1_repo.annotate(
198 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2)
199 assert_equal 2, ann1.lines.size
200 assert_equal '2', ann1.revisions[0].identifier
201 assert_equal 'test00@', ann1.revisions[0].author
202 assert_equal 'It is written in Python.', ann1.lines[1]
203 ann2 = latin1_repo.annotate(
204 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2)
205 assert_equal 1, ann2.lines.size
206 assert_equal '2', ann2.revisions[0].identifier
207 assert_equal 'test00@', ann2.revisions[0].author
208 assert_equal "test-#{@char_1_ascii8bit}.txt", ann2.lines[0]
209 end
210
211 def test_diff_latin1_path
212 latin1_repo = create_latin1_repo
213 diff1 = latin1_repo.diff(
214 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2, 1)
215 assert_equal 7, diff1.size
216 buf = diff1[5].gsub(/\r\n|\r|\n/, "")
217 assert_equal "+test-#{@char_1_ascii8bit}.txt", buf
218 end
219
220 def test_entries_latin1_path
221 latin1_repo = create_latin1_repo
222 entries = latin1_repo.entries("test-#{@char_1_utf8}-dir", 2)
223 assert_kind_of Redmine::Scm::Adapters::Entries, entries
224 assert_equal 3, entries.size
225 assert_equal 'file', entries[1].kind
226 assert_equal "test-#{@char_1_utf8}-1.txt", entries[0].name
227 assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", entries[0].path
228 end
229
230 def test_entry_latin1_path
231 latin1_repo = create_latin1_repo
232 ["test-#{@char_1_utf8}-dir",
233 "/test-#{@char_1_utf8}-dir",
234 "/test-#{@char_1_utf8}-dir/"
235 ].each do |path|
236 entry = latin1_repo.entry(path, 2)
237 assert_equal "test-#{@char_1_utf8}-dir", entry.path
238 assert_equal "dir", entry.kind
239 end
240 ["test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt",
241 "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt"
242 ].each do |path|
243 entry = latin1_repo.entry(path, 2)
244 assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt",
245 entry.path
246 assert_equal "file", entry.kind
247 end
248 end
249
250 def test_changeset_latin1_path
251 latin1_repo = create_latin1_repo
252 assert_equal 0, latin1_repo.changesets.count
253 latin1_repo.fetch_changesets
254 @project.reload
255 assert_equal 3, latin1_repo.changesets.count
256
257 cs2 = latin1_repo.changesets.find_by_revision('2')
258 assert_not_nil cs2
259 assert_equal "test-#{@char_1_utf8}", cs2.comments
260 c2 = cs2.filechanges.sort_by(&:path)
261 assert_equal 4, c2.size
262 assert_equal 'A', c2[0].action
263 assert_equal "/test-#{@char_1_utf8}-dir/", c2[0].path
264 assert_equal 'A', c2[1].action
265 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", c2[1].path
266 assert_equal 'A', c2[2].action
267 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c2[2].path
268 assert_equal 'A', c2[3].action
269 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c2[3].path
270
271 cs3 = latin1_repo.changesets.find_by_revision('3')
272 assert_not_nil cs3
273 assert_equal "modify, move and delete #{@char_1_utf8} files", cs3.comments
274 c3 = cs3.filechanges.sort_by(&:path)
275 assert_equal 3, c3.size
276 assert_equal 'M', c3[0].action
277 assert_equal "/test-#{@char_1_utf8}-1.txt", c3[0].path
278 assert_equal 'D', c3[1].action
279 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c3[1].path
280 assert_equal 'M', c3[2].action
281 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c3[2].path
282 end
283 else
284 msg = "Bazaar non ASCII output test cannot run this environment." + "\n"
285 if msg.respond_to?(:force_encoding)
286 msg += "Encoding.locale_charmap: " + Encoding.locale_charmap + "\n"
287 end
288 puts msg
289 end
290
291 private
292
293 def create_latin1_repo
294 repo = Repository::Bazaar.create(
295 :project => @project,
296 :identifier => 'latin1',
297 :url => REPOSITORY_PATH_NON_ASCII,
298 :log_encoding => 'ISO-8859-1'
299 )
300 assert repo
301 repo
302 end
303 else
304 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
305 def test_fake; assert true end
306 end
307 end