scm: bazaar: add methods of getting bazaar version and add unit lib test (#4273).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4831 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
cad0356322
commit
6d8fe71a73
|
@ -33,6 +33,25 @@ module Redmine
|
||||||
def sq_bin
|
def sq_bin
|
||||||
@@sq_bin ||= shell_quote(BZR_BIN)
|
@@sq_bin ||= shell_quote(BZR_BIN)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def client_version
|
||||||
|
@@client_version ||= (scm_command_version || [])
|
||||||
|
end
|
||||||
|
|
||||||
|
def client_available
|
||||||
|
!client_version.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def scm_command_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
|
end
|
||||||
|
|
||||||
# Get info about the repository
|
# Get info about the repository
|
||||||
|
|
|
@ -5,12 +5,28 @@ begin
|
||||||
class BazaarAdapterTest < ActiveSupport::TestCase
|
class BazaarAdapterTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository'
|
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository'
|
||||||
|
REPOSITORY_PATH.gsub!(/\/+/, '/')
|
||||||
|
|
||||||
if File.directory?(REPOSITORY_PATH)
|
if File.directory?(REPOSITORY_PATH)
|
||||||
def setup
|
def setup
|
||||||
@adapter = Redmine::Scm::Adapters::BazaarAdapter.new(MODULE_NAME, REPOSITORY_PATH)
|
@adapter = Redmine::Scm::Adapters::BazaarAdapter.new(REPOSITORY_PATH)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_scm_version
|
||||||
|
to_test = { "Bazaar (bzr) 2.1.2\n" => [2,1,2],
|
||||||
|
"2.1.1\n1.7\n1.8" => [2,1,1],
|
||||||
|
"2.0.1\r\n1.8.1\r\n1.9.1" => [2,0,1]}
|
||||||
|
to_test.each do |s, v|
|
||||||
|
test_scm_version_for(s, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def test_scm_version_for(scm_command_version, version)
|
||||||
|
@adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
|
||||||
|
assert_equal version, @adapter.class.scm_command_version
|
||||||
|
end
|
||||||
else
|
else
|
||||||
puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
|
puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
|
||||||
def test_fake; assert true end
|
def test_fake; assert true end
|
||||||
|
|
Loading…
Reference in New Issue