##// END OF EJS Templates
fix English syntax of skipping test comment of Bazaar non ASCII environment...
Toshi MARUYAMA -
r13232:08bae5928a90
parent child
Show More
@@ -1,297 +1,297
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 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 RepositoryBazaarTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = repository_path('bazaar')
26 26 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
27 27 NUM_REV = 4
28 28
29 29 REPOSITORY_PATH_NON_ASCII = Rails.root.join(REPOSITORY_PATH + '/' + 'non_ascii').to_s
30 30
31 31 # Bazaar core does not support xml output such as Subversion and Mercurial.
32 32 # "bzr" command output and command line parameter depend on locale.
33 33 # So, non ASCII path tests cannot run independent locale.
34 34 #
35 35 # If you want to run Bazaar non ASCII path tests on Linux *Ruby 1.9*,
36 36 # you need to set locale character set "ISO-8859-1".
37 37 # E.g. "LANG=en_US.ISO-8859-1".
38 38 # On Linux other platforms (e.g. Ruby 1.8, JRuby),
39 39 # you need to set "RUN_LATIN1_OUTPUT_TEST = true" manually.
40 40 #
41 41 # On Windows, because it is too hard to change system locale,
42 42 # you cannot run Bazaar non ASCII path tests.
43 43 #
44 44 RUN_LATIN1_OUTPUT_TEST = (RUBY_PLATFORM != 'java' &&
45 45 Encoding.locale_charmap == "ISO-8859-1")
46 46
47 47 CHAR_1_UTF8_HEX = "\xc3\x9c".force_encoding('UTF-8')
48 48 CHAR_1_LATIN1_HEX = "\xdc".force_encoding('ASCII-8BIT')
49 49
50 50 def setup
51 51 @project = Project.find(3)
52 52 @repository = Repository::Bazaar.create(
53 53 :project => @project, :url => REPOSITORY_PATH_TRUNK,
54 54 :log_encoding => 'UTF-8')
55 55 assert @repository
56 56 end
57 57
58 58 def test_blank_path_to_repository_error_message
59 59 set_language_if_valid 'en'
60 60 repo = Repository::Bazaar.new(
61 61 :project => @project,
62 62 :identifier => 'test',
63 63 :log_encoding => 'UTF-8'
64 64 )
65 65 assert !repo.save
66 66 assert_include "Path to repository can't be blank",
67 67 repo.errors.full_messages
68 68 end
69 69
70 70 def test_blank_path_to_repository_error_message_fr
71 71 set_language_if_valid 'fr'
72 72 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
73 73 repo = Repository::Bazaar.new(
74 74 :project => @project,
75 75 :url => "",
76 76 :identifier => 'test',
77 77 :log_encoding => 'UTF-8'
78 78 )
79 79 assert !repo.save
80 80 assert_include str, repo.errors.full_messages
81 81 end
82 82
83 83 if File.directory?(REPOSITORY_PATH_TRUNK)
84 84 def test_fetch_changesets_from_scratch
85 85 assert_equal 0, @repository.changesets.count
86 86 @repository.fetch_changesets
87 87 @project.reload
88 88
89 89 assert_equal NUM_REV, @repository.changesets.count
90 90 assert_equal 9, @repository.filechanges.count
91 91 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
92 92 end
93 93
94 94 def test_fetch_changesets_incremental
95 95 assert_equal 0, @repository.changesets.count
96 96 @repository.fetch_changesets
97 97 @project.reload
98 98 assert_equal NUM_REV, @repository.changesets.count
99 99 # Remove changesets with revision > 5
100 100 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
101 101 @project.reload
102 102 @repository.reload
103 103 assert_equal 2, @repository.changesets.count
104 104
105 105 @repository.fetch_changesets
106 106 @project.reload
107 107 assert_equal NUM_REV, @repository.changesets.count
108 108 end
109 109
110 110 def test_entries
111 111 entries = @repository.entries
112 112 assert_kind_of Redmine::Scm::Adapters::Entries, entries
113 113 assert_equal 2, entries.size
114 114
115 115 assert_equal 'dir', entries[0].kind
116 116 assert_equal 'directory', entries[0].name
117 117 assert_equal 'directory', entries[0].path
118 118
119 119 assert_equal 'file', entries[1].kind
120 120 assert_equal 'doc-mkdir.txt', entries[1].name
121 121 assert_equal 'doc-mkdir.txt', entries[1].path
122 122 end
123 123
124 124 def test_entries_in_subdirectory
125 125 entries = @repository.entries('directory')
126 126 assert_equal 3, entries.size
127 127
128 128 assert_equal 'file', entries.last.kind
129 129 assert_equal 'edit.png', entries.last.name
130 130 assert_equal 'directory/edit.png', entries.last.path
131 131 end
132 132
133 133 def test_previous
134 134 assert_equal 0, @repository.changesets.count
135 135 @repository.fetch_changesets
136 136 @project.reload
137 137 assert_equal NUM_REV, @repository.changesets.count
138 138 changeset = @repository.find_changeset_by_name('3')
139 139 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
140 140 end
141 141
142 142 def test_previous_nil
143 143 assert_equal 0, @repository.changesets.count
144 144 @repository.fetch_changesets
145 145 @project.reload
146 146 assert_equal NUM_REV, @repository.changesets.count
147 147 changeset = @repository.find_changeset_by_name('1')
148 148 assert_nil changeset.previous
149 149 end
150 150
151 151 def test_next
152 152 assert_equal 0, @repository.changesets.count
153 153 @repository.fetch_changesets
154 154 @project.reload
155 155 assert_equal NUM_REV, @repository.changesets.count
156 156 changeset = @repository.find_changeset_by_name('2')
157 157 assert_equal @repository.find_changeset_by_name('3'), changeset.next
158 158 end
159 159
160 160 def test_next_nil
161 161 assert_equal 0, @repository.changesets.count
162 162 @repository.fetch_changesets
163 163 @project.reload
164 164 assert_equal NUM_REV, @repository.changesets.count
165 165 changeset = @repository.find_changeset_by_name('4')
166 166 assert_nil changeset.next
167 167 end
168 168
169 169 if File.directory?(REPOSITORY_PATH_NON_ASCII) && RUN_LATIN1_OUTPUT_TEST
170 170 def test_cat_latin1_path
171 171 latin1_repo = create_latin1_repo
172 172 buf = latin1_repo.cat(
173 173 "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-2.txt", 2)
174 174 assert buf
175 175 lines = buf.split("\n")
176 176 assert_equal 2, lines.length
177 177 assert_equal 'It is written in Python.', lines[1]
178 178
179 179 buf = latin1_repo.cat(
180 180 "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt", 2)
181 181 assert buf
182 182 lines = buf.split("\n")
183 183 assert_equal 1, lines.length
184 184 assert_equal "test-#{CHAR_1_LATIN1_HEX}.txt", lines[0]
185 185 end
186 186
187 187 def test_annotate_latin1_path
188 188 latin1_repo = create_latin1_repo
189 189 ann1 = latin1_repo.annotate(
190 190 "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-2.txt", 2)
191 191 assert_equal 2, ann1.lines.size
192 192 assert_equal '2', ann1.revisions[0].identifier
193 193 assert_equal 'test00@', ann1.revisions[0].author
194 194 assert_equal 'It is written in Python.', ann1.lines[1]
195 195 ann2 = latin1_repo.annotate(
196 196 "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt", 2)
197 197 assert_equal 1, ann2.lines.size
198 198 assert_equal '2', ann2.revisions[0].identifier
199 199 assert_equal 'test00@', ann2.revisions[0].author
200 200 assert_equal "test-#{CHAR_1_LATIN1_HEX}.txt", ann2.lines[0]
201 201 end
202 202
203 203 def test_diff_latin1_path
204 204 latin1_repo = create_latin1_repo
205 205 diff1 = latin1_repo.diff(
206 206 "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt", 2, 1)
207 207 assert_equal 7, diff1.size
208 208 buf = diff1[5].gsub(/\r\n|\r|\n/, "")
209 209 assert_equal "+test-#{CHAR_1_LATIN1_HEX}.txt", buf
210 210 end
211 211
212 212 def test_entries_latin1_path
213 213 latin1_repo = create_latin1_repo
214 214 entries = latin1_repo.entries("test-#{CHAR_1_UTF8_HEX}-dir", 2)
215 215 assert_kind_of Redmine::Scm::Adapters::Entries, entries
216 216 assert_equal 3, entries.size
217 217 assert_equal 'file', entries[1].kind
218 218 assert_equal "test-#{CHAR_1_UTF8_HEX}-1.txt", entries[0].name
219 219 assert_equal "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt", entries[0].path
220 220 end
221 221
222 222 def test_entry_latin1_path
223 223 latin1_repo = create_latin1_repo
224 224 ["test-#{CHAR_1_UTF8_HEX}-dir",
225 225 "/test-#{CHAR_1_UTF8_HEX}-dir",
226 226 "/test-#{CHAR_1_UTF8_HEX}-dir/"
227 227 ].each do |path|
228 228 entry = latin1_repo.entry(path, 2)
229 229 assert_equal "test-#{CHAR_1_UTF8_HEX}-dir", entry.path
230 230 assert_equal "dir", entry.kind
231 231 end
232 232 ["test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt",
233 233 "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt"
234 234 ].each do |path|
235 235 entry = latin1_repo.entry(path, 2)
236 236 assert_equal "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt",
237 237 entry.path
238 238 assert_equal "file", entry.kind
239 239 end
240 240 end
241 241
242 242 def test_changeset_latin1_path
243 243 latin1_repo = create_latin1_repo
244 244 assert_equal 0, latin1_repo.changesets.count
245 245 latin1_repo.fetch_changesets
246 246 @project.reload
247 247 assert_equal 3, latin1_repo.changesets.count
248 248
249 249 cs2 = latin1_repo.changesets.find_by_revision('2')
250 250 assert_not_nil cs2
251 251 assert_equal "test-#{CHAR_1_UTF8_HEX}", cs2.comments
252 252 c2 = cs2.filechanges.sort_by(&:path)
253 253 assert_equal 4, c2.size
254 254 assert_equal 'A', c2[0].action
255 255 assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/", c2[0].path
256 256 assert_equal 'A', c2[1].action
257 257 assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt", c2[1].path
258 258 assert_equal 'A', c2[2].action
259 259 assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-2.txt", c2[2].path
260 260 assert_equal 'A', c2[3].action
261 261 assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}.txt", c2[3].path
262 262
263 263 cs3 = latin1_repo.changesets.find_by_revision('3')
264 264 assert_not_nil cs3
265 265 assert_equal "modify, move and delete #{CHAR_1_UTF8_HEX} files", cs3.comments
266 266 c3 = cs3.filechanges.sort_by(&:path)
267 267 assert_equal 3, c3.size
268 268 assert_equal 'M', c3[0].action
269 269 assert_equal "/test-#{CHAR_1_UTF8_HEX}-1.txt", c3[0].path
270 270 assert_equal 'D', c3[1].action
271 271 assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-2.txt", c3[1].path
272 272 assert_equal 'M', c3[2].action
273 273 assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}.txt", c3[2].path
274 274 end
275 275 else
276 msg = "Bazaar non ASCII output test cannot run this environment.\n"
276 msg = "Bazaar non ASCII output test cannot run on this environment.\n"
277 277 msg += "Encoding.locale_charmap: " + Encoding.locale_charmap + "\n"
278 278 puts msg
279 279 end
280 280
281 281 private
282 282
283 283 def create_latin1_repo
284 284 repo = Repository::Bazaar.create(
285 285 :project => @project,
286 286 :identifier => 'latin1',
287 287 :url => REPOSITORY_PATH_NON_ASCII,
288 288 :log_encoding => 'ISO-8859-1'
289 289 )
290 290 assert repo
291 291 repo
292 292 end
293 293 else
294 294 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
295 295 def test_fake; assert true end
296 296 end
297 297 end
General Comments 0
You need to be logged in to leave comments. Login now