##// END OF EJS Templates
scm: mercurial: refactor mercurial unit test....
Toshi MARUYAMA -
r4509:e86b8febdc79
parent child
Show More
@@ -1,60 +1,73
1 require File.expand_path('../../../../../../test_helper', __FILE__)
1 require File.expand_path('../../../../../../test_helper', __FILE__)
2 begin
2 begin
3 require 'mocha'
3 require 'mocha'
4
4
5 class MercurialAdapterTest < ActiveSupport::TestCase
5 class MercurialAdapterTest < ActiveSupport::TestCase
6
6
7 TEMPLATES_DIR = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATES_DIR
7 TEMPLATES_DIR = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATES_DIR
8 TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME
8 TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME
9 TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
9 TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
10
10
11 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
11 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
12
12
13 if File.directory?(REPOSITORY_PATH)
14 def setup
15 @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH)
16 end
17
13 def test_hgversion
18 def test_hgversion
14 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
19 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
15 "Mercurial Distributed SCM (1.0)\n" => [1,0],
20 "Mercurial Distributed SCM (1.0)\n" => [1,0],
16 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
21 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
17 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
22 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
18 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
23 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
19 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
24 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
20 "(1.6)\n(1.7)\n(1.8)" => [1,6],
25 "(1.6)\n(1.7)\n(1.8)" => [1,6],
21 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
26 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
22
27
23 to_test.each do |s, v|
28 to_test.each do |s, v|
24 test_hgversion_for(s, v)
29 test_hgversion_for(s, v)
25 end
30 end
26 end
31 end
27
32
28 def test_template_path
33 def test_template_path
29 to_test = { [0,9,5] => "0.9.5",
34 to_test = { [0,9,5] => "0.9.5",
30 [1,0] => "1.0",
35 [1,0] => "1.0",
31 [] => "1.0",
36 [] => "1.0",
32 [1,0,1] => "1.0",
37 [1,0,1] => "1.0",
33 [1,7] => "1.0",
38 [1,7] => "1.0",
34 [1,7,1] => "1.0"}
39 [1,7,1] => "1.0"}
35 to_test.each do |v, template|
40 to_test.each do |v, template|
36 test_template_path_for(v, template)
41 test_template_path_for(v, template)
37 end
42 end
38 end
43 end
39
44
45 def test_cat
46 assert @adapter.cat("sources/welcome_controller.rb", 2)
47 assert_nil @adapter.cat("sources/welcome_controller.rb")
48 end
49
40 private
50 private
41
51
42 def test_hgversion_for(hgversion, version)
52 def test_hgversion_for(hgversion, version)
43 Redmine::Scm::Adapters::MercurialAdapter.expects(:hgversion_from_command_line).returns(hgversion)
53 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
44 adapter = Redmine::Scm::Adapters::MercurialAdapter
54 assert_equal version, @adapter.class.hgversion
45 assert_equal version, adapter.hgversion
46 end
55 end
47
56
48 def test_template_path_for(version, template)
57 def test_template_path_for(version, template)
49 adapter = Redmine::Scm::Adapters::MercurialAdapter
58 assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
50 assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", adapter.template_path_for(version)
59 @adapter.class.template_path_for(version)
51 assert File.exist?(adapter.template_path_for(version))
60 assert File.exist?(@adapter.class.template_path_for(version))
61 end
62 else
63 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
64 def test_fake; assert true end
52 end
65 end
53 end
66 end
54
67
55 rescue LoadError
68 rescue LoadError
56 class MercurialMochaFake < ActiveSupport::TestCase
69 class MercurialMochaFake < ActiveSupport::TestCase
57 def test_fake; assert(false, "Requires mocha to run those tests") end
70 def test_fake; assert(false, "Requires mocha to run those tests") end
58 end
71 end
59 end
72 end
60
73
@@ -1,94 +1,87
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositoryMercurialTest < ActiveSupport::TestCase
20 class RepositoryMercurialTest < ActiveSupport::TestCase
21 fixtures :projects
21 fixtures :projects
22
22
23 # No '..' in the repository path
23 # No '..' in the repository path
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
25
25
26 def setup
26 def setup
27 @project = Project.find(1)
27 @project = Project.find(1)
28 assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
28 assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
29 end
29 end
30
30
31 if File.directory?(REPOSITORY_PATH)
31 if File.directory?(REPOSITORY_PATH)
32 def test_fetch_changesets_from_scratch
32 def test_fetch_changesets_from_scratch
33 @repository.fetch_changesets
33 @repository.fetch_changesets
34 @repository.reload
34 @repository.reload
35
35
36 assert_equal 6, @repository.changesets.count
36 assert_equal 6, @repository.changesets.count
37 assert_equal 11, @repository.changes.count
37 assert_equal 11, @repository.changes.count
38 assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments
38 assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments
39 end
39 end
40
40
41 def test_fetch_changesets_incremental
41 def test_fetch_changesets_incremental
42 @repository.fetch_changesets
42 @repository.fetch_changesets
43 # Remove changesets with revision > 2
43 # Remove changesets with revision > 2
44 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
44 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
45 @repository.reload
45 @repository.reload
46 assert_equal 3, @repository.changesets.count
46 assert_equal 3, @repository.changesets.count
47
47
48 @repository.fetch_changesets
48 @repository.fetch_changesets
49 assert_equal 6, @repository.changesets.count
49 assert_equal 6, @repository.changesets.count
50 end
50 end
51
51
52 def test_entries
52 def test_entries
53 assert_equal 2, @repository.entries("sources", 2).size
53 assert_equal 2, @repository.entries("sources", 2).size
54 assert_equal 1, @repository.entries("sources", 3).size
54 assert_equal 1, @repository.entries("sources", 3).size
55 end
55 end
56
56
57 def test_locate_on_outdated_repository
57 def test_locate_on_outdated_repository
58 # Change the working dir state
59 %x{hg -R #{REPOSITORY_PATH} up -r 0}
60 assert_equal 1, @repository.entries("images", 0).size
58 assert_equal 1, @repository.entries("images", 0).size
61 assert_equal 2, @repository.entries("images").size
59 assert_equal 2, @repository.entries("images").size
62 assert_equal 2, @repository.entries("images", 2).size
60 assert_equal 2, @repository.entries("images", 2).size
63 end
61 end
64
62
65 def test_cat
66 assert @repository.scm.cat("sources/welcome_controller.rb", 2)
67 assert_nil @repository.scm.cat("sources/welcome_controller.rb")
68 end
69
70 def test_isodatesec
63 def test_isodatesec
71 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
64 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
72 if @repository.scm.class.client_version_above?([1, 0])
65 if @repository.scm.class.client_version_above?([1, 0])
73 @repository.fetch_changesets
66 @repository.fetch_changesets
74 @repository.reload
67 @repository.reload
75 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
68 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
76 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
69 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
77 end
70 end
78 end
71 end
79
72
80 def test_changeset_order_by_revision
73 def test_changeset_order_by_revision
81 @repository.fetch_changesets
74 @repository.fetch_changesets
82 @repository.reload
75 @repository.reload
83
76
84 c0 = @repository.latest_changeset
77 c0 = @repository.latest_changeset
85 c1 = @repository.changesets.find_by_revision('0')
78 c1 = @repository.changesets.find_by_revision('0')
86 # sorted by revision (id), not by date
79 # sorted by revision (id), not by date
87 assert c0.revision.to_i > c1.revision.to_i
80 assert c0.revision.to_i > c1.revision.to_i
88 assert c0.committed_on < c1.committed_on
81 assert c0.committed_on < c1.committed_on
89 end
82 end
90 else
83 else
91 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
84 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
92 def test_fake; assert true end
85 def test_fake; assert true end
93 end
86 end
94 end
87 end
General Comments 0
You need to be logged in to leave comments. Login now