##// END OF EJS Templates
scm: mercurial: remove new line in diff unit test(#7253)....
Toshi MARUYAMA -
r4549:b017a846ba73
parent child
Show More
@@ -1,121 +1,124
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)
13 if File.directory?(REPOSITORY_PATH)
14 def setup
14 def setup
15 @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH)
15 @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH)
16 end
16 end
17
17
18 def test_hgversion
18 def test_hgversion
19 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],
20 "Mercurial Distributed SCM (1.0)\n" => [1,0],
20 "Mercurial Distributed SCM (1.0)\n" => [1,0],
21 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
21 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
22 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
22 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
23 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
23 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
24 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
24 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
25 "(1.6)\n(1.7)\n(1.8)" => [1,6],
25 "(1.6)\n(1.7)\n(1.8)" => [1,6],
26 "(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]}
27
27
28 to_test.each do |s, v|
28 to_test.each do |s, v|
29 test_hgversion_for(s, v)
29 test_hgversion_for(s, v)
30 end
30 end
31 end
31 end
32
32
33 def test_template_path
33 def test_template_path
34 to_test = { [0,9,5] => "0.9.5",
34 to_test = { [0,9,5] => "0.9.5",
35 [1,0] => "1.0",
35 [1,0] => "1.0",
36 [] => "1.0",
36 [] => "1.0",
37 [1,0,1] => "1.0",
37 [1,0,1] => "1.0",
38 [1,7] => "1.0",
38 [1,7] => "1.0",
39 [1,7,1] => "1.0" }
39 [1,7,1] => "1.0" }
40 to_test.each do |v, template|
40 to_test.each do |v, template|
41 test_template_path_for(v, template)
41 test_template_path_for(v, template)
42 end
42 end
43 end
43 end
44
44
45 def test_diff
45 def test_diff
46 assert_nil @adapter.diff(nil, '100000')
46 assert_nil @adapter.diff(nil, '100000')
47 assert_nil @adapter.diff(nil, '100000', '200000')
47 assert_nil @adapter.diff(nil, '100000', '200000')
48 [2, '400bb8672109', '400', 400].each do |r1|
48 [2, '400bb8672109', '400', 400].each do |r1|
49 diff1 = @adapter.diff(nil, r1)
49 diff1 = @adapter.diff(nil, r1)
50 assert_equal 28, diff1.size
50 assert_equal 28, diff1.size
51 assert_equal "+ return true unless klass.respond_to?('watched_by')\r\n", diff1[24]
51 buf = diff1[24].gsub(/\r\n|\r|\n/, "")
52 assert_equal "+ return true unless klass.respond_to?('watched_by')", buf
52 [4, 'def6d2f1254a'].each do |r2|
53 [4, 'def6d2f1254a'].each do |r2|
53 diff2 = @adapter.diff(nil,r1,r2)
54 diff2 = @adapter.diff(nil,r1,r2)
54 assert_equal 50, diff2.size
55 assert_equal 50, diff2.size
55 assert_equal "+class WelcomeController < ApplicationController\r\n", diff2[42]
56 buf = diff2[42].gsub(/\r\n|\r|\n/, "")
57 assert_equal "+class WelcomeController < ApplicationController", buf
56 diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
58 diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
57 assert_equal 20, diff3.size
59 assert_equal 20, diff3.size
58 assert_equal "+ @watched.remove_watcher(user)\r\n", diff3[12]
60 buf = diff3[12].gsub(/\r\n|\r|\n/, "")
61 assert_equal "+ @watched.remove_watcher(user)", buf
59 end
62 end
60 end
63 end
61 end
64 end
62
65
63 def test_cat
66 def test_cat
64 [2, '400bb8672109', '400', 400].each do |r|
67 [2, '400bb8672109', '400', 400].each do |r|
65 buf = @adapter.cat('sources/welcome_controller.rb', r)
68 buf = @adapter.cat('sources/welcome_controller.rb', r)
66 assert buf
69 assert buf
67 lines = buf.split("\r\n")
70 lines = buf.split("\r\n")
68 assert_equal 25, lines.length
71 assert_equal 25, lines.length
69 assert_equal 'class WelcomeController < ApplicationController', lines[17]
72 assert_equal 'class WelcomeController < ApplicationController', lines[17]
70 end
73 end
71 assert_nil @adapter.cat('sources/welcome_controller.rb')
74 assert_nil @adapter.cat('sources/welcome_controller.rb')
72 end
75 end
73
76
74 def test_annotate
77 def test_annotate
75 assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
78 assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
76 [2, '400bb8672109', '400', 400].each do |r|
79 [2, '400bb8672109', '400', 400].each do |r|
77 ann = @adapter.annotate('sources/welcome_controller.rb', r)
80 ann = @adapter.annotate('sources/welcome_controller.rb', r)
78 assert ann
81 assert ann
79 assert_equal '1', ann.revisions[17].revision
82 assert_equal '1', ann.revisions[17].revision
80 assert_equal '9d5b5b004199', ann.revisions[17].identifier
83 assert_equal '9d5b5b004199', ann.revisions[17].identifier
81 assert_equal 'jsmith', ann.revisions[0].author
84 assert_equal 'jsmith', ann.revisions[0].author
82 assert_equal 25, ann.lines.length
85 assert_equal 25, ann.lines.length
83 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
86 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
84 end
87 end
85 end
88 end
86
89
87 def test_access_by_nodeid
90 def test_access_by_nodeid
88 path = 'sources/welcome_controller.rb'
91 path = 'sources/welcome_controller.rb'
89 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
92 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
90 end
93 end
91
94
92 def test_access_by_fuzzy_nodeid
95 def test_access_by_fuzzy_nodeid
93 path = 'sources/welcome_controller.rb'
96 path = 'sources/welcome_controller.rb'
94 # falls back to nodeid
97 # falls back to nodeid
95 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
98 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
96 end
99 end
97
100
98 private
101 private
99
102
100 def test_hgversion_for(hgversion, version)
103 def test_hgversion_for(hgversion, version)
101 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
104 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
102 assert_equal version, @adapter.class.hgversion
105 assert_equal version, @adapter.class.hgversion
103 end
106 end
104
107
105 def test_template_path_for(version, template)
108 def test_template_path_for(version, template)
106 assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
109 assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
107 @adapter.class.template_path_for(version)
110 @adapter.class.template_path_for(version)
108 assert File.exist?(@adapter.class.template_path_for(version))
111 assert File.exist?(@adapter.class.template_path_for(version))
109 end
112 end
110 else
113 else
111 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
114 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
112 def test_fake; assert true end
115 def test_fake; assert true end
113 end
116 end
114 end
117 end
115
118
116 rescue LoadError
119 rescue LoadError
117 class MercurialMochaFake < ActiveSupport::TestCase
120 class MercurialMochaFake < ActiveSupport::TestCase
118 def test_fake; assert(false, "Requires mocha to run those tests") end
121 def test_fake; assert(false, "Requires mocha to run those tests") end
119 end
122 end
120 end
123 end
121
124
General Comments 0
You need to be logged in to leave comments. Login now