@@ -26,12 +26,40 class RepositoryBazaarTest < ActiveSupport::TestCase | |||
|
26 | 26 | REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk") |
|
27 | 27 | NUM_REV = 4 |
|
28 | 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, tests cannot run independent locale. | |
|
34 | # | |
|
35 | # If you want to run Bazaar non ASCII path tests on *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 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 | ||
|
29 | 51 | def setup |
|
30 | 52 | @project = Project.find(3) |
|
31 | 53 | @repository = Repository::Bazaar.create( |
|
32 | 54 | :project => @project, :url => REPOSITORY_PATH_TRUNK, |
|
33 | 55 | :log_encoding => 'UTF-8') |
|
34 | 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 | |
|
35 | 63 | end |
|
36 | 64 | |
|
37 | 65 | def test_blank_path_to_repository_error_message |
@@ -144,6 +172,133 class RepositoryBazaarTest < ActiveSupport::TestCase | |||
|
144 | 172 | changeset = @repository.find_changeset_by_name('4') |
|
145 | 173 | assert_nil changeset.next |
|
146 | 174 | end |
|
175 | ||
|
176 | if File.directory?(REPOSITORY_PATH_NON_ASCII) && RUN_LATIN1_OUTPUT_TEST | |
|
177 | def test_cat_latin1_path | |
|
178 | latin1_repo = create_latin1_repo | |
|
179 | buf = latin1_repo.cat( | |
|
180 | "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2) | |
|
181 | assert buf | |
|
182 | lines = buf.split("\n") | |
|
183 | assert_equal 2, lines.length | |
|
184 | assert_equal 'It is written in Python.', lines[1] | |
|
185 | ||
|
186 | buf = latin1_repo.cat( | |
|
187 | "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2) | |
|
188 | assert buf | |
|
189 | lines = buf.split("\n") | |
|
190 | assert_equal 1, lines.length | |
|
191 | assert_equal "test-#{@char_1_ascii8bit}.txt", lines[0] | |
|
192 | end | |
|
193 | ||
|
194 | def test_annotate_latin1_path | |
|
195 | latin1_repo = create_latin1_repo | |
|
196 | ann1 = latin1_repo.annotate( | |
|
197 | "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2) | |
|
198 | assert_equal 2, ann1.lines.size | |
|
199 | assert_equal '2', ann1.revisions[0].identifier | |
|
200 | assert_equal 'test00@', ann1.revisions[0].author | |
|
201 | assert_equal 'It is written in Python.', ann1.lines[1] | |
|
202 | ann2 = latin1_repo.annotate( | |
|
203 | "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2) | |
|
204 | assert_equal 1, ann2.lines.size | |
|
205 | assert_equal '2', ann2.revisions[0].identifier | |
|
206 | assert_equal 'test00@', ann2.revisions[0].author | |
|
207 | assert_equal "test-#{@char_1_ascii8bit}.txt", ann2.lines[0] | |
|
208 | end | |
|
209 | ||
|
210 | def test_diff_latin1_path | |
|
211 | latin1_repo = create_latin1_repo | |
|
212 | diff1 = latin1_repo.diff( | |
|
213 | "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2, 1) | |
|
214 | assert_equal 7, diff1.size | |
|
215 | buf = diff1[5].gsub(/\r\n|\r|\n/, "") | |
|
216 | assert_equal "+test-#{@char_1_ascii8bit}.txt", buf | |
|
217 | end | |
|
218 | ||
|
219 | def test_entries_latin1_path | |
|
220 | latin1_repo = create_latin1_repo | |
|
221 | entries = latin1_repo.entries("test-#{@char_1_utf8}-dir", 2) | |
|
222 | assert_kind_of Redmine::Scm::Adapters::Entries, entries | |
|
223 | assert_equal 3, entries.size | |
|
224 | assert_equal 'file', entries[1].kind | |
|
225 | assert_equal "test-#{@char_1_utf8}-1.txt", entries[0].name | |
|
226 | assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", entries[0].path | |
|
227 | end | |
|
228 | ||
|
229 | def test_entry_latin1_path | |
|
230 | latin1_repo = create_latin1_repo | |
|
231 | ["test-#{@char_1_utf8}-dir", | |
|
232 | "/test-#{@char_1_utf8}-dir", | |
|
233 | "/test-#{@char_1_utf8}-dir/" | |
|
234 | ].each do |path| | |
|
235 | entry = latin1_repo.entry(path, 2) | |
|
236 | assert_equal "test-#{@char_1_utf8}-dir", entry.path | |
|
237 | assert_equal "dir", entry.kind | |
|
238 | end | |
|
239 | ["test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", | |
|
240 | "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt" | |
|
241 | ].each do |path| | |
|
242 | entry = latin1_repo.entry(path, 2) | |
|
243 | assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", | |
|
244 | entry.path | |
|
245 | assert_equal "file", entry.kind | |
|
246 | end | |
|
247 | end | |
|
248 | ||
|
249 | def test_changeset_latin1_path | |
|
250 | latin1_repo = create_latin1_repo | |
|
251 | assert_equal 0, latin1_repo.changesets.count | |
|
252 | latin1_repo.fetch_changesets | |
|
253 | @project.reload | |
|
254 | assert_equal 3, latin1_repo.changesets.count | |
|
255 | ||
|
256 | cs2 = latin1_repo.changesets.find_by_revision('2') | |
|
257 | assert_not_nil cs2 | |
|
258 | assert_equal "test-#{@char_1_utf8}", cs2.comments | |
|
259 | c2 = cs2.filechanges.sort_by(&:path) | |
|
260 | assert_equal 4, c2.size | |
|
261 | assert_equal 'A', c2[0].action | |
|
262 | assert_equal "/test-#{@char_1_utf8}-dir/", c2[0].path | |
|
263 | assert_equal 'A', c2[1].action | |
|
264 | assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", c2[1].path | |
|
265 | assert_equal 'A', c2[2].action | |
|
266 | assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c2[2].path | |
|
267 | assert_equal 'A', c2[3].action | |
|
268 | assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c2[3].path | |
|
269 | ||
|
270 | cs3 = latin1_repo.changesets.find_by_revision('3') | |
|
271 | assert_not_nil cs3 | |
|
272 | assert_equal "modify, move and delete #{@char_1_utf8} files", cs3.comments | |
|
273 | c3 = cs3.filechanges.sort_by(&:path) | |
|
274 | assert_equal 3, c3.size | |
|
275 | assert_equal 'M', c3[0].action | |
|
276 | assert_equal "/test-#{@char_1_utf8}-1.txt", c3[0].path | |
|
277 | assert_equal 'D', c3[1].action | |
|
278 | assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c3[1].path | |
|
279 | assert_equal 'M', c3[2].action | |
|
280 | assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c3[2].path | |
|
281 | end | |
|
282 | else | |
|
283 | msg = "Bazaar non ASCII output test cannot run this environment." + "\n" | |
|
284 | if msg.respond_to?(:force_encoding) | |
|
285 | msg += "Encoding.locale_charmap: " + Encoding.locale_charmap + "\n" | |
|
286 | end | |
|
287 | puts msg | |
|
288 | end | |
|
289 | ||
|
290 | private | |
|
291 | ||
|
292 | def create_latin1_repo | |
|
293 | repo = Repository::Bazaar.create( | |
|
294 | :project => @project, | |
|
295 | :identifier => 'latin1', | |
|
296 | :url => REPOSITORY_PATH_NON_ASCII, | |
|
297 | :log_encoding => 'ISO-8859-1' | |
|
298 | ) | |
|
299 | assert repo | |
|
300 | repo | |
|
301 | end | |
|
147 | 302 | else |
|
148 | 303 | puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!" |
|
149 | 304 | def test_fake; assert true end |
General Comments 0
You need to be logged in to leave comments.
Login now