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