annotate .svn/pristine/cb/cb011925faaf39d091329859f0fbe2f0e4eeb869.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 begin
Chris@1296 20 require 'mocha'
Chris@1296 21
Chris@1296 22 class BazaarAdapterTest < ActiveSupport::TestCase
Chris@1296 23 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
Chris@1296 24 REPOSITORY_PATH.gsub!(/\/+/, '/')
Chris@1296 25
Chris@1296 26 if File.directory?(REPOSITORY_PATH)
Chris@1296 27 def setup
Chris@1296 28 @adapter = Redmine::Scm::Adapters::BazaarAdapter.new(
Chris@1296 29 File.join(REPOSITORY_PATH, "trunk")
Chris@1296 30 )
Chris@1296 31 end
Chris@1296 32
Chris@1296 33 def test_scm_version
Chris@1296 34 to_test = { "Bazaar (bzr) 2.1.2\n" => [2,1,2],
Chris@1296 35 "2.1.1\n1.7\n1.8" => [2,1,1],
Chris@1296 36 "2.0.1\r\n1.8.1\r\n1.9.1" => [2,0,1]}
Chris@1296 37 to_test.each do |s, v|
Chris@1296 38 test_scm_version_for(s, v)
Chris@1296 39 end
Chris@1296 40 end
Chris@1296 41
Chris@1296 42 def test_cat
Chris@1296 43 cat = @adapter.cat('directory/document.txt')
Chris@1296 44 assert cat =~ /Write the contents of a file as of a given revision to standard output/
Chris@1296 45 end
Chris@1296 46
Chris@1296 47 def test_cat_path_invalid
Chris@1296 48 assert_nil @adapter.cat('invalid')
Chris@1296 49 end
Chris@1296 50
Chris@1296 51 def test_cat_revision_invalid
Chris@1296 52 assert_nil @adapter.cat('doc-mkdir.txt', '12345678')
Chris@1296 53 end
Chris@1296 54
Chris@1296 55 def test_diff
Chris@1296 56 diff1 = @adapter.diff('doc-mkdir.txt', 3, 2)
Chris@1296 57 assert_equal 21, diff1.size
Chris@1296 58 buf = diff1[14].gsub(/\r\n|\r|\n/, "")
Chris@1296 59 assert_equal "-Display more information.", buf
Chris@1296 60 end
Chris@1296 61
Chris@1296 62 def test_diff_path_invalid
Chris@1296 63 assert_equal [], @adapter.diff('invalid', 1)
Chris@1296 64 end
Chris@1296 65
Chris@1296 66 def test_diff_revision_invalid
Chris@1296 67 assert_equal [], @adapter.diff(nil, 12345678)
Chris@1296 68 assert_equal [], @adapter.diff(nil, 12345678, 87654321)
Chris@1296 69 end
Chris@1296 70
Chris@1296 71 def test_annotate
Chris@1296 72 annotate = @adapter.annotate('doc-mkdir.txt')
Chris@1296 73 assert_equal 17, annotate.lines.size
Chris@1296 74 assert_equal '1', annotate.revisions[0].identifier
Chris@1296 75 assert_equal 'jsmith@', annotate.revisions[0].author
Chris@1296 76 assert_equal 'mkdir', annotate.lines[0]
Chris@1296 77 end
Chris@1296 78
Chris@1296 79 def test_annotate_path_invalid
Chris@1296 80 assert_nil @adapter.annotate('invalid')
Chris@1296 81 end
Chris@1296 82
Chris@1296 83 def test_annotate_revision_invalid
Chris@1296 84 assert_nil @adapter.annotate('doc-mkdir.txt', '12345678')
Chris@1296 85 end
Chris@1296 86
Chris@1296 87 def test_branch_conf_path
Chris@1296 88 p = "c:\\test\\test\\"
Chris@1296 89 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
Chris@1296 90 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
Chris@1296 91 p = "c:\\test\\test\\.bzr"
Chris@1296 92 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
Chris@1296 93 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
Chris@1296 94 p = "c:\\test\\test\\.bzr\\"
Chris@1296 95 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
Chris@1296 96 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
Chris@1296 97 p = "c:\\test\\test"
Chris@1296 98 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
Chris@1296 99 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
Chris@1296 100 p = "\\\\server\\test\\test\\"
Chris@1296 101 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
Chris@1296 102 assert_equal File.join("\\\\server\\test\\test", ".bzr", "branch", "branch.conf"), bcp
Chris@1296 103 end
Chris@1296 104
Chris@1296 105 def test_append_revisions_only_true
Chris@1296 106 assert_equal true, @adapter.append_revisions_only
Chris@1296 107 end
Chris@1296 108
Chris@1296 109 def test_append_revisions_only_false
Chris@1296 110 adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
Chris@1296 111 File.join(REPOSITORY_PATH, "empty-branch")
Chris@1296 112 )
Chris@1296 113 assert_equal false, adpt.append_revisions_only
Chris@1296 114 end
Chris@1296 115
Chris@1296 116 def test_append_revisions_only_shared_repo
Chris@1296 117 adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
Chris@1296 118 REPOSITORY_PATH
Chris@1296 119 )
Chris@1296 120 assert_equal false, adpt.append_revisions_only
Chris@1296 121 end
Chris@1296 122
Chris@1296 123 def test_info_not_nil
Chris@1296 124 assert_not_nil @adapter.info
Chris@1296 125 end
Chris@1296 126
Chris@1296 127 def test_info_nil
Chris@1296 128 adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
Chris@1296 129 "/invalid/invalid/"
Chris@1296 130 )
Chris@1296 131 assert_nil adpt.info
Chris@1296 132 end
Chris@1296 133
Chris@1296 134 def test_info
Chris@1296 135 info = @adapter.info
Chris@1296 136 assert_equal 4, info.lastrev.identifier.to_i
Chris@1296 137 end
Chris@1296 138
Chris@1296 139 def test_info_emtpy
Chris@1296 140 adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
Chris@1296 141 File.join(REPOSITORY_PATH, "empty-branch")
Chris@1296 142 )
Chris@1296 143 assert_equal 0, adpt.info.lastrev.identifier.to_i
Chris@1296 144 end
Chris@1296 145
Chris@1296 146 def test_entries_path_invalid
Chris@1296 147 assert_equal [], @adapter.entries('invalid')
Chris@1296 148 end
Chris@1296 149
Chris@1296 150 def test_entries_revision_invalid
Chris@1296 151 assert_nil @adapter.entries(nil, 12345678)
Chris@1296 152 end
Chris@1296 153
Chris@1296 154 def test_revisions
Chris@1296 155 revisions = @adapter.revisions(nil, 4, 2)
Chris@1296 156 assert_equal 3, revisions.size
Chris@1296 157 assert_equal 2, revisions[2].identifier
Chris@1296 158 assert_equal 'jsmith@foo.bar-20071203175224-v0eog5d5wrgdrshg', revisions[2].scmid
Chris@1296 159 assert_equal 4, revisions[0].identifier
Chris@1296 160 assert_equal 'jsmith@foo.bar-20071203175422-t40bf8li5zz0c4cg', revisions[0].scmid
Chris@1296 161 assert_equal 2, revisions[0].paths.size
Chris@1296 162 assert_equal 'D', revisions[0].paths[0][:action]
Chris@1296 163 assert_equal '/doc-deleted.txt', revisions[0].paths[0][:path]
Chris@1296 164 assert_equal 'docdeleted.txt-20071203175320-iwwj561ojuubs3gt-1', revisions[0].paths[0][:revision]
Chris@1296 165 assert_equal 'M', revisions[0].paths[1][:action]
Chris@1296 166 assert_equal '/directory/doc-ls.txt', revisions[0].paths[1][:path]
Chris@1296 167 assert_equal 'docls.txt-20071203175005-a3hyc3mn0shl7cgu-1', revisions[0].paths[1][:revision]
Chris@1296 168 end
Chris@1296 169
Chris@1296 170 def test_revisions_path_invalid
Chris@1296 171 assert_nil @adapter.revisions('invalid')
Chris@1296 172 end
Chris@1296 173
Chris@1296 174 def test_revisions_revision_invalid
Chris@1296 175 assert_nil @adapter.revisions(nil, 12345678)
Chris@1296 176 assert_nil @adapter.revisions(nil, 12345678, 87654321)
Chris@1296 177 end
Chris@1296 178
Chris@1296 179 def test_entry
Chris@1296 180 entry = @adapter.entry()
Chris@1296 181 assert_equal "", entry.path
Chris@1296 182 assert_equal "dir", entry.kind
Chris@1296 183 entry = @adapter.entry('')
Chris@1296 184 assert_equal "", entry.path
Chris@1296 185 assert_equal "dir", entry.kind
Chris@1296 186 assert_nil @adapter.entry('invalid')
Chris@1296 187 assert_nil @adapter.entry('/invalid')
Chris@1296 188 assert_nil @adapter.entry('/invalid/')
Chris@1296 189 assert_nil @adapter.entry('invalid/invalid')
Chris@1296 190 assert_nil @adapter.entry('invalid/invalid/')
Chris@1296 191 assert_nil @adapter.entry('/invalid/invalid')
Chris@1296 192 assert_nil @adapter.entry('/invalid/invalid/')
Chris@1296 193 ["doc-ls.txt", "/doc-ls.txt"].each do |path|
Chris@1296 194 entry = @adapter.entry(path, 2)
Chris@1296 195 assert_equal "doc-ls.txt", entry.path
Chris@1296 196 assert_equal "file", entry.kind
Chris@1296 197 end
Chris@1296 198 ["directory", "/directory", "/directory/"].each do |path|
Chris@1296 199 entry = @adapter.entry(path, 2)
Chris@1296 200 assert_equal "directory", entry.path
Chris@1296 201 assert_equal "dir", entry.kind
Chris@1296 202 end
Chris@1296 203 ["directory/document.txt", "/directory/document.txt"].each do |path|
Chris@1296 204 entry = @adapter.entry(path, 2)
Chris@1296 205 assert_equal "directory/document.txt", entry.path
Chris@1296 206 assert_equal "file", entry.kind
Chris@1296 207 end
Chris@1296 208 end
Chris@1296 209
Chris@1296 210 private
Chris@1296 211
Chris@1296 212 def test_scm_version_for(scm_command_version, version)
Chris@1296 213 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
Chris@1296 214 assert_equal version, @adapter.class.scm_command_version
Chris@1296 215 end
Chris@1296 216 else
Chris@1296 217 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
Chris@1296 218 def test_fake; assert true end
Chris@1296 219 end
Chris@1296 220 end
Chris@1296 221 rescue LoadError
Chris@1296 222 class BazaarMochaFake < ActiveSupport::TestCase
Chris@1296 223 def test_fake; assert(false, "Requires mocha to run those tests") end
Chris@1296 224 end
Chris@1296 225 end