Mercurial > hg > soundsoftware-site
comparison .svn/pristine/74/74659fa6cdf8fb6e2bcf14986b0b23d99872b7b3.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../../../../../test_helper', __FILE__) | |
19 begin | |
20 require 'mocha' | |
21 | |
22 class BazaarAdapterTest < ActiveSupport::TestCase | |
23 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s | |
24 REPOSITORY_PATH.gsub!(/\/+/, '/') | |
25 | |
26 if File.directory?(REPOSITORY_PATH) | |
27 def setup | |
28 @adapter = Redmine::Scm::Adapters::BazaarAdapter.new( | |
29 File.join(REPOSITORY_PATH, "trunk") | |
30 ) | |
31 end | |
32 | |
33 def test_scm_version | |
34 to_test = { "Bazaar (bzr) 2.1.2\n" => [2,1,2], | |
35 "2.1.1\n1.7\n1.8" => [2,1,1], | |
36 "2.0.1\r\n1.8.1\r\n1.9.1" => [2,0,1]} | |
37 to_test.each do |s, v| | |
38 test_scm_version_for(s, v) | |
39 end | |
40 end | |
41 | |
42 def test_cat | |
43 cat = @adapter.cat('directory/document.txt') | |
44 assert cat =~ /Write the contents of a file as of a given revision to standard output/ | |
45 end | |
46 | |
47 def test_cat_path_invalid | |
48 assert_nil @adapter.cat('invalid') | |
49 end | |
50 | |
51 def test_cat_revision_invalid | |
52 assert_nil @adapter.cat('doc-mkdir.txt', '12345678') | |
53 end | |
54 | |
55 def test_diff | |
56 diff1 = @adapter.diff('doc-mkdir.txt', 3, 2) | |
57 assert_equal 21, diff1.size | |
58 buf = diff1[14].gsub(/\r\n|\r|\n/, "") | |
59 assert_equal "-Display more information.", buf | |
60 end | |
61 | |
62 def test_diff_path_invalid | |
63 assert_equal [], @adapter.diff('invalid', 1) | |
64 end | |
65 | |
66 def test_diff_revision_invalid | |
67 assert_equal [], @adapter.diff(nil, 12345678) | |
68 assert_equal [], @adapter.diff(nil, 12345678, 87654321) | |
69 end | |
70 | |
71 def test_annotate | |
72 annotate = @adapter.annotate('doc-mkdir.txt') | |
73 assert_equal 17, annotate.lines.size | |
74 assert_equal '1', annotate.revisions[0].identifier | |
75 assert_equal 'jsmith@', annotate.revisions[0].author | |
76 assert_equal 'mkdir', annotate.lines[0] | |
77 end | |
78 | |
79 def test_annotate_path_invalid | |
80 assert_nil @adapter.annotate('invalid') | |
81 end | |
82 | |
83 def test_annotate_revision_invalid | |
84 assert_nil @adapter.annotate('doc-mkdir.txt', '12345678') | |
85 end | |
86 | |
87 def test_branch_conf_path | |
88 p = "c:\\test\\test\\" | |
89 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p) | |
90 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp | |
91 p = "c:\\test\\test\\.bzr" | |
92 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p) | |
93 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp | |
94 p = "c:\\test\\test\\.bzr\\" | |
95 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p) | |
96 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp | |
97 p = "c:\\test\\test" | |
98 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p) | |
99 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp | |
100 p = "\\\\server\\test\\test\\" | |
101 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p) | |
102 assert_equal File.join("\\\\server\\test\\test", ".bzr", "branch", "branch.conf"), bcp | |
103 end | |
104 | |
105 def test_append_revisions_only_true | |
106 assert_equal true, @adapter.append_revisions_only | |
107 end | |
108 | |
109 def test_append_revisions_only_false | |
110 adpt = Redmine::Scm::Adapters::BazaarAdapter.new( | |
111 File.join(REPOSITORY_PATH, "empty-branch") | |
112 ) | |
113 assert_equal false, adpt.append_revisions_only | |
114 end | |
115 | |
116 def test_append_revisions_only_shared_repo | |
117 adpt = Redmine::Scm::Adapters::BazaarAdapter.new( | |
118 REPOSITORY_PATH | |
119 ) | |
120 assert_equal false, adpt.append_revisions_only | |
121 end | |
122 | |
123 def test_info_not_nil | |
124 assert_not_nil @adapter.info | |
125 end | |
126 | |
127 def test_info_nil | |
128 adpt = Redmine::Scm::Adapters::BazaarAdapter.new( | |
129 "/invalid/invalid/" | |
130 ) | |
131 assert_nil adpt.info | |
132 end | |
133 | |
134 def test_info | |
135 info = @adapter.info | |
136 assert_equal 4, info.lastrev.identifier.to_i | |
137 end | |
138 | |
139 def test_info_emtpy | |
140 adpt = Redmine::Scm::Adapters::BazaarAdapter.new( | |
141 File.join(REPOSITORY_PATH, "empty-branch") | |
142 ) | |
143 assert_equal 0, adpt.info.lastrev.identifier.to_i | |
144 end | |
145 | |
146 def test_entries_path_invalid | |
147 assert_equal [], @adapter.entries('invalid') | |
148 end | |
149 | |
150 def test_entries_revision_invalid | |
151 assert_nil @adapter.entries(nil, 12345678) | |
152 end | |
153 | |
154 def test_revisions | |
155 revisions = @adapter.revisions(nil, 4, 2) | |
156 assert_equal 3, revisions.size | |
157 assert_equal 2, revisions[2].identifier | |
158 assert_equal 'jsmith@foo.bar-20071203175224-v0eog5d5wrgdrshg', revisions[2].scmid | |
159 assert_equal 4, revisions[0].identifier | |
160 assert_equal 'jsmith@foo.bar-20071203175422-t40bf8li5zz0c4cg', revisions[0].scmid | |
161 assert_equal 2, revisions[0].paths.size | |
162 assert_equal 'D', revisions[0].paths[0][:action] | |
163 assert_equal '/doc-deleted.txt', revisions[0].paths[0][:path] | |
164 assert_equal 'docdeleted.txt-20071203175320-iwwj561ojuubs3gt-1', revisions[0].paths[0][:revision] | |
165 assert_equal 'M', revisions[0].paths[1][:action] | |
166 assert_equal '/directory/doc-ls.txt', revisions[0].paths[1][:path] | |
167 assert_equal 'docls.txt-20071203175005-a3hyc3mn0shl7cgu-1', revisions[0].paths[1][:revision] | |
168 end | |
169 | |
170 def test_revisions_path_invalid | |
171 assert_nil @adapter.revisions('invalid') | |
172 end | |
173 | |
174 def test_revisions_revision_invalid | |
175 assert_nil @adapter.revisions(nil, 12345678) | |
176 assert_nil @adapter.revisions(nil, 12345678, 87654321) | |
177 end | |
178 | |
179 def test_entry | |
180 entry = @adapter.entry() | |
181 assert_equal "", entry.path | |
182 assert_equal "dir", entry.kind | |
183 entry = @adapter.entry('') | |
184 assert_equal "", entry.path | |
185 assert_equal "dir", entry.kind | |
186 assert_nil @adapter.entry('invalid') | |
187 assert_nil @adapter.entry('/invalid') | |
188 assert_nil @adapter.entry('/invalid/') | |
189 assert_nil @adapter.entry('invalid/invalid') | |
190 assert_nil @adapter.entry('invalid/invalid/') | |
191 assert_nil @adapter.entry('/invalid/invalid') | |
192 assert_nil @adapter.entry('/invalid/invalid/') | |
193 ["doc-ls.txt", "/doc-ls.txt"].each do |path| | |
194 entry = @adapter.entry(path, 2) | |
195 assert_equal "doc-ls.txt", entry.path | |
196 assert_equal "file", entry.kind | |
197 end | |
198 ["directory", "/directory", "/directory/"].each do |path| | |
199 entry = @adapter.entry(path, 2) | |
200 assert_equal "directory", entry.path | |
201 assert_equal "dir", entry.kind | |
202 end | |
203 ["directory/document.txt", "/directory/document.txt"].each do |path| | |
204 entry = @adapter.entry(path, 2) | |
205 assert_equal "directory/document.txt", entry.path | |
206 assert_equal "file", entry.kind | |
207 end | |
208 end | |
209 | |
210 private | |
211 | |
212 def test_scm_version_for(scm_command_version, version) | |
213 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version) | |
214 assert_equal version, @adapter.class.scm_command_version | |
215 end | |
216 else | |
217 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!" | |
218 def test_fake; assert true end | |
219 end | |
220 end | |
221 rescue LoadError | |
222 class BazaarMochaFake < ActiveSupport::TestCase | |
223 def test_fake; assert(false, "Requires mocha to run those tests") end | |
224 end | |
225 end |