Project

General

Profile

Patch #5117 » hg-version-2010-11-20.patch

Toshi MARUYAMA, 2010-11-20 17:23

View differences:

lib/redmine/scm/adapters/mercurial_adapter.rb
30 30
        
31 31
        class << self
32 32
          def client_version
33
            @@client_version ||= (hgversion || [])
33
            @client_version ||= hgversion
34 34
          end
35 35
          
36 36
          def hgversion  
37 37
            # The hg version is expressed either as a
38 38
            # release number (eg 0.9.5 or 1.0) or as a revision
39 39
            # id composed of 12 hexa characters.
40
            theversion = hgversion_from_command_line
41
            if m = theversion.match(/\b\d+(\.\d+)+\b/)
42
              m[0].split(".").collect(&:to_i)
43
            end
40
            hgversion_from_command_line[/\d+(\.\d+)+/].to_s.split('.').map(&:to_i)
44 41
          end
45 42
          
46 43
          def hgversion_from_command_line
47
            %x{#{HG_BIN} --version}.lines.first.to_s
44
            shellout("#{HG_BIN} --version") { |io| io.read }.to_s
48 45
          end
46
          private :hgversion_from_command_line
49 47
          
50 48
          def template_path
51
            @@template_path ||= template_path_for(client_version)
49
            template_path_for(client_version)
52 50
          end
53 51
          
54 52
          def template_path_for(version)
test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb
1

  
1 2
require File.dirname(__FILE__) + '/../../../../../test_helper'
2 3
begin
3 4
  require 'mocha'
......
9 10
    TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
10 11
    
11 12
    REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
13

  
14
    def setup
15
      @adapter = Redmine::Scm::Adapters::MercurialAdapter
16
    end
12 17
    
13 18
    def test_hgversion
14
      to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
15
                  "Mercurial Distributed SCM (1.0)\n" => [1,0],
16
                  "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
17
                  "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
18
                  "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
19
                  "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5]}
19
      to_test = {
20
                    "0.9.5"                 => [0,9,5],
21
                    "1.0"                   => [1,0],
22
                    "1e4ddc9ac9f7+20080325" => [],
23
                    "1.0.1+20080525"        => [1,0,1],
24
                    "1916e629a29d"          => [] ,
25
                    "1.6"                   => [1,6],
26
                    "1.6.1"                 => [1,6,1],
27
                    "Mercurial Distributed SCM (version 1.6.3)" => [1,6,3],
28
                    ## Italian
29
                    # $ make local
30
                    # $ LANG=it ./hg --version
31
                    "Mercurial SCM Distribuito (versione 1.6.3+61-1c9bb7e00f71)" => [1,6,3],
32
                  }
20 33
      
21 34
      to_test.each do |s, v|
22 35
        test_hgversion_for(s, v)
......
24 37
    end
25 38
    
26 39
    def test_template_path
27
      to_test = { [0,9,5] => "0.9.5",
28
                  [1,0] => "1.0",
29
                  [] => "1.0",
30
                  [1,0,1] => "1.0"}
40
      to_test = {
41
                    [0,9,5] => "0.9.5",
42
                    [1,0]   => "1.0"  ,
43
                    []      => "1.0"  ,
44
                    [1,0,1] => "1.0"  ,
45
                    [1,6]   => "1.0"  ,
46
                    [1,6,1] => "1.0"  ,
47
                  }
31 48
      
32 49
      to_test.each do |v, template|
33 50
        test_template_path_for(v, template)
......
37 54
    private
38 55
    
39 56
    def test_hgversion_for(hgversion, version)
40
      Redmine::Scm::Adapters::MercurialAdapter.expects(:hgversion_from_command_line).returns(hgversion)
41
      adapter = Redmine::Scm::Adapters::MercurialAdapter
42
      assert_equal version, adapter.hgversion
57
      @adapter.expects(:hgversion_from_command_line).returns(hgversion)
58
      assert_equal version, @adapter.hgversion
43 59
    end
44 60
    
45 61
    def test_template_path_for(version, template)
46
      adapter = Redmine::Scm::Adapters::MercurialAdapter
47
      assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", adapter.template_path_for(version)
48
      assert File.exist?(adapter.template_path_for(version))
62
      assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
63
                   @adapter.template_path_for(version)
64
      assert File.exist?(@adapter.template_path_for(version))
49 65
    end
50 66
  end
51 67
  
52 68
rescue LoadError
53
  def test_fake; assert(false, "Requires mocha to run those tests")  end
69
  class MercurialMochaFake < ActiveSupport::TestCase
70
    def test_fake; assert(false, "Requires mocha to run those tests")  end
71
  end
54 72
end
73

  
(10-10/13)