From 0d3703c0b3b3cc57a59a82252b096d4849c7f2e9 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Sat, 22 Jan 2011 15:38:23 +0000 Subject: [PATCH] scm: darcs: change io.gets to io.read and add darcs version unit (#4494, #5404). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4743 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/scm/adapters/darcs_adapter.rb | 16 +++++++--------- .../redmine/scm/adapters/darcs_adapter_test.rb | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/redmine/scm/adapters/darcs_adapter.rb b/lib/redmine/scm/adapters/darcs_adapter.rb index ecc69a4e9..381f609c0 100644 --- a/lib/redmine/scm/adapters/darcs_adapter.rb +++ b/lib/redmine/scm/adapters/darcs_adapter.rb @@ -31,16 +31,14 @@ module Redmine end def darcs_binary_version - cmd = "#{DARCS_BIN} --version" - version = nil - shellout(cmd) do |io| - # Read darcs version in first returned line - if m = io.gets.match(%r{((\d+\.)+\d+)}) - version = m[0].scan(%r{\d+}).collect(&:to_i) - end + darcsversion = darcs_binary_version_from_command_line + if m = darcsversion.match(%r{\A(.*?)((\d+\.)+\d+)}) + m[2].scan(%r{\d+}).collect(&:to_i) end - return nil if $? && $?.exitstatus != 0 - version + end + + def darcs_binary_version_from_command_line + shellout("#{DARCS_BIN} --version") { |io| io.read }.to_s end end diff --git a/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb index ddcea89b6..820ffdb90 100644 --- a/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb @@ -11,6 +11,21 @@ begin @adapter = Redmine::Scm::Adapters::DarcsAdapter.new(REPOSITORY_PATH) end + def test_darcsversion + to_test = { "1.0.9 (release)\n" => [1,0,9] , + "2.2.0 (release)\n" => [2,2,0] } + to_test.each do |s, v| + test_darcsversion_for(s, v) + end + end + + private + + def test_darcsversion_for(darcsversion, version) + @adapter.class.expects(:darcs_binary_version_from_command_line).returns(darcsversion) + assert_equal version, @adapter.class.darcs_binary_version + end + else puts "Darcs test repository NOT FOUND. Skipping unit tests !!!" def test_fake; assert true end -- 2.39.5