@@ -1,192 +1,193 | |||
|
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 | HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_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 | @diff_c_support = true |
|
17 | 17 | end |
|
18 | 18 | |
|
19 | 19 | def test_hgversion |
|
20 | 20 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], |
|
21 | 21 | "Mercurial Distributed SCM (1.0)\n" => [1,0], |
|
22 | 22 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, |
|
23 | 23 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], |
|
24 | 24 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, |
|
25 | 25 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], |
|
26 | 26 | "(1.6)\n(1.7)\n(1.8)" => [1,6], |
|
27 | 27 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} |
|
28 | 28 | |
|
29 | 29 | to_test.each do |s, v| |
|
30 | 30 | test_hgversion_for(s, v) |
|
31 | 31 | end |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_template_path |
|
35 | 35 | to_test = { [0,9,5] => "0.9.5", |
|
36 | 36 | [1,0] => "1.0", |
|
37 | 37 | [] => "1.0", |
|
38 | 38 | [1,0,1] => "1.0", |
|
39 | 39 | [1,7] => "1.0", |
|
40 | 40 | [1,7,1] => "1.0" } |
|
41 | 41 | to_test.each do |v, template| |
|
42 | 42 | test_template_path_for(v, template) |
|
43 | 43 | end |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def test_info |
|
47 | 47 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", |
|
48 | 48 | REPOSITORY_PATH + "//"].each do |repo| |
|
49 | 49 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) |
|
50 | assert_equal REPOSITORY_PATH, adp.info.root_url | |
|
50 | repo_path = adp.info.root_url.gsub(/\\/, "/") | |
|
51 | assert_equal REPOSITORY_PATH, repo_path | |
|
51 | 52 | assert_equal '16', adp.info.lastrev.revision |
|
52 | 53 | assert_equal '4cddb4e45f52',adp.info.lastrev.scmid |
|
53 | 54 | end |
|
54 | 55 | end |
|
55 | 56 | |
|
56 | 57 | def test_revisions |
|
57 | 58 | revisions = @adapter.revisions(nil, 2, 4) |
|
58 | 59 | assert_equal 3, revisions.size |
|
59 | 60 | assert_equal '2', revisions[0].revision |
|
60 | 61 | assert_equal '400bb8672109', revisions[0].scmid |
|
61 | 62 | assert_equal '4', revisions[2].revision |
|
62 | 63 | assert_equal 'def6d2f1254a', revisions[2].scmid |
|
63 | 64 | |
|
64 | 65 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) |
|
65 | 66 | assert_equal 2, revisions.size |
|
66 | 67 | assert_equal '2', revisions[0].revision |
|
67 | 68 | assert_equal '400bb8672109', revisions[0].scmid |
|
68 | 69 | end |
|
69 | 70 | |
|
70 | 71 | def test_diff |
|
71 | 72 | if @adapter.class.client_version_above?([1, 2]) |
|
72 | 73 | assert_nil @adapter.diff(nil, '100000') |
|
73 | 74 | end |
|
74 | 75 | assert_nil @adapter.diff(nil, '100000', '200000') |
|
75 | 76 | [2, '400bb8672109', '400', 400].each do |r1| |
|
76 | 77 | diff1 = @adapter.diff(nil, r1) |
|
77 | 78 | if @diff_c_support |
|
78 | 79 | assert_equal 28, diff1.size |
|
79 | 80 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") |
|
80 | 81 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf |
|
81 | 82 | else |
|
82 | 83 | assert_equal 0, diff1.size |
|
83 | 84 | end |
|
84 | 85 | [4, 'def6d2f1254a'].each do |r2| |
|
85 | 86 | diff2 = @adapter.diff(nil,r1,r2) |
|
86 | 87 | assert_equal 49, diff2.size |
|
87 | 88 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") |
|
88 | 89 | assert_equal "+class WelcomeController < ApplicationController", buf |
|
89 | 90 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) |
|
90 | 91 | assert_equal 20, diff3.size |
|
91 | 92 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") |
|
92 | 93 | assert_equal "+ @watched.remove_watcher(user)", buf |
|
93 | 94 | end |
|
94 | 95 | end |
|
95 | 96 | end |
|
96 | 97 | |
|
97 | 98 | def test_diff_made_by_revision |
|
98 | 99 | if @diff_c_support |
|
99 | 100 | [16, '16', '4cddb4e45f52'].each do |r1| |
|
100 | 101 | diff1 = @adapter.diff(nil, r1) |
|
101 | 102 | assert_equal 5, diff1.size |
|
102 | 103 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") |
|
103 | 104 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf |
|
104 | 105 | end |
|
105 | 106 | end |
|
106 | 107 | end |
|
107 | 108 | |
|
108 | 109 | def test_cat |
|
109 | 110 | [2, '400bb8672109', '400', 400].each do |r| |
|
110 | 111 | buf = @adapter.cat('sources/welcome_controller.rb', r) |
|
111 | 112 | assert buf |
|
112 | 113 | lines = buf.split("\r\n") |
|
113 | 114 | assert_equal 25, lines.length |
|
114 | 115 | assert_equal 'class WelcomeController < ApplicationController', lines[17] |
|
115 | 116 | end |
|
116 | 117 | assert_nil @adapter.cat('sources/welcome_controller.rb') |
|
117 | 118 | end |
|
118 | 119 | |
|
119 | 120 | def test_annotate |
|
120 | 121 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines |
|
121 | 122 | [2, '400bb8672109', '400', 400].each do |r| |
|
122 | 123 | ann = @adapter.annotate('sources/welcome_controller.rb', r) |
|
123 | 124 | assert ann |
|
124 | 125 | assert_equal '1', ann.revisions[17].revision |
|
125 | 126 | assert_equal '9d5b5b004199', ann.revisions[17].identifier |
|
126 | 127 | assert_equal 'jsmith', ann.revisions[0].author |
|
127 | 128 | assert_equal 25, ann.lines.length |
|
128 | 129 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] |
|
129 | 130 | end |
|
130 | 131 | end |
|
131 | 132 | |
|
132 | 133 | # TODO filesize etc. |
|
133 | 134 | def test_entries |
|
134 | 135 | assert_nil @adapter.entries(nil, '100000') |
|
135 | 136 | [2, '400bb8672109', '400', 400].each do |r| |
|
136 | 137 | entries1 = @adapter.entries(nil, r) |
|
137 | 138 | assert entries1 |
|
138 | 139 | assert_equal 3, entries1.size |
|
139 | 140 | assert_equal 'sources', entries1[1].name |
|
140 | 141 | assert_equal 'sources', entries1[1].path |
|
141 | 142 | assert_equal 'dir', entries1[1].kind |
|
142 | 143 | assert_equal 'README', entries1[2].name |
|
143 | 144 | assert_equal 'README', entries1[2].path |
|
144 | 145 | assert_equal 'file', entries1[2].kind |
|
145 | 146 | |
|
146 | 147 | entries2 = @adapter.entries('sources', r) |
|
147 | 148 | assert entries2 |
|
148 | 149 | assert_equal 2, entries2.size |
|
149 | 150 | assert_equal 'watchers_controller.rb', entries2[0].name |
|
150 | 151 | assert_equal 'sources/watchers_controller.rb', entries2[0].path |
|
151 | 152 | assert_equal 'file', entries2[0].kind |
|
152 | 153 | assert_equal 'welcome_controller.rb', entries2[1].name |
|
153 | 154 | assert_equal 'sources/welcome_controller.rb', entries2[1].path |
|
154 | 155 | assert_equal 'file', entries2[1].kind |
|
155 | 156 | end |
|
156 | 157 | end |
|
157 | 158 | |
|
158 | 159 | def test_access_by_nodeid |
|
159 | 160 | path = 'sources/welcome_controller.rb' |
|
160 | 161 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') |
|
161 | 162 | end |
|
162 | 163 | |
|
163 | 164 | def test_access_by_fuzzy_nodeid |
|
164 | 165 | path = 'sources/welcome_controller.rb' |
|
165 | 166 | # falls back to nodeid |
|
166 | 167 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') |
|
167 | 168 | end |
|
168 | 169 | |
|
169 | 170 | private |
|
170 | 171 | |
|
171 | 172 | def test_hgversion_for(hgversion, version) |
|
172 | 173 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) |
|
173 | 174 | assert_equal version, @adapter.class.hgversion |
|
174 | 175 | end |
|
175 | 176 | |
|
176 | 177 | def test_template_path_for(version, template) |
|
177 | 178 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", |
|
178 | 179 | @adapter.class.template_path_for(version) |
|
179 | 180 | assert File.exist?(@adapter.class.template_path_for(version)) |
|
180 | 181 | end |
|
181 | 182 | else |
|
182 | 183 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
183 | 184 | def test_fake; assert true end |
|
184 | 185 | end |
|
185 | 186 | end |
|
186 | 187 | |
|
187 | 188 | rescue LoadError |
|
188 | 189 | class MercurialMochaFake < ActiveSupport::TestCase |
|
189 | 190 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
190 | 191 | end |
|
191 | 192 | end |
|
192 | 193 |
General Comments 0
You need to be logged in to leave comments.
Login now