annotate .svn/pristine/55/55d19caa0b30cb24ce3fc09b9feabb1a8fe2c09a.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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