annotate .svn/pristine/0c/0c9dc58fe829b59060fa2ba2bfeb1db760e787c2.svn-base @ 1628:9c5f8e24dadc live tip

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