@@ -1,356 +1,371 | |||||
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 | HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_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\/\.\.}, '') + |
|
11 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + | |
12 | '/tmp/test/mercurial_repository' |
|
12 | '/tmp/test/mercurial_repository' | |
13 |
|
13 | |||
14 | CHAR_1_HEX = "\xc3\x9c" |
|
14 | CHAR_1_HEX = "\xc3\x9c" | |
15 |
|
15 | |||
16 | if File.directory?(REPOSITORY_PATH) |
|
16 | if File.directory?(REPOSITORY_PATH) | |
17 | def setup |
|
17 | def setup | |
18 | adapter_class = Redmine::Scm::Adapters::MercurialAdapter |
|
18 | adapter_class = Redmine::Scm::Adapters::MercurialAdapter | |
19 | assert adapter_class |
|
19 | assert adapter_class | |
20 | assert adapter_class.client_command |
|
20 | assert adapter_class.client_command | |
21 | assert_equal true, adapter_class.client_available |
|
21 | assert_equal true, adapter_class.client_available | |
22 | assert_equal true, adapter_class.client_version_above?([0, 9, 5]) |
|
22 | assert_equal true, adapter_class.client_version_above?([0, 9, 5]) | |
23 |
|
23 | |||
24 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new( |
|
24 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new( | |
25 | REPOSITORY_PATH, |
|
25 | REPOSITORY_PATH, | |
26 | nil, |
|
26 | nil, | |
27 | nil, |
|
27 | nil, | |
28 | nil, |
|
28 | nil, | |
29 | 'ISO-8859-1') |
|
29 | 'ISO-8859-1') | |
30 | @diff_c_support = true |
|
30 | @diff_c_support = true | |
31 | @char_1 = CHAR_1_HEX.dup |
|
31 | @char_1 = CHAR_1_HEX.dup | |
32 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
32 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" | |
33 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
33 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" | |
34 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
34 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" | |
35 | if @tag_char_1.respond_to?(:force_encoding) |
|
35 | if @tag_char_1.respond_to?(:force_encoding) | |
36 | @char_1.force_encoding('UTF-8') |
|
36 | @char_1.force_encoding('UTF-8') | |
37 | @tag_char_1.force_encoding('UTF-8') |
|
37 | @tag_char_1.force_encoding('UTF-8') | |
38 | @branch_char_0.force_encoding('UTF-8') |
|
38 | @branch_char_0.force_encoding('UTF-8') | |
39 | @branch_char_1.force_encoding('UTF-8') |
|
39 | @branch_char_1.force_encoding('UTF-8') | |
40 | end |
|
40 | end | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def test_hgversion |
|
43 | def test_hgversion | |
44 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], |
|
44 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], | |
45 | "Mercurial Distributed SCM (1.0)\n" => [1,0], |
|
45 | "Mercurial Distributed SCM (1.0)\n" => [1,0], | |
46 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, |
|
46 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, | |
47 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], |
|
47 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], | |
48 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, |
|
48 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, | |
49 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], |
|
49 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], | |
50 | "(1.6)\n(1.7)\n(1.8)" => [1,6], |
|
50 | "(1.6)\n(1.7)\n(1.8)" => [1,6], | |
51 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} |
|
51 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} | |
52 |
|
52 | |||
53 | to_test.each do |s, v| |
|
53 | to_test.each do |s, v| | |
54 | test_hgversion_for(s, v) |
|
54 | test_hgversion_for(s, v) | |
55 | end |
|
55 | end | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | def test_template_path |
|
58 | def test_template_path | |
59 | to_test = { [0,9,5] => "0.9.5", |
|
59 | to_test = { [0,9,5] => "0.9.5", | |
60 | [1,0] => "1.0", |
|
60 | [1,0] => "1.0", | |
61 | [] => "1.0", |
|
61 | [] => "1.0", | |
62 | [1,0,1] => "1.0", |
|
62 | [1,0,1] => "1.0", | |
63 | [1,7] => "1.0", |
|
63 | [1,7] => "1.0", | |
64 | [1,7,1] => "1.0" } |
|
64 | [1,7,1] => "1.0" } | |
65 | to_test.each do |v, template| |
|
65 | to_test.each do |v, template| | |
66 | test_template_path_for(v, template) |
|
66 | test_template_path_for(v, template) | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | def test_info |
|
70 | def test_info | |
71 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", |
|
71 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", | |
72 | REPOSITORY_PATH + "//"].each do |repo| |
|
72 | REPOSITORY_PATH + "//"].each do |repo| | |
73 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) |
|
73 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) | |
74 | repo_path = adp.info.root_url.gsub(/\\/, "/") |
|
74 | repo_path = adp.info.root_url.gsub(/\\/, "/") | |
75 | assert_equal REPOSITORY_PATH, repo_path |
|
75 | assert_equal REPOSITORY_PATH, repo_path | |
76 | assert_equal '28', adp.info.lastrev.revision |
|
76 | assert_equal '28', adp.info.lastrev.revision | |
77 | assert_equal '3ae45e2d177d',adp.info.lastrev.scmid |
|
77 | assert_equal '3ae45e2d177d',adp.info.lastrev.scmid | |
78 | end |
|
78 | end | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_revisions |
|
81 | def test_revisions | |
82 | revisions = @adapter.revisions(nil, 2, 4) |
|
82 | revisions = @adapter.revisions(nil, 2, 4) | |
83 | assert_equal 3, revisions.size |
|
83 | assert_equal 3, revisions.size | |
84 | assert_equal '2', revisions[0].revision |
|
84 | assert_equal '2', revisions[0].revision | |
85 | assert_equal '400bb8672109', revisions[0].scmid |
|
85 | assert_equal '400bb8672109', revisions[0].scmid | |
86 | assert_equal '4', revisions[2].revision |
|
86 | assert_equal '4', revisions[2].revision | |
87 | assert_equal 'def6d2f1254a', revisions[2].scmid |
|
87 | assert_equal 'def6d2f1254a', revisions[2].scmid | |
88 |
|
88 | |||
89 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) |
|
89 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) | |
90 | assert_equal 2, revisions.size |
|
90 | assert_equal 2, revisions.size | |
91 | assert_equal '2', revisions[0].revision |
|
91 | assert_equal '2', revisions[0].revision | |
92 | assert_equal '400bb8672109', revisions[0].scmid |
|
92 | assert_equal '400bb8672109', revisions[0].scmid | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def test_diff |
|
95 | def test_diff | |
96 | if @adapter.class.client_version_above?([1, 2]) |
|
96 | if @adapter.class.client_version_above?([1, 2]) | |
97 | assert_nil @adapter.diff(nil, '100000') |
|
97 | assert_nil @adapter.diff(nil, '100000') | |
98 | end |
|
98 | end | |
99 | assert_nil @adapter.diff(nil, '100000', '200000') |
|
99 | assert_nil @adapter.diff(nil, '100000', '200000') | |
100 | [2, '400bb8672109', '400', 400].each do |r1| |
|
100 | [2, '400bb8672109', '400', 400].each do |r1| | |
101 | diff1 = @adapter.diff(nil, r1) |
|
101 | diff1 = @adapter.diff(nil, r1) | |
102 | if @diff_c_support |
|
102 | if @diff_c_support | |
103 | assert_equal 28, diff1.size |
|
103 | assert_equal 28, diff1.size | |
104 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") |
|
104 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") | |
105 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf |
|
105 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf | |
106 | else |
|
106 | else | |
107 | assert_equal 0, diff1.size |
|
107 | assert_equal 0, diff1.size | |
108 | end |
|
108 | end | |
109 | [4, 'def6d2f1254a'].each do |r2| |
|
109 | [4, 'def6d2f1254a'].each do |r2| | |
110 | diff2 = @adapter.diff(nil,r1,r2) |
|
110 | diff2 = @adapter.diff(nil,r1,r2) | |
111 | assert_equal 49, diff2.size |
|
111 | assert_equal 49, diff2.size | |
112 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") |
|
112 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") | |
113 | assert_equal "+class WelcomeController < ApplicationController", buf |
|
113 | assert_equal "+class WelcomeController < ApplicationController", buf | |
114 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) |
|
114 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) | |
115 | assert_equal 20, diff3.size |
|
115 | assert_equal 20, diff3.size | |
116 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") |
|
116 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") | |
117 | assert_equal "+ @watched.remove_watcher(user)", buf |
|
117 | assert_equal "+ @watched.remove_watcher(user)", buf | |
118 | end |
|
118 | end | |
119 | end |
|
119 | end | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | def test_diff_made_by_revision |
|
122 | def test_diff_made_by_revision | |
123 | if @diff_c_support |
|
123 | if @diff_c_support | |
124 | [24, '24', '4cddb4e45f52'].each do |r1| |
|
124 | [24, '24', '4cddb4e45f52'].each do |r1| | |
125 | diff1 = @adapter.diff(nil, r1) |
|
125 | diff1 = @adapter.diff(nil, r1) | |
126 | assert_equal 5, diff1.size |
|
126 | assert_equal 5, diff1.size | |
127 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") |
|
127 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") | |
128 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf |
|
128 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf | |
129 | end |
|
129 | end | |
130 | end |
|
130 | end | |
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | def test_cat |
|
133 | def test_cat | |
134 | [2, '400bb8672109', '400', 400].each do |r| |
|
134 | [2, '400bb8672109', '400', 400].each do |r| | |
135 | buf = @adapter.cat('sources/welcome_controller.rb', r) |
|
135 | buf = @adapter.cat('sources/welcome_controller.rb', r) | |
136 | assert buf |
|
136 | assert buf | |
137 | lines = buf.split("\r\n") |
|
137 | lines = buf.split("\r\n") | |
138 | assert_equal 25, lines.length |
|
138 | assert_equal 25, lines.length | |
139 | assert_equal 'class WelcomeController < ApplicationController', lines[17] |
|
139 | assert_equal 'class WelcomeController < ApplicationController', lines[17] | |
140 | end |
|
140 | end | |
141 | assert_nil @adapter.cat('sources/welcome_controller.rb') |
|
141 | assert_nil @adapter.cat('sources/welcome_controller.rb') | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | def test_annotate |
|
144 | def test_annotate | |
145 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines |
|
145 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines | |
146 | [2, '400bb8672109', '400', 400].each do |r| |
|
146 | [2, '400bb8672109', '400', 400].each do |r| | |
147 | ann = @adapter.annotate('sources/welcome_controller.rb', r) |
|
147 | ann = @adapter.annotate('sources/welcome_controller.rb', r) | |
148 | assert ann |
|
148 | assert ann | |
149 | assert_equal '1', ann.revisions[17].revision |
|
149 | assert_equal '1', ann.revisions[17].revision | |
150 | assert_equal '9d5b5b004199', ann.revisions[17].identifier |
|
150 | assert_equal '9d5b5b004199', ann.revisions[17].identifier | |
151 | assert_equal 'jsmith', ann.revisions[0].author |
|
151 | assert_equal 'jsmith', ann.revisions[0].author | |
152 | assert_equal 25, ann.lines.length |
|
152 | assert_equal 25, ann.lines.length | |
153 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] |
|
153 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] | |
154 | end |
|
154 | end | |
155 | end |
|
155 | end | |
156 |
|
156 | |||
157 | def test_entries |
|
157 | def test_entries | |
158 | assert_nil @adapter.entries(nil, '100000') |
|
158 | assert_nil @adapter.entries(nil, '100000') | |
159 |
|
159 | |||
160 | assert_equal 1, @adapter.entries("sources", 3).size |
|
160 | assert_equal 1, @adapter.entries("sources", 3).size | |
161 | assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size |
|
161 | assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size | |
162 |
|
162 | |||
163 | [2, '400bb8672109', '400', 400].each do |r| |
|
163 | [2, '400bb8672109', '400', 400].each do |r| | |
164 | entries1 = @adapter.entries(nil, r) |
|
164 | entries1 = @adapter.entries(nil, r) | |
165 | assert entries1 |
|
165 | assert entries1 | |
166 | assert_equal 3, entries1.size |
|
166 | assert_equal 3, entries1.size | |
167 | assert_equal 'sources', entries1[1].name |
|
167 | assert_equal 'sources', entries1[1].name | |
168 | assert_equal 'sources', entries1[1].path |
|
168 | assert_equal 'sources', entries1[1].path | |
169 | assert_equal 'dir', entries1[1].kind |
|
169 | assert_equal 'dir', entries1[1].kind | |
170 | readme = entries1[2] |
|
170 | readme = entries1[2] | |
171 | assert_equal 'README', readme.name |
|
171 | assert_equal 'README', readme.name | |
172 | assert_equal 'README', readme.path |
|
172 | assert_equal 'README', readme.path | |
173 | assert_equal 'file', readme.kind |
|
173 | assert_equal 'file', readme.kind | |
174 | assert_equal 27, readme.size |
|
174 | assert_equal 27, readme.size | |
175 | assert_equal '1', readme.lastrev.revision |
|
175 | assert_equal '1', readme.lastrev.revision | |
176 | assert_equal '9d5b5b004199', readme.lastrev.identifier |
|
176 | assert_equal '9d5b5b004199', readme.lastrev.identifier | |
177 | # 2007-12-14 10:24:01 +0100 |
|
177 | # 2007-12-14 10:24:01 +0100 | |
178 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time |
|
178 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time | |
179 |
|
179 | |||
180 | entries2 = @adapter.entries('sources', r) |
|
180 | entries2 = @adapter.entries('sources', r) | |
181 | assert entries2 |
|
181 | assert entries2 | |
182 | assert_equal 2, entries2.size |
|
182 | assert_equal 2, entries2.size | |
183 | assert_equal 'watchers_controller.rb', entries2[0].name |
|
183 | assert_equal 'watchers_controller.rb', entries2[0].name | |
184 | assert_equal 'sources/watchers_controller.rb', entries2[0].path |
|
184 | assert_equal 'sources/watchers_controller.rb', entries2[0].path | |
185 | assert_equal 'file', entries2[0].kind |
|
185 | assert_equal 'file', entries2[0].kind | |
186 | assert_equal 'welcome_controller.rb', entries2[1].name |
|
186 | assert_equal 'welcome_controller.rb', entries2[1].name | |
187 | assert_equal 'sources/welcome_controller.rb', entries2[1].path |
|
187 | assert_equal 'sources/welcome_controller.rb', entries2[1].path | |
188 | assert_equal 'file', entries2[1].kind |
|
188 | assert_equal 'file', entries2[1].kind | |
189 | end |
|
189 | end | |
190 | end |
|
190 | end | |
191 |
|
191 | |||
192 | def test_entries_tag |
|
192 | def test_entries_tag | |
193 | entries1 = @adapter.entries(nil, 'tag_test.00') |
|
193 | entries1 = @adapter.entries(nil, 'tag_test.00') | |
194 | assert entries1 |
|
194 | assert entries1 | |
195 | assert_equal 3, entries1.size |
|
195 | assert_equal 3, entries1.size | |
196 | assert_equal 'sources', entries1[1].name |
|
196 | assert_equal 'sources', entries1[1].name | |
197 | assert_equal 'sources', entries1[1].path |
|
197 | assert_equal 'sources', entries1[1].path | |
198 | assert_equal 'dir', entries1[1].kind |
|
198 | assert_equal 'dir', entries1[1].kind | |
199 | readme = entries1[2] |
|
199 | readme = entries1[2] | |
200 | assert_equal 'README', readme.name |
|
200 | assert_equal 'README', readme.name | |
201 | assert_equal 'README', readme.path |
|
201 | assert_equal 'README', readme.path | |
202 | assert_equal 'file', readme.kind |
|
202 | assert_equal 'file', readme.kind | |
203 | assert_equal 21, readme.size |
|
203 | assert_equal 21, readme.size | |
204 | assert_equal '0', readme.lastrev.revision |
|
204 | assert_equal '0', readme.lastrev.revision | |
205 | assert_equal '0885933ad4f6', readme.lastrev.identifier |
|
205 | assert_equal '0885933ad4f6', readme.lastrev.identifier | |
206 | # 2007-12-14 10:22:52 +0100 |
|
206 | # 2007-12-14 10:22:52 +0100 | |
207 | assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time |
|
207 | assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | def test_entries_branch |
|
210 | def test_entries_branch | |
211 | entries1 = @adapter.entries(nil, 'test-branch-00') |
|
211 | entries1 = @adapter.entries(nil, 'test-branch-00') | |
212 | assert entries1 |
|
212 | assert entries1 | |
213 | assert_equal 5, entries1.size |
|
213 | assert_equal 5, entries1.size | |
214 | assert_equal 'sql_escape', entries1[2].name |
|
214 | assert_equal 'sql_escape', entries1[2].name | |
215 | assert_equal 'sql_escape', entries1[2].path |
|
215 | assert_equal 'sql_escape', entries1[2].path | |
216 | assert_equal 'dir', entries1[2].kind |
|
216 | assert_equal 'dir', entries1[2].kind | |
217 | readme = entries1[4] |
|
217 | readme = entries1[4] | |
218 | assert_equal 'README', readme.name |
|
218 | assert_equal 'README', readme.name | |
219 | assert_equal 'README', readme.path |
|
219 | assert_equal 'README', readme.path | |
220 | assert_equal 'file', readme.kind |
|
220 | assert_equal 'file', readme.kind | |
221 | assert_equal 365, readme.size |
|
221 | assert_equal 365, readme.size | |
222 | assert_equal '8', readme.lastrev.revision |
|
222 | assert_equal '8', readme.lastrev.revision | |
223 | assert_equal 'c51f5bb613cd', readme.lastrev.identifier |
|
223 | assert_equal 'c51f5bb613cd', readme.lastrev.identifier | |
224 | # 2001-02-01 00:00:00 -0900 |
|
224 | # 2001-02-01 00:00:00 -0900 | |
225 | assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time |
|
225 | assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time | |
226 | end |
|
226 | end | |
227 |
|
227 | |||
228 | def test_locate_on_outdated_repository |
|
228 | def test_locate_on_outdated_repository | |
229 | assert_equal 1, @adapter.entries("images", 0).size |
|
229 | assert_equal 1, @adapter.entries("images", 0).size | |
230 | assert_equal 2, @adapter.entries("images").size |
|
230 | assert_equal 2, @adapter.entries("images").size | |
231 | assert_equal 2, @adapter.entries("images", 2).size |
|
231 | assert_equal 2, @adapter.entries("images", 2).size | |
232 | end |
|
232 | end | |
233 |
|
233 | |||
234 | def test_access_by_nodeid |
|
234 | def test_access_by_nodeid | |
235 | path = 'sources/welcome_controller.rb' |
|
235 | path = 'sources/welcome_controller.rb' | |
236 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') |
|
236 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') | |
237 | end |
|
237 | end | |
238 |
|
238 | |||
239 | def test_access_by_fuzzy_nodeid |
|
239 | def test_access_by_fuzzy_nodeid | |
240 | path = 'sources/welcome_controller.rb' |
|
240 | path = 'sources/welcome_controller.rb' | |
241 | # falls back to nodeid |
|
241 | # falls back to nodeid | |
242 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') |
|
242 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') | |
243 | end |
|
243 | end | |
244 |
|
244 | |||
245 | def test_tags |
|
245 | def test_tags | |
246 | assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags |
|
246 | assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags | |
247 | end |
|
247 | end | |
248 |
|
248 | |||
249 | def test_tagmap |
|
249 | def test_tagmap | |
250 | tm = { |
|
250 | tm = { | |
251 | @tag_char_1 => 'adf805632193', |
|
251 | @tag_char_1 => 'adf805632193', | |
252 | 'tag_test.00' => '6987191f453a', |
|
252 | 'tag_test.00' => '6987191f453a', | |
253 | 'tag-init-revision' => '0885933ad4f6', |
|
253 | 'tag-init-revision' => '0885933ad4f6', | |
254 | } |
|
254 | } | |
255 | assert_equal tm, @adapter.tagmap |
|
255 | assert_equal tm, @adapter.tagmap | |
256 | end |
|
256 | end | |
257 |
|
257 | |||
258 | def test_branches |
|
258 | def test_branches | |
259 | assert_equal [ |
|
259 | assert_equal [ | |
260 | 'default', |
|
260 | 'default', | |
261 | @branch_char_1, |
|
261 | @branch_char_1, | |
262 | 'branch (1)[2]&,%.-3_4', |
|
262 | 'branch (1)[2]&,%.-3_4', | |
263 | @branch_char_0, |
|
263 | @branch_char_0, | |
264 | 'test_branch.latin-1', |
|
264 | 'test_branch.latin-1', | |
265 | 'test-branch-00', |
|
265 | 'test-branch-00', | |
266 | ], @adapter.branches |
|
266 | ], @adapter.branches | |
267 | end |
|
267 | end | |
268 |
|
268 | |||
269 | def test_branchmap |
|
269 | def test_branchmap | |
270 | bm = { |
|
270 | bm = { | |
271 | 'default' => '3ae45e2d177d', |
|
271 | 'default' => '3ae45e2d177d', | |
272 | 'test_branch.latin-1' => 'c2ffe7da686a', |
|
272 | 'test_branch.latin-1' => 'c2ffe7da686a', | |
273 | 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7', |
|
273 | 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7', | |
274 | 'test-branch-00' => '3a330eb32958', |
|
274 | 'test-branch-00' => '3a330eb32958', | |
275 | @branch_char_0 => 'c8d3e4887474', |
|
275 | @branch_char_0 => 'c8d3e4887474', | |
276 | @branch_char_1 => '7bbf4c738e71', |
|
276 | @branch_char_1 => '7bbf4c738e71', | |
277 | } |
|
277 | } | |
278 | assert_equal bm, @adapter.branchmap |
|
278 | assert_equal bm, @adapter.branchmap | |
279 | end |
|
279 | end | |
280 |
|
280 | |||
281 | def test_path_space |
|
281 | def test_path_space | |
282 | p = 'README (1)[2]&,%.-3_4' |
|
282 | p = 'README (1)[2]&,%.-3_4' | |
283 | [15, '933ca60293d7'].each do |r1| |
|
283 | [15, '933ca60293d7'].each do |r1| | |
284 | assert @adapter.diff(p, r1) |
|
284 | assert @adapter.diff(p, r1) | |
285 | assert @adapter.cat(p, r1) |
|
285 | assert @adapter.cat(p, r1) | |
286 | assert_equal 1, @adapter.annotate(p, r1).lines.length |
|
286 | assert_equal 1, @adapter.annotate(p, r1).lines.length | |
287 | [25, 'afc61e85bde7'].each do |r2| |
|
287 | [25, 'afc61e85bde7'].each do |r2| | |
288 | assert @adapter.diff(p, r1, r2) |
|
288 | assert @adapter.diff(p, r1, r2) | |
289 | end |
|
289 | end | |
290 | end |
|
290 | end | |
291 | end |
|
291 | end | |
292 |
|
292 | |||
293 | def test_tag_non_ascii |
|
293 | def test_tag_non_ascii | |
294 | p = "latin-1-dir/test-#{@char_1}-1.txt" |
|
294 | p = "latin-1-dir/test-#{@char_1}-1.txt" | |
295 | assert @adapter.cat(p, @tag_char_1) |
|
295 | assert @adapter.cat(p, @tag_char_1) | |
296 | assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length |
|
296 | assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length | |
297 | end |
|
297 | end | |
298 |
|
298 | |||
299 | def test_branch_non_ascii |
|
299 | def test_branch_non_ascii | |
300 | p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt" |
|
300 | p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt" | |
301 | assert @adapter.cat(p, @branch_char_1) |
|
301 | assert @adapter.cat(p, @branch_char_1) | |
302 | assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length |
|
302 | assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length | |
303 | end |
|
303 | end | |
304 |
|
304 | |||
305 | def test_nodes_in_branch |
|
305 | def test_nodes_in_branch | |
306 | [ |
|
306 | [ | |
307 | 'default', |
|
307 | 'default', | |
308 | @branch_char_1, |
|
308 | @branch_char_1, | |
309 | 'branch (1)[2]&,%.-3_4', |
|
309 | 'branch (1)[2]&,%.-3_4', | |
310 | @branch_char_0, |
|
310 | @branch_char_0, | |
311 | 'test_branch.latin-1', |
|
311 | 'test_branch.latin-1', | |
312 | 'test-branch-00', |
|
312 | 'test-branch-00', | |
313 | ].each do |bra| |
|
313 | ].each do |bra| | |
314 | nib0 = @adapter.nodes_in_branch(bra) |
|
314 | nib0 = @adapter.nodes_in_branch(bra) | |
315 | assert nib0 |
|
315 | assert nib0 | |
316 | nib1 = @adapter.nodes_in_branch(bra, :limit => 1) |
|
316 | nib1 = @adapter.nodes_in_branch(bra, :limit => 1) | |
317 | assert_equal 1, nib1.size |
|
317 | assert_equal 1, nib1.size | |
318 | case bra |
|
318 | case bra | |
319 | when 'branch (1)[2]&,%.-3_4' |
|
319 | when 'branch (1)[2]&,%.-3_4' | |
320 | assert_equal 3, nib0.size |
|
320 | assert_equal 3, nib0.size | |
321 | assert_equal nib0[0], 'afc61e85bde7' |
|
321 | assert_equal nib0[0], 'afc61e85bde7' | |
322 | nib2 = @adapter.nodes_in_branch(bra, :limit => 2) |
|
322 | nib2 = @adapter.nodes_in_branch(bra, :limit => 2) | |
323 | assert_equal 2, nib2.size |
|
323 | assert_equal 2, nib2.size | |
324 | assert_equal nib2[1], '933ca60293d7' |
|
324 | assert_equal nib2[1], '933ca60293d7' | |
325 | when @branch_char_1 |
|
325 | when @branch_char_1 | |
326 | assert_equal 2, nib0.size |
|
326 | assert_equal 2, nib0.size | |
327 | assert_equal nib0[1], '08ff3227303e' |
|
327 | assert_equal nib0[1], '08ff3227303e' | |
328 | nib2 = @adapter.nodes_in_branch(bra, :limit => 1) |
|
328 | nib2 = @adapter.nodes_in_branch(bra, :limit => 1) | |
329 | assert_equal 1, nib2.size |
|
329 | assert_equal 1, nib2.size | |
330 | assert_equal nib2[0], '7bbf4c738e71' |
|
330 | assert_equal nib2[0], '7bbf4c738e71' | |
331 | end |
|
331 | end | |
332 | end |
|
332 | end | |
333 | end |
|
333 | end | |
334 |
|
334 | |||
|
335 | def test_path_encoding_default_utf8 | |||
|
336 | adpt1 = Redmine::Scm::Adapters::MercurialAdapter.new( | |||
|
337 | REPOSITORY_PATH | |||
|
338 | ) | |||
|
339 | assert_equal "UTF-8", adpt1.path_encoding | |||
|
340 | adpt2 = Redmine::Scm::Adapters::MercurialAdapter.new( | |||
|
341 | REPOSITORY_PATH, | |||
|
342 | nil, | |||
|
343 | nil, | |||
|
344 | nil, | |||
|
345 | "" | |||
|
346 | ) | |||
|
347 | assert_equal "UTF-8", adpt2.path_encoding | |||
|
348 | end | |||
|
349 | ||||
335 | private |
|
350 | private | |
336 |
|
351 | |||
337 | def test_hgversion_for(hgversion, version) |
|
352 | def test_hgversion_for(hgversion, version) | |
338 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) |
|
353 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) | |
339 | assert_equal version, @adapter.class.hgversion |
|
354 | assert_equal version, @adapter.class.hgversion | |
340 | end |
|
355 | end | |
341 |
|
356 | |||
342 | def test_template_path_for(version, template) |
|
357 | def test_template_path_for(version, template) | |
343 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", |
|
358 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", | |
344 | @adapter.class.template_path_for(version) |
|
359 | @adapter.class.template_path_for(version) | |
345 | assert File.exist?(@adapter.class.template_path_for(version)) |
|
360 | assert File.exist?(@adapter.class.template_path_for(version)) | |
346 | end |
|
361 | end | |
347 | else |
|
362 | else | |
348 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
363 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
349 | def test_fake; assert true end |
|
364 | def test_fake; assert true end | |
350 | end |
|
365 | end | |
351 | end |
|
366 | end | |
352 | rescue LoadError |
|
367 | rescue LoadError | |
353 | class MercurialMochaFake < ActiveSupport::TestCase |
|
368 | class MercurialMochaFake < ActiveSupport::TestCase | |
354 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
369 | def test_fake; assert(false, "Requires mocha to run those tests") end | |
355 | end |
|
370 | end | |
356 | end |
|
371 | end |
General Comments 0
You need to be logged in to leave comments.
Login now