scm: subversion: refactor getting svn version and add lib test (#4273).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4825 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-02-15 02:12:39 +00:00
parent 60d80653ba
commit 41f190e8ed
2 changed files with 32 additions and 10 deletions

View File

@ -38,19 +38,21 @@ module Redmine
def client_version
@@client_version ||= (svn_binary_version || [])
end
def client_available
!client_version.empty?
end
def svn_binary_version
cmd = "#{sq_bin} --version"
version = nil
shellout(cmd) do |io|
# Read svn version in first returned line
if m = io.read.to_s.match(%r{\A(.*?)((\d+\.)+\d+)})
version = m[2].scan(%r{\d+}).collect(&:to_i)
end
end
return nil if $? && $?.exitstatus != 0
version
scm_version = scm_version_from_command_line
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
end
def scm_version_from_command_line
shellout("#{sq_bin} --version") { |io| io.read }.to_s
end
end
# Get info about the svn repository

View File

@ -24,12 +24,32 @@ begin
if repository_configured?('subversion')
def setup
repo_path = "file://#{self.class.repository_path('subversion')}"
@adapter = Redmine::Scm::Adapters::SubversionAdapter.new(repo_path)
end
def test_client_version
v = Redmine::Scm::Adapters::SubversionAdapter.client_version
assert v.is_a?(Array)
end
def test_scm_version
to_test = { "svn, version 1.6.13 (r1002816)\n" => [1,6,13],
"svn, versione 1.6.13 (r1002816)\n" => [1,6,13],
"1.6.1\n1.7\n1.8" => [1,6,1],
"1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
to_test.each do |s, v|
test_scm_version_for(s, v)
end
end
private
def test_scm_version_for(scm_version, version)
@adapter.class.expects(:scm_version_from_command_line).returns(scm_version)
assert_equal version, @adapter.class.svn_binary_version
end
else
puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
def test_fake; assert true end