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