Mercurial > hg > soundsoftware-site
comparison test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb @ 245:051f544170fe
* Update to SVN trunk revision 4993
author | Chris Cannam |
---|---|
date | Thu, 03 Mar 2011 11:42:28 +0000 |
parents | 0579821a129a |
children | eeebe205a056 cbce1fd3b1b7 |
comparison
equal
deleted
inserted
replaced
244:8972b600f4fb | 245:051f544170fe |
---|---|
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 HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_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 @diff_c_support = true | |
16 end | 17 end |
17 | 18 |
18 def test_hgversion | 19 def test_hgversion |
19 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], | 20 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], |
20 "Mercurial Distributed SCM (1.0)\n" => [1,0], | 21 "Mercurial Distributed SCM (1.0)\n" => [1,0], |
40 to_test.each do |v, template| | 41 to_test.each do |v, template| |
41 test_template_path_for(v, template) | 42 test_template_path_for(v, template) |
42 end | 43 end |
43 end | 44 end |
44 | 45 |
46 def test_info | |
47 [REPOSITORY_PATH, REPOSITORY_PATH + "/", | |
48 REPOSITORY_PATH + "//"].each do |repo| | |
49 adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) | |
50 repo_path = adp.info.root_url.gsub(/\\/, "/") | |
51 assert_equal REPOSITORY_PATH, repo_path | |
52 assert_equal '16', adp.info.lastrev.revision | |
53 assert_equal '4cddb4e45f52',adp.info.lastrev.scmid | |
54 end | |
55 end | |
56 | |
57 def test_revisions | |
58 revisions = @adapter.revisions(nil, 2, 4) | |
59 assert_equal 3, revisions.size | |
60 assert_equal '2', revisions[0].revision | |
61 assert_equal '400bb8672109', revisions[0].scmid | |
62 assert_equal '4', revisions[2].revision | |
63 assert_equal 'def6d2f1254a', revisions[2].scmid | |
64 | |
65 revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) | |
66 assert_equal 2, revisions.size | |
67 assert_equal '2', revisions[0].revision | |
68 assert_equal '400bb8672109', revisions[0].scmid | |
69 end | |
70 | |
45 def test_diff | 71 def test_diff |
46 if @adapter.class.client_version_above?([1, 2]) | 72 if @adapter.class.client_version_above?([1, 2]) |
47 assert_nil @adapter.diff(nil, '100000') | 73 assert_nil @adapter.diff(nil, '100000') |
48 end | 74 end |
49 assert_nil @adapter.diff(nil, '100000', '200000') | 75 assert_nil @adapter.diff(nil, '100000', '200000') |
50 [2, '400bb8672109', '400', 400].each do |r1| | 76 [2, '400bb8672109', '400', 400].each do |r1| |
51 diff1 = @adapter.diff(nil, r1) | 77 diff1 = @adapter.diff(nil, r1) |
52 if @adapter.class.client_version_above?([1, 2]) | 78 if @diff_c_support |
53 assert_equal 28, diff1.size | 79 assert_equal 28, diff1.size |
54 buf = diff1[24].gsub(/\r\n|\r|\n/, "") | 80 buf = diff1[24].gsub(/\r\n|\r|\n/, "") |
55 assert_equal "+ return true unless klass.respond_to?('watched_by')", buf | 81 assert_equal "+ return true unless klass.respond_to?('watched_by')", buf |
56 else | 82 else |
57 assert_equal 0, diff1.size | 83 assert_equal 0, diff1.size |
68 end | 94 end |
69 end | 95 end |
70 end | 96 end |
71 | 97 |
72 def test_diff_made_by_revision | 98 def test_diff_made_by_revision |
73 if @adapter.class.client_version_above?([1, 2]) | 99 if @diff_c_support |
74 [16, '16', '4cddb4e45f52'].each do |r1| | 100 [16, '16', '4cddb4e45f52'].each do |r1| |
75 diff1 = @adapter.diff(nil, r1) | 101 diff1 = @adapter.diff(nil, r1) |
76 assert_equal 5, diff1.size | 102 assert_equal 5, diff1.size |
77 buf = diff1[4].gsub(/\r\n|\r|\n/, "") | 103 buf = diff1[4].gsub(/\r\n|\r|\n/, "") |
78 assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf | 104 assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf |
102 assert_equal 25, ann.lines.length | 128 assert_equal 25, ann.lines.length |
103 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] | 129 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] |
104 end | 130 end |
105 end | 131 end |
106 | 132 |
107 # TODO filesize etc. | |
108 def test_entries | 133 def test_entries |
109 assert_nil @adapter.entries(nil, '100000') | 134 assert_nil @adapter.entries(nil, '100000') |
135 | |
136 assert_equal 1, @adapter.entries("sources", 3).size | |
137 assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size | |
138 | |
110 [2, '400bb8672109', '400', 400].each do |r| | 139 [2, '400bb8672109', '400', 400].each do |r| |
111 entries1 = @adapter.entries(nil, r) | 140 entries1 = @adapter.entries(nil, r) |
112 assert entries1 | 141 assert entries1 |
113 assert_equal 3, entries1.size | 142 assert_equal 3, entries1.size |
114 assert_equal 'sources', entries1[1].name | 143 assert_equal 'sources', entries1[1].name |
115 assert_equal 'sources', entries1[1].path | 144 assert_equal 'sources', entries1[1].path |
116 assert_equal 'dir', entries1[1].kind | 145 assert_equal 'dir', entries1[1].kind |
117 assert_equal 'README', entries1[2].name | 146 readme = entries1[2] |
118 assert_equal 'README', entries1[2].path | 147 assert_equal 'README', readme.name |
119 assert_equal 'file', entries1[2].kind | 148 assert_equal 'README', readme.path |
149 assert_equal 'file', readme.kind | |
150 assert_equal 27, readme.size | |
151 assert_equal '1', readme.lastrev.revision | |
152 assert_equal '9d5b5b004199', readme.lastrev.identifier | |
153 # 2007-12-14 10:24:01 +0100 | |
154 assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time | |
120 | 155 |
121 entries2 = @adapter.entries('sources', r) | 156 entries2 = @adapter.entries('sources', r) |
122 assert entries2 | 157 assert entries2 |
123 assert_equal 2, entries2.size | 158 assert_equal 2, entries2.size |
124 assert_equal 'watchers_controller.rb', entries2[0].name | 159 assert_equal 'watchers_controller.rb', entries2[0].name |
128 assert_equal 'sources/welcome_controller.rb', entries2[1].path | 163 assert_equal 'sources/welcome_controller.rb', entries2[1].path |
129 assert_equal 'file', entries2[1].kind | 164 assert_equal 'file', entries2[1].kind |
130 end | 165 end |
131 end | 166 end |
132 | 167 |
168 def test_entries_tag | |
169 entries1 = @adapter.entries(nil, 'tag_test.00') | |
170 assert entries1 | |
171 assert_equal 3, entries1.size | |
172 assert_equal 'sources', entries1[1].name | |
173 assert_equal 'sources', entries1[1].path | |
174 assert_equal 'dir', entries1[1].kind | |
175 readme = entries1[2] | |
176 assert_equal 'README', readme.name | |
177 assert_equal 'README', readme.path | |
178 assert_equal 'file', readme.kind | |
179 assert_equal 21, readme.size | |
180 assert_equal '0', readme.lastrev.revision | |
181 assert_equal '0885933ad4f6', readme.lastrev.identifier | |
182 # 2007-12-14 10:22:52 +0100 | |
183 assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time | |
184 end | |
185 | |
186 def test_entries_branch | |
187 entries1 = @adapter.entries(nil, 'test-branch-00') | |
188 assert entries1 | |
189 assert_equal 5, entries1.size | |
190 assert_equal 'sql_escape', entries1[2].name | |
191 assert_equal 'sql_escape', entries1[2].path | |
192 assert_equal 'dir', entries1[2].kind | |
193 readme = entries1[4] | |
194 assert_equal 'README', readme.name | |
195 assert_equal 'README', readme.path | |
196 assert_equal 'file', readme.kind | |
197 assert_equal 365, readme.size | |
198 assert_equal '8', readme.lastrev.revision | |
199 assert_equal 'c51f5bb613cd', readme.lastrev.identifier | |
200 # 2001-02-01 00:00:00 -0900 | |
201 assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time | |
202 end | |
203 | |
204 def test_locate_on_outdated_repository | |
205 assert_equal 1, @adapter.entries("images", 0).size | |
206 assert_equal 2, @adapter.entries("images").size | |
207 assert_equal 2, @adapter.entries("images", 2).size | |
208 end | |
209 | |
133 def test_access_by_nodeid | 210 def test_access_by_nodeid |
134 path = 'sources/welcome_controller.rb' | 211 path = 'sources/welcome_controller.rb' |
135 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') | 212 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') |
136 end | 213 end |
137 | 214 |
139 path = 'sources/welcome_controller.rb' | 216 path = 'sources/welcome_controller.rb' |
140 # falls back to nodeid | 217 # falls back to nodeid |
141 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') | 218 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') |
142 end | 219 end |
143 | 220 |
221 def test_tags | |
222 assert_equal ['tag_test.00', 'tag-init-revision'], @adapter.tags | |
223 end | |
224 | |
225 def test_tagmap | |
226 tm = { 'tag_test.00' => '6987191f453a', | |
227 'tag-init-revision' => '0885933ad4f6' } | |
228 assert_equal tm, @adapter.tagmap | |
229 end | |
230 | |
231 def test_branches | |
232 assert_equal ['default', 'branch (1)[2]&,%.-3_4', 'test-branch-00'], | |
233 @adapter.branches | |
234 end | |
235 | |
236 def test_branchmap | |
237 bm = { 'default' => '4cddb4e45f52', | |
238 'branch (1)[2]&,%.-3_4' => '933ca60293d7', | |
239 'test-branch-00' => '3a330eb32958' } | |
240 assert_equal bm, @adapter.branchmap | |
241 end | |
242 | |
144 private | 243 private |
145 | 244 |
146 def test_hgversion_for(hgversion, version) | 245 def test_hgversion_for(hgversion, version) |
147 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) | 246 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) |
148 assert_equal version, @adapter.class.hgversion | 247 assert_equal version, @adapter.class.hgversion |
149 end | 248 end |
150 | 249 |
151 def test_template_path_for(version, template) | 250 def test_template_path_for(version, template) |
152 assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", | 251 assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", |
153 @adapter.class.template_path_for(version) | 252 @adapter.class.template_path_for(version) |
154 assert File.exist?(@adapter.class.template_path_for(version)) | 253 assert File.exist?(@adapter.class.template_path_for(version)) |
155 end | 254 end |
156 else | 255 else |
157 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | 256 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |