From 323c36b3c3dd88b3da2642b63df1ba1743c78c67 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Tue, 15 Feb 2011 02:12:39 +0000 Subject: [PATCH] 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 --- .../scm/adapters/subversion_adapter.rb | 22 ++++++++++--------- .../scm/adapters/subversion_adapter_test.rb | 20 +++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/redmine/scm/adapters/subversion_adapter.rb b/lib/redmine/scm/adapters/subversion_adapter.rb index c17d7a5e..802dc4a1 100644 --- a/lib/redmine/scm/adapters/subversion_adapter.rb +++ b/lib/redmine/scm/adapters/subversion_adapter.rb @@ -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 diff --git a/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb index 966a8292..1d8b9cbe 100644 --- a/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb @@ -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