Commits

Yuya Nishihara committed c5a47a5

hg/version: actually fix test case (refs #7)

Comments (0)

Files changed (1)

 
 closes #5117
 
+Test-case-by: Toshi MARUYAMA <marutosijp2@gmail.com>
+
 diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb
 --- a/lib/redmine/scm/adapters/mercurial_adapter.rb
 +++ b/lib/redmine/scm/adapters/mercurial_adapter.rb
 -            if theversion.match(/^\d+(\.\d+)+/)
 -              theversion.split(".").collect(&:to_i)
 -            end
-+            hgversion_str.to_s.split('.').map { |e| e.to_i }
++            hgversion_from_command_line[/\d+(\.\d+)+/].to_s.split('.').map { |e| e.to_i }
            end
            
--          def hgversion_from_command_line
+           def hgversion_from_command_line
 -            %x{#{HG_BIN} --version}.match(/\(version (.*)\)/)[1]
-+          def hgversion_str
-+            shellout("#{HG_BIN} --version") { |io| io.gets }.to_s[/\d+(\.\d+)+/]
++            shellout("#{HG_BIN} --version") { |io| io.gets }.to_s
            end
-+          private :hgversion_str
++          private :hgversion_from_command_line
            
            def template_path
 -            @@template_path ||= template_path_for(client_version)
            end
            
            def template_path_for(version)
+diff --git a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb
+--- a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb
++++ b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb
+@@ -1,3 +1,4 @@
++
+ require File.dirname(__FILE__) + '/../../../../../test_helper'
+ begin
+   require 'mocha'
+@@ -9,13 +10,26 @@ begin
+     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],
++                    ## Italian
++                    # $ make local
++                    # $ LANG=it ./hg --version
++                    "Mercurial SCM Distribuito (versione 1.6.3+61-1c9bb7e00f71)" => [1,6,3],
++                  }
+       
+       to_test.each do |s, v|
+         test_hgversion_for(s, v)
+@@ -23,10 +37,14 @@ begin
+     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)
+@@ -36,15 +54,14 @@ begin
+     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
+