Project

General

Profile

Patch #5117 » hg-version-20101114.diff

Toshi MARUYAMA, 2010-11-14 13:19

View differences:

lib/redmine/scm/adapters/mercurial_adapter.rb
class << self
def client_version
@@client_version ||= (hgversion || [])
@client_version ||= hgversion
end
def hgversion
# The hg version is expressed either as a
# release number (eg 0.9.5 or 1.0) or as a revision
# id composed of 12 hexa characters.
theversion = hgversion_from_command_line
if theversion.match(/^\d+(\.\d+)+/)
theversion.split(".").collect(&:to_i)
version = []
buf = hgversion_from_command_line
if buf && m = buf.match(%r{\A(.*?)((\d+\.)+\d+)})
version = m[2].scan(%r{\d+}).collect(&:to_i)
end
version
end
def hgversion_from_command_line
%x{#{HG_BIN} --version}.match(/\(version (.*)\)/)[1]
buf = nil
cmd = "#{HG_BIN} --version"
shellout(cmd) do |io|
# Read svn version in first returned line
buf = io.read.to_s
end
return nil if $? && $?.exitstatus != 0
buf
end
private :hgversion_from_command_line
def template_path
@@template_path ||= template_path_for(client_version)
template_path_for(client_version)
end
def template_path_for(version)
test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb
require File.dirname(__FILE__) + '/../../../../../test_helper'
begin
require 'mocha'
......
TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
def setup
@adapter = Redmine::Scm::Adapters::MercurialAdapter
end
def test_hgversion
to_test = { "0.9.5" => [0,9,5],
"1.0" => [1,0],
"1e4ddc9ac9f7+20080325" => nil,
"1.0.1+20080525" => [1,0,1],
"1916e629a29d" => nil}
to_test = {
"0.9.5" => [0,9,5],
"1.0" => [1,0],
"1e4ddc9ac9f7+20080325" => [],
"1.0.1+20080525" => [1,0,1],
"1916e629a29d" => [] ,
"1.6" => [1,6],
"1.6.1" => [1,6,1],
"Mercurial Distributed SCM (version 1.6.3)" => [1,6,3],
"Mercurial Distributed SCM (version 1.7)" => [1,7],
## Italian
# $ make local
# $ LANG=it ./hg --version
"Mercurial SCM Distribuito (versione 1.6.3+61-1c9bb7e00f71)" => [1,6,3],
# Multi lines CRLF.
"Mercurial Distributed SCM (version 1.6.3)\r\n1.7\r\n(1.8.1)" => [1,6,3],
# Multi lines LF.
"Mercurial Distributed SCM (version 1.7)\n1.7.1\n(1.8.1)" => [1,7],
}
to_test.each do |s, v|
test_hgversion_for(s, v)
......
end
def test_template_path
to_test = { [0,9,5] => "0.9.5",
[1,0] => "1.0",
[] => "1.0",
[1,0,1] => "1.0"}
to_test = {
[0,9,5] => "0.9.5",
[1,0] => "1.0" ,
[] => "1.0" ,
[1,0,1] => "1.0" ,
[1,6] => "1.0" ,
[1,6,1] => "1.0" ,
}
to_test.each do |v, template|
test_template_path_for(v, template)
......
private
def test_hgversion_for(hgversion, version)
Redmine::Scm::Adapters::MercurialAdapter.expects(:hgversion_from_command_line).returns(hgversion)
adapter = Redmine::Scm::Adapters::MercurialAdapter
assert_equal version, adapter.hgversion
@adapter.expects(:hgversion_from_command_line).returns(hgversion)
assert_equal version, @adapter.hgversion
end
def test_template_path_for(version, template)
adapter = Redmine::Scm::Adapters::MercurialAdapter
assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", adapter.template_path_for(version)
assert File.exist?(adapter.template_path_for(version))
assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
@adapter.template_path_for(version)
assert File.exist?(@adapter.template_path_for(version))
end
end
rescue LoadError
def test_fake; assert(false, "Requires mocha to run those tests") end
class MercurialMochaFake < ActiveSupport::TestCase
def test_fake; assert(false, "Requires mocha to run those tests") end
end
end
(7-7/13)