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