From 2afc8e8c952268540cda1058fca2cbac6234c546 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Tue, 15 Feb 2011 08:04:11 +0000 Subject: [PATCH] scm: cvs: add methods of getting cvs version and add unit lib test (#4273). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4832 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/scm/adapters/cvs_adapter.rb | 19 +++++++++++++++++++ .../redmine/scm/adapters/cvs_adapter_test.rb | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/redmine/scm/adapters/cvs_adapter.rb b/lib/redmine/scm/adapters/cvs_adapter.rb index c3d3bf726..676f5f7c9 100644 --- a/lib/redmine/scm/adapters/cvs_adapter.rb +++ b/lib/redmine/scm/adapters/cvs_adapter.rb @@ -33,6 +33,25 @@ module Redmine def sq_bin @@sq_bin ||= shell_quote(CVS_BIN) 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) + 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 # Guidelines for the input: diff --git a/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb index b6b4b6ee8..b6155ea34 100644 --- a/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb @@ -13,6 +13,15 @@ begin @adapter = Redmine::Scm::Adapters::CvsAdapter.new(MODULE_NAME, REPOSITORY_PATH) end + def test_scm_version + to_test = { "\nConcurrent Versions System (CVS) 1.12.13 (client/server)\n" => [1,12,13], + "\r\n1.12.12\r\n1.12.11" => [1,12,12], + "1.12.11\r\n1.12.10\r\n" => [1,12,11]} + to_test.each do |s, v| + test_scm_version_for(s, v) + end + end + def test_revisions_all cnt = 0 @adapter.revisions('', nil, nil, :with_paths => true) do |revision| @@ -29,6 +38,13 @@ begin end assert_equal 2, cnt 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 puts "Cvs test repository NOT FOUND. Skipping unit tests !!!" def test_fake; assert true end