##// END OF EJS Templates
scm: mercurial: set instance value flag of whether "hg diff -c" supports true at tests (#7518)....
Toshi MARUYAMA -
r4735:05210f18ed31
parent child
Show More
@@ -1,224 +1,224
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'repositories_controller'
19 require 'repositories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
23
24 class RepositoriesMercurialControllerTest < ActionController::TestCase
24 class RepositoriesMercurialControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26
26
27 # No '..' in the repository path
27 # No '..' in the repository path
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
29
29
30 def setup
30 def setup
31 @controller = RepositoriesController.new
31 @controller = RepositoriesController.new
32 @request = ActionController::TestRequest.new
32 @request = ActionController::TestRequest.new
33 @response = ActionController::TestResponse.new
33 @response = ActionController::TestResponse.new
34 User.current = nil
34 User.current = nil
35 @repository = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
35 @repository = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
36 assert @repository
36 assert @repository
37 @diff_c_support = @repository.scm.class.client_version_above?([1, 2])
37 @diff_c_support = true
38 end
38 end
39
39
40 if File.directory?(REPOSITORY_PATH)
40 if File.directory?(REPOSITORY_PATH)
41 def test_show
41 def test_show
42 get :show, :id => 3
42 get :show, :id => 3
43 assert_response :success
43 assert_response :success
44 assert_template 'show'
44 assert_template 'show'
45 assert_not_nil assigns(:entries)
45 assert_not_nil assigns(:entries)
46 assert_not_nil assigns(:changesets)
46 assert_not_nil assigns(:changesets)
47 end
47 end
48
48
49 def test_show_root
49 def test_show_root
50 get :show, :id => 3
50 get :show, :id => 3
51 assert_response :success
51 assert_response :success
52 assert_template 'show'
52 assert_template 'show'
53 assert_not_nil assigns(:entries)
53 assert_not_nil assigns(:entries)
54 assert_equal 4, assigns(:entries).size
54 assert_equal 4, assigns(:entries).size
55 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
55 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
56 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
56 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
57 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
57 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
58 end
58 end
59
59
60 def test_show_directory
60 def test_show_directory
61 get :show, :id => 3, :path => ['images']
61 get :show, :id => 3, :path => ['images']
62 assert_response :success
62 assert_response :success
63 assert_template 'show'
63 assert_template 'show'
64 assert_not_nil assigns(:entries)
64 assert_not_nil assigns(:entries)
65 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
65 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
66 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
66 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
67 assert_not_nil entry
67 assert_not_nil entry
68 assert_equal 'file', entry.kind
68 assert_equal 'file', entry.kind
69 assert_equal 'images/edit.png', entry.path
69 assert_equal 'images/edit.png', entry.path
70 end
70 end
71
71
72 def test_show_at_given_revision
72 def test_show_at_given_revision
73 [0, '0', '0885933ad4f6'].each do |r1|
73 [0, '0', '0885933ad4f6'].each do |r1|
74 get :show, :id => 3, :path => ['images'], :rev => r1
74 get :show, :id => 3, :path => ['images'], :rev => r1
75 assert_response :success
75 assert_response :success
76 assert_template 'show'
76 assert_template 'show'
77 assert_not_nil assigns(:entries)
77 assert_not_nil assigns(:entries)
78 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
78 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
79 end
79 end
80 end
80 end
81
81
82 def test_show_directory_sql_escape_percent
82 def test_show_directory_sql_escape_percent
83 [13, '13', '3a330eb32958'].each do |r1|
83 [13, '13', '3a330eb32958'].each do |r1|
84 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
84 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
85 assert_response :success
85 assert_response :success
86 assert_template 'show'
86 assert_template 'show'
87
87
88 assert_not_nil assigns(:entries)
88 assert_not_nil assigns(:entries)
89 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
89 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
90 changesets = assigns(:changesets)
90 changesets = assigns(:changesets)
91
91
92 ## This is not yet implemented.
92 ## This is not yet implemented.
93 # assert_not_nil changesets
93 # assert_not_nil changesets
94 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
94 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
95 end
95 end
96 end
96 end
97
97
98 def test_changes
98 def test_changes
99 get :changes, :id => 3, :path => ['images', 'edit.png']
99 get :changes, :id => 3, :path => ['images', 'edit.png']
100 assert_response :success
100 assert_response :success
101 assert_template 'changes'
101 assert_template 'changes'
102 assert_tag :tag => 'h2', :content => 'edit.png'
102 assert_tag :tag => 'h2', :content => 'edit.png'
103 end
103 end
104
104
105 def test_entry_show
105 def test_entry_show
106 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
106 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
107 assert_response :success
107 assert_response :success
108 assert_template 'entry'
108 assert_template 'entry'
109 # Line 10
109 # Line 10
110 assert_tag :tag => 'th',
110 assert_tag :tag => 'th',
111 :content => '10',
111 :content => '10',
112 :attributes => { :class => 'line-num' },
112 :attributes => { :class => 'line-num' },
113 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
113 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
114 end
114 end
115
115
116 def test_entry_download
116 def test_entry_download
117 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
117 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
118 assert_response :success
118 assert_response :success
119 # File content
119 # File content
120 assert @response.body.include?('WITHOUT ANY WARRANTY')
120 assert @response.body.include?('WITHOUT ANY WARRANTY')
121 end
121 end
122
122
123 def test_directory_entry
123 def test_directory_entry
124 get :entry, :id => 3, :path => ['sources']
124 get :entry, :id => 3, :path => ['sources']
125 assert_response :success
125 assert_response :success
126 assert_template 'show'
126 assert_template 'show'
127 assert_not_nil assigns(:entry)
127 assert_not_nil assigns(:entry)
128 assert_equal 'sources', assigns(:entry).name
128 assert_equal 'sources', assigns(:entry).name
129 end
129 end
130
130
131 def test_diff
131 def test_diff
132 @repository.fetch_changesets
132 @repository.fetch_changesets
133 @repository.reload
133 @repository.reload
134
134
135 [4, '4', 'def6d2f1254a'].each do |r1|
135 [4, '4', 'def6d2f1254a'].each do |r1|
136 # Full diff of changeset 4
136 # Full diff of changeset 4
137 get :diff, :id => 3, :rev => r1
137 get :diff, :id => 3, :rev => r1
138 assert_response :success
138 assert_response :success
139 assert_template 'diff'
139 assert_template 'diff'
140
140
141 if @diff_c_support
141 if @diff_c_support
142 # Line 22 removed
142 # Line 22 removed
143 assert_tag :tag => 'th',
143 assert_tag :tag => 'th',
144 :content => '22',
144 :content => '22',
145 :sibling => { :tag => 'td',
145 :sibling => { :tag => 'td',
146 :attributes => { :class => /diff_out/ },
146 :attributes => { :class => /diff_out/ },
147 :content => /def remove/ }
147 :content => /def remove/ }
148 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
148 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
149 end
149 end
150 end
150 end
151 end
151 end
152
152
153 def test_diff_two_revs
153 def test_diff_two_revs
154 @repository.fetch_changesets
154 @repository.fetch_changesets
155 @repository.reload
155 @repository.reload
156
156
157 [2, '400bb8672109', '400', 400].each do |r1|
157 [2, '400bb8672109', '400', 400].each do |r1|
158 [4, 'def6d2f1254a'].each do |r2|
158 [4, 'def6d2f1254a'].each do |r2|
159 get :diff, :id => 3, :rev => r1,
159 get :diff, :id => 3, :rev => r1,
160 :rev_to => r2
160 :rev_to => r2
161 assert_response :success
161 assert_response :success
162 assert_template 'diff'
162 assert_template 'diff'
163
163
164 diff = assigns(:diff)
164 diff = assigns(:diff)
165 assert_not_nil diff
165 assert_not_nil diff
166 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
166 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
167 end
167 end
168 end
168 end
169 end
169 end
170
170
171 def test_annotate
171 def test_annotate
172 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
172 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
173 assert_response :success
173 assert_response :success
174 assert_template 'annotate'
174 assert_template 'annotate'
175 # Line 23, revision 4:def6d2f1254a
175 # Line 23, revision 4:def6d2f1254a
176 assert_tag :tag => 'th',
176 assert_tag :tag => 'th',
177 :content => '23',
177 :content => '23',
178 :attributes => { :class => 'line-num' },
178 :attributes => { :class => 'line-num' },
179 :sibling =>
179 :sibling =>
180 {
180 {
181 :tag => 'td',
181 :tag => 'td',
182 :attributes => { :class => 'revision' },
182 :attributes => { :class => 'revision' },
183 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
183 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
184 }
184 }
185 assert_tag :tag => 'th',
185 assert_tag :tag => 'th',
186 :content => '23',
186 :content => '23',
187 :attributes => { :class => 'line-num' },
187 :attributes => { :class => 'line-num' },
188 :sibling =>
188 :sibling =>
189 {
189 {
190 :tag => 'td' ,
190 :tag => 'td' ,
191 :content => 'jsmith' ,
191 :content => 'jsmith' ,
192 :attributes => { :class => 'author' },
192 :attributes => { :class => 'author' },
193 }
193 }
194 assert_tag :tag => 'th',
194 assert_tag :tag => 'th',
195 :content => '23',
195 :content => '23',
196 :attributes => { :class => 'line-num' },
196 :attributes => { :class => 'line-num' },
197 :sibling => { :tag => 'td', :content => /watcher =/ }
197 :sibling => { :tag => 'td', :content => /watcher =/ }
198 end
198 end
199
199
200 def test_annotate_at_given_revision
200 def test_annotate_at_given_revision
201 @repository.fetch_changesets
201 @repository.fetch_changesets
202 @repository.reload
202 @repository.reload
203 [2, '400bb8672109', '400', 400].each do |r1|
203 [2, '400bb8672109', '400', 400].each do |r1|
204 get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb']
204 get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb']
205 assert_response :success
205 assert_response :success
206 assert_template 'annotate'
206 assert_template 'annotate'
207 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
207 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
208 end
208 end
209 end
209 end
210
210
211 def test_empty_revision
211 def test_empty_revision
212 @repository.fetch_changesets
212 @repository.fetch_changesets
213 @repository.reload
213 @repository.reload
214 ['', ' ', nil].each do |r|
214 ['', ' ', nil].each do |r|
215 get :revision, :id => 3, :rev => r
215 get :revision, :id => 3, :rev => r
216 assert_response 404
216 assert_response 404
217 assert_error_tag :content => /was not found/
217 assert_error_tag :content => /was not found/
218 end
218 end
219 end
219 end
220 else
220 else
221 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
221 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
222 def test_fake; assert true end
222 def test_fake; assert true end
223 end
223 end
224 end
224 end
@@ -1,192 +1,192
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\/\.\.}, '') + '/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 = @adapter.class.client_version_above?([1, 2])
16 @diff_c_support = true
17 end
17 end
18
18
19 def test_hgversion
19 def test_hgversion
20 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],
21 "Mercurial Distributed SCM (1.0)\n" => [1,0],
21 "Mercurial Distributed SCM (1.0)\n" => [1,0],
22 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
22 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
23 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
23 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
24 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
24 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
25 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
25 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
26 "(1.6)\n(1.7)\n(1.8)" => [1,6],
26 "(1.6)\n(1.7)\n(1.8)" => [1,6],
27 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
27 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
28
28
29 to_test.each do |s, v|
29 to_test.each do |s, v|
30 test_hgversion_for(s, v)
30 test_hgversion_for(s, v)
31 end
31 end
32 end
32 end
33
33
34 def test_template_path
34 def test_template_path
35 to_test = { [0,9,5] => "0.9.5",
35 to_test = { [0,9,5] => "0.9.5",
36 [1,0] => "1.0",
36 [1,0] => "1.0",
37 [] => "1.0",
37 [] => "1.0",
38 [1,0,1] => "1.0",
38 [1,0,1] => "1.0",
39 [1,7] => "1.0",
39 [1,7] => "1.0",
40 [1,7,1] => "1.0" }
40 [1,7,1] => "1.0" }
41 to_test.each do |v, template|
41 to_test.each do |v, template|
42 test_template_path_for(v, template)
42 test_template_path_for(v, template)
43 end
43 end
44 end
44 end
45
45
46 def test_info
46 def test_info
47 [REPOSITORY_PATH, REPOSITORY_PATH + "/",
47 [REPOSITORY_PATH, REPOSITORY_PATH + "/",
48 REPOSITORY_PATH + "//"].each do |repo|
48 REPOSITORY_PATH + "//"].each do |repo|
49 adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
49 adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
50 assert_equal REPOSITORY_PATH, adp.info.root_url
50 assert_equal REPOSITORY_PATH, adp.info.root_url
51 assert_equal '16', adp.info.lastrev.revision
51 assert_equal '16', adp.info.lastrev.revision
52 assert_equal '4cddb4e45f52',adp.info.lastrev.scmid
52 assert_equal '4cddb4e45f52',adp.info.lastrev.scmid
53 end
53 end
54 end
54 end
55
55
56 def test_revisions
56 def test_revisions
57 revisions = @adapter.revisions(nil, 2, 4)
57 revisions = @adapter.revisions(nil, 2, 4)
58 assert_equal 3, revisions.size
58 assert_equal 3, revisions.size
59 assert_equal '2', revisions[0].revision
59 assert_equal '2', revisions[0].revision
60 assert_equal '400bb8672109', revisions[0].scmid
60 assert_equal '400bb8672109', revisions[0].scmid
61 assert_equal '4', revisions[2].revision
61 assert_equal '4', revisions[2].revision
62 assert_equal 'def6d2f1254a', revisions[2].scmid
62 assert_equal 'def6d2f1254a', revisions[2].scmid
63
63
64 revisions = @adapter.revisions(nil, 2, 4, {:limit => 2})
64 revisions = @adapter.revisions(nil, 2, 4, {:limit => 2})
65 assert_equal 2, revisions.size
65 assert_equal 2, revisions.size
66 assert_equal '2', revisions[0].revision
66 assert_equal '2', revisions[0].revision
67 assert_equal '400bb8672109', revisions[0].scmid
67 assert_equal '400bb8672109', revisions[0].scmid
68 end
68 end
69
69
70 def test_diff
70 def test_diff
71 if @adapter.class.client_version_above?([1, 2])
71 if @adapter.class.client_version_above?([1, 2])
72 assert_nil @adapter.diff(nil, '100000')
72 assert_nil @adapter.diff(nil, '100000')
73 end
73 end
74 assert_nil @adapter.diff(nil, '100000', '200000')
74 assert_nil @adapter.diff(nil, '100000', '200000')
75 [2, '400bb8672109', '400', 400].each do |r1|
75 [2, '400bb8672109', '400', 400].each do |r1|
76 diff1 = @adapter.diff(nil, r1)
76 diff1 = @adapter.diff(nil, r1)
77 if @diff_c_support
77 if @diff_c_support
78 assert_equal 28, diff1.size
78 assert_equal 28, diff1.size
79 buf = diff1[24].gsub(/\r\n|\r|\n/, "")
79 buf = diff1[24].gsub(/\r\n|\r|\n/, "")
80 assert_equal "+ return true unless klass.respond_to?('watched_by')", buf
80 assert_equal "+ return true unless klass.respond_to?('watched_by')", buf
81 else
81 else
82 assert_equal 0, diff1.size
82 assert_equal 0, diff1.size
83 end
83 end
84 [4, 'def6d2f1254a'].each do |r2|
84 [4, 'def6d2f1254a'].each do |r2|
85 diff2 = @adapter.diff(nil,r1,r2)
85 diff2 = @adapter.diff(nil,r1,r2)
86 assert_equal 49, diff2.size
86 assert_equal 49, diff2.size
87 buf = diff2[41].gsub(/\r\n|\r|\n/, "")
87 buf = diff2[41].gsub(/\r\n|\r|\n/, "")
88 assert_equal "+class WelcomeController < ApplicationController", buf
88 assert_equal "+class WelcomeController < ApplicationController", buf
89 diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
89 diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
90 assert_equal 20, diff3.size
90 assert_equal 20, diff3.size
91 buf = diff3[12].gsub(/\r\n|\r|\n/, "")
91 buf = diff3[12].gsub(/\r\n|\r|\n/, "")
92 assert_equal "+ @watched.remove_watcher(user)", buf
92 assert_equal "+ @watched.remove_watcher(user)", buf
93 end
93 end
94 end
94 end
95 end
95 end
96
96
97 def test_diff_made_by_revision
97 def test_diff_made_by_revision
98 if @diff_c_support
98 if @diff_c_support
99 [16, '16', '4cddb4e45f52'].each do |r1|
99 [16, '16', '4cddb4e45f52'].each do |r1|
100 diff1 = @adapter.diff(nil, r1)
100 diff1 = @adapter.diff(nil, r1)
101 assert_equal 5, diff1.size
101 assert_equal 5, diff1.size
102 buf = diff1[4].gsub(/\r\n|\r|\n/, "")
102 buf = diff1[4].gsub(/\r\n|\r|\n/, "")
103 assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf
103 assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf
104 end
104 end
105 end
105 end
106 end
106 end
107
107
108 def test_cat
108 def test_cat
109 [2, '400bb8672109', '400', 400].each do |r|
109 [2, '400bb8672109', '400', 400].each do |r|
110 buf = @adapter.cat('sources/welcome_controller.rb', r)
110 buf = @adapter.cat('sources/welcome_controller.rb', r)
111 assert buf
111 assert buf
112 lines = buf.split("\r\n")
112 lines = buf.split("\r\n")
113 assert_equal 25, lines.length
113 assert_equal 25, lines.length
114 assert_equal 'class WelcomeController < ApplicationController', lines[17]
114 assert_equal 'class WelcomeController < ApplicationController', lines[17]
115 end
115 end
116 assert_nil @adapter.cat('sources/welcome_controller.rb')
116 assert_nil @adapter.cat('sources/welcome_controller.rb')
117 end
117 end
118
118
119 def test_annotate
119 def test_annotate
120 assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
120 assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
121 [2, '400bb8672109', '400', 400].each do |r|
121 [2, '400bb8672109', '400', 400].each do |r|
122 ann = @adapter.annotate('sources/welcome_controller.rb', r)
122 ann = @adapter.annotate('sources/welcome_controller.rb', r)
123 assert ann
123 assert ann
124 assert_equal '1', ann.revisions[17].revision
124 assert_equal '1', ann.revisions[17].revision
125 assert_equal '9d5b5b004199', ann.revisions[17].identifier
125 assert_equal '9d5b5b004199', ann.revisions[17].identifier
126 assert_equal 'jsmith', ann.revisions[0].author
126 assert_equal 'jsmith', ann.revisions[0].author
127 assert_equal 25, ann.lines.length
127 assert_equal 25, ann.lines.length
128 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
128 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
129 end
129 end
130 end
130 end
131
131
132 # TODO filesize etc.
132 # TODO filesize etc.
133 def test_entries
133 def test_entries
134 assert_nil @adapter.entries(nil, '100000')
134 assert_nil @adapter.entries(nil, '100000')
135 [2, '400bb8672109', '400', 400].each do |r|
135 [2, '400bb8672109', '400', 400].each do |r|
136 entries1 = @adapter.entries(nil, r)
136 entries1 = @adapter.entries(nil, r)
137 assert entries1
137 assert entries1
138 assert_equal 3, entries1.size
138 assert_equal 3, entries1.size
139 assert_equal 'sources', entries1[1].name
139 assert_equal 'sources', entries1[1].name
140 assert_equal 'sources', entries1[1].path
140 assert_equal 'sources', entries1[1].path
141 assert_equal 'dir', entries1[1].kind
141 assert_equal 'dir', entries1[1].kind
142 assert_equal 'README', entries1[2].name
142 assert_equal 'README', entries1[2].name
143 assert_equal 'README', entries1[2].path
143 assert_equal 'README', entries1[2].path
144 assert_equal 'file', entries1[2].kind
144 assert_equal 'file', entries1[2].kind
145
145
146 entries2 = @adapter.entries('sources', r)
146 entries2 = @adapter.entries('sources', r)
147 assert entries2
147 assert entries2
148 assert_equal 2, entries2.size
148 assert_equal 2, entries2.size
149 assert_equal 'watchers_controller.rb', entries2[0].name
149 assert_equal 'watchers_controller.rb', entries2[0].name
150 assert_equal 'sources/watchers_controller.rb', entries2[0].path
150 assert_equal 'sources/watchers_controller.rb', entries2[0].path
151 assert_equal 'file', entries2[0].kind
151 assert_equal 'file', entries2[0].kind
152 assert_equal 'welcome_controller.rb', entries2[1].name
152 assert_equal 'welcome_controller.rb', entries2[1].name
153 assert_equal 'sources/welcome_controller.rb', entries2[1].path
153 assert_equal 'sources/welcome_controller.rb', entries2[1].path
154 assert_equal 'file', entries2[1].kind
154 assert_equal 'file', entries2[1].kind
155 end
155 end
156 end
156 end
157
157
158 def test_access_by_nodeid
158 def test_access_by_nodeid
159 path = 'sources/welcome_controller.rb'
159 path = 'sources/welcome_controller.rb'
160 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
160 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
161 end
161 end
162
162
163 def test_access_by_fuzzy_nodeid
163 def test_access_by_fuzzy_nodeid
164 path = 'sources/welcome_controller.rb'
164 path = 'sources/welcome_controller.rb'
165 # falls back to nodeid
165 # falls back to nodeid
166 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
166 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
167 end
167 end
168
168
169 private
169 private
170
170
171 def test_hgversion_for(hgversion, version)
171 def test_hgversion_for(hgversion, version)
172 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
172 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
173 assert_equal version, @adapter.class.hgversion
173 assert_equal version, @adapter.class.hgversion
174 end
174 end
175
175
176 def test_template_path_for(version, template)
176 def test_template_path_for(version, template)
177 assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
177 assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
178 @adapter.class.template_path_for(version)
178 @adapter.class.template_path_for(version)
179 assert File.exist?(@adapter.class.template_path_for(version))
179 assert File.exist?(@adapter.class.template_path_for(version))
180 end
180 end
181 else
181 else
182 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
182 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
183 def test_fake; assert true end
183 def test_fake; assert true end
184 end
184 end
185 end
185 end
186
186
187 rescue LoadError
187 rescue LoadError
188 class MercurialMochaFake < ActiveSupport::TestCase
188 class MercurialMochaFake < ActiveSupport::TestCase
189 def test_fake; assert(false, "Requires mocha to run those tests") end
189 def test_fake; assert(false, "Requires mocha to run those tests") end
190 end
190 end
191 end
191 end
192
192
General Comments 0
You need to be logged in to leave comments. Login now