##// END OF EJS Templates
scm: git: use report_last_commit option in unit adapter test (#7047)....
Toshi MARUYAMA -
r5534:931fd58de6e2
parent child
Show More
@@ -1,244 +1,246
1 # encoding: utf-8
1 # encoding: utf-8
2
2
3 # This file includes UTF-8 "Felix Schäfer".
3 # This file includes UTF-8 "Felix Schäfer".
4 # We need to consider Ruby 1.9 compatibility.
4 # We need to consider Ruby 1.9 compatibility.
5
5
6 require File.expand_path('../../../../../../test_helper', __FILE__)
6 require File.expand_path('../../../../../../test_helper', __FILE__)
7 begin
7 begin
8 require 'mocha'
8 require 'mocha'
9
9
10 class GitAdapterTest < ActiveSupport::TestCase
10 class GitAdapterTest < ActiveSupport::TestCase
11 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
11 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
12
12
13 FELIX_UTF8 = "Felix Schäfer"
13 FELIX_UTF8 = "Felix Schäfer"
14 FELIX_HEX = "Felix Sch\xC3\xA4fer"
14 FELIX_HEX = "Felix Sch\xC3\xA4fer"
15 CHAR_1_HEX = "\xc3\x9c"
15 CHAR_1_HEX = "\xc3\x9c"
16
16
17 ## Ruby uses ANSI api to fork a process on Windows.
17 ## Ruby uses ANSI api to fork a process on Windows.
18 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
18 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
19 ## and these are incompatible with ASCII.
19 ## and these are incompatible with ASCII.
20 # WINDOWS_PASS = Redmine::Platform.mswin?
20 # WINDOWS_PASS = Redmine::Platform.mswin?
21 WINDOWS_PASS = false
21 WINDOWS_PASS = false
22
22
23 if File.directory?(REPOSITORY_PATH)
23 if File.directory?(REPOSITORY_PATH)
24 def setup
24 def setup
25 adapter_class = Redmine::Scm::Adapters::GitAdapter
25 adapter_class = Redmine::Scm::Adapters::GitAdapter
26 assert adapter_class
26 assert adapter_class
27 assert adapter_class.client_command
27 assert adapter_class.client_command
28 assert_equal true, adapter_class.client_available
28 assert_equal true, adapter_class.client_available
29 assert_equal true, adapter_class.client_version_above?([1])
29 assert_equal true, adapter_class.client_version_above?([1])
30 assert_equal true, adapter_class.client_version_above?([1, 0])
30 assert_equal true, adapter_class.client_version_above?([1, 0])
31
31
32 @adapter = Redmine::Scm::Adapters::GitAdapter.new(
32 @adapter = Redmine::Scm::Adapters::GitAdapter.new(
33 REPOSITORY_PATH,
33 REPOSITORY_PATH,
34 nil,
34 nil,
35 nil,
35 nil,
36 nil,
36 nil,
37 'ISO-8859-1'
37 'ISO-8859-1'
38 )
38 )
39 assert @adapter
39 assert @adapter
40 @char_1 = CHAR_1_HEX.dup
40 @char_1 = CHAR_1_HEX.dup
41 if @char_1.respond_to?(:force_encoding)
41 if @char_1.respond_to?(:force_encoding)
42 @char_1.force_encoding('UTF-8')
42 @char_1.force_encoding('UTF-8')
43 end
43 end
44 end
44 end
45
45
46 def test_scm_version
46 def test_scm_version
47 to_test = { "git version 1.7.3.4\n" => [1,7,3,4],
47 to_test = { "git version 1.7.3.4\n" => [1,7,3,4],
48 "1.6.1\n1.7\n1.8" => [1,6,1],
48 "1.6.1\n1.7\n1.8" => [1,6,1],
49 "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
49 "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
50 to_test.each do |s, v|
50 to_test.each do |s, v|
51 test_scm_version_for(s, v)
51 test_scm_version_for(s, v)
52 end
52 end
53 end
53 end
54
54
55 def test_branches
55 def test_branches
56 assert_equal [
56 assert_equal [
57 'latin-1-path-encoding',
57 'latin-1-path-encoding',
58 'master',
58 'master',
59 'test-latin-1',
59 'test-latin-1',
60 'test_branch',
60 'test_branch',
61 ], @adapter.branches
61 ], @adapter.branches
62 end
62 end
63
63
64 def test_tags
64 def test_tags
65 assert_equal [
65 assert_equal [
66 "tag00.lightweight",
66 "tag00.lightweight",
67 "tag01.annotated",
67 "tag01.annotated",
68 ], @adapter.tags
68 ], @adapter.tags
69 end
69 end
70
70
71 def test_getting_all_revisions
71 def test_getting_all_revisions
72 assert_equal 21, @adapter.revisions('',nil,nil,:all => true).length
72 assert_equal 21, @adapter.revisions('',nil,nil,:all => true).length
73 end
73 end
74
74
75 def test_getting_certain_revisions
75 def test_getting_certain_revisions
76 assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length
76 assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length
77 end
77 end
78
78
79 def test_revisions_reverse
79 def test_revisions_reverse
80 revs1 = @adapter.revisions('',nil,nil,{:all => true, :reverse => true })
80 revs1 = @adapter.revisions('',nil,nil,{:all => true, :reverse => true })
81 assert_equal 21, revs1.length
81 assert_equal 21, revs1.length
82 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[0].identifier
82 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[0].identifier
83 assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[20].identifier
83 assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[20].identifier
84
84
85 since2 = Time.gm(2010, 9, 30, 0, 0, 0)
85 since2 = Time.gm(2010, 9, 30, 0, 0, 0)
86 revs2 = @adapter.revisions('',nil,nil,{:all => true, :since => since2, :reverse => true })
86 revs2 = @adapter.revisions('',nil,nil,{:all => true, :since => since2, :reverse => true })
87 assert_equal 6, revs2.length
87 assert_equal 6, revs2.length
88 assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', revs2[0].identifier
88 assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', revs2[0].identifier
89 assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[5].identifier
89 assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[5].identifier
90 end
90 end
91
91
92 def test_getting_revisions_with_spaces_in_filename
92 def test_getting_revisions_with_spaces_in_filename
93 assert_equal 1, @adapter.revisions("filemane with spaces.txt",
93 assert_equal 1, @adapter.revisions("filemane with spaces.txt",
94 nil, nil, :all => true).length
94 nil, nil, :all => true).length
95 end
95 end
96
96
97 def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
97 def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
98 assert_equal " filename with a leading space.txt ",
98 assert_equal " filename with a leading space.txt ",
99 @adapter.revisions(" filename with a leading space.txt ",
99 @adapter.revisions(" filename with a leading space.txt ",
100 nil, nil, :all => true)[0].paths[0][:path]
100 nil, nil, :all => true)[0].paths[0][:path]
101 end
101 end
102
102
103 def test_getting_entries_with_leading_and_trailing_spaces_in_filename
103 def test_getting_entries_with_leading_and_trailing_spaces_in_filename
104 assert_equal " filename with a leading space.txt ",
104 assert_equal " filename with a leading space.txt ",
105 @adapter.entries('',
105 @adapter.entries('',
106 '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
106 '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
107 end
107 end
108
108
109 def test_annotate
109 def test_annotate
110 annotate = @adapter.annotate('sources/watchers_controller.rb')
110 annotate = @adapter.annotate('sources/watchers_controller.rb')
111 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
111 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
112 assert_equal 41, annotate.lines.size
112 assert_equal 41, annotate.lines.size
113 assert_equal "# This program is free software; you can redistribute it and/or",
113 assert_equal "# This program is free software; you can redistribute it and/or",
114 annotate.lines[4].strip
114 annotate.lines[4].strip
115 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
115 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
116 annotate.revisions[4].identifier
116 annotate.revisions[4].identifier
117 assert_equal "jsmith", annotate.revisions[4].author
117 assert_equal "jsmith", annotate.revisions[4].author
118 end
118 end
119
119
120 def test_annotate_moved_file
120 def test_annotate_moved_file
121 annotate = @adapter.annotate('renamed_test.txt')
121 annotate = @adapter.annotate('renamed_test.txt')
122 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
122 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
123 assert_equal 2, annotate.lines.size
123 assert_equal 2, annotate.lines.size
124 end
124 end
125
125
126 def test_last_rev
126 def test_last_rev
127 last_rev = @adapter.lastrev("README",
127 last_rev = @adapter.lastrev("README",
128 "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
128 "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
129 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
129 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
130 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
130 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
131 assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
131 assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
132 assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
132 assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
133 end
133 end
134
134
135 def test_last_rev_with_spaces_in_filename
135 def test_last_rev_with_spaces_in_filename
136 last_rev = @adapter.lastrev("filemane with spaces.txt",
136 last_rev = @adapter.lastrev("filemane with spaces.txt",
137 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
137 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
138 str_felix_utf8 = FELIX_UTF8.dup
138 str_felix_utf8 = FELIX_UTF8.dup
139 str_felix_hex = FELIX_HEX.dup
139 str_felix_hex = FELIX_HEX.dup
140 last_rev_author = last_rev.author
140 last_rev_author = last_rev.author
141 if last_rev_author.respond_to?(:force_encoding)
141 if last_rev_author.respond_to?(:force_encoding)
142 last_rev_author.force_encoding('UTF-8')
142 last_rev_author.force_encoding('UTF-8')
143 end
143 end
144 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
144 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
145 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
145 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
146 assert_equal "#{str_felix_utf8} <felix@fachschaften.org>",
146 assert_equal "#{str_felix_utf8} <felix@fachschaften.org>",
147 last_rev.author
147 last_rev.author
148 assert_equal "#{str_felix_hex} <felix@fachschaften.org>",
148 assert_equal "#{str_felix_hex} <felix@fachschaften.org>",
149 last_rev.author
149 last_rev.author
150 assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
150 assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
151 end
151 end
152
152
153 def test_latin_1_path
153 def test_latin_1_path
154 if WINDOWS_PASS
154 if WINDOWS_PASS
155 #
155 #
156 else
156 else
157 p2 = "latin-1-dir/test-#{@char_1}-2.txt"
157 p2 = "latin-1-dir/test-#{@char_1}-2.txt"
158 ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1|
158 ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1|
159 assert @adapter.diff(p2, r1)
159 assert @adapter.diff(p2, r1)
160 assert @adapter.cat(p2, r1)
160 assert @adapter.cat(p2, r1)
161 assert_equal 1, @adapter.annotate(p2, r1).lines.length
161 assert_equal 1, @adapter.annotate(p2, r1).lines.length
162 ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2|
162 ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2|
163 assert @adapter.diff(p2, r1, r2)
163 assert @adapter.diff(p2, r1, r2)
164 end
164 end
165 end
165 end
166 end
166 end
167 end
167 end
168
168
169 def test_entries_tag
169 def test_entries_tag
170 entries1 = @adapter.entries(nil, 'tag01.annotated')
170 entries1 = @adapter.entries(nil, 'tag01.annotated',
171 options = {:report_last_commit => true})
171 assert entries1
172 assert entries1
172 assert_equal 3, entries1.size
173 assert_equal 3, entries1.size
173 assert_equal 'sources', entries1[1].name
174 assert_equal 'sources', entries1[1].name
174 assert_equal 'sources', entries1[1].path
175 assert_equal 'sources', entries1[1].path
175 assert_equal 'dir', entries1[1].kind
176 assert_equal 'dir', entries1[1].kind
176 readme = entries1[2]
177 readme = entries1[2]
177 assert_equal 'README', readme.name
178 assert_equal 'README', readme.name
178 assert_equal 'README', readme.path
179 assert_equal 'README', readme.path
179 assert_equal 'file', readme.kind
180 assert_equal 'file', readme.kind
180 assert_equal 27, readme.size
181 assert_equal 27, readme.size
181 assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier
182 assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier
182 assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
183 assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
183 end
184 end
184
185
185 def test_entries_branch
186 def test_entries_branch
186 entries1 = @adapter.entries(nil, 'test_branch')
187 entries1 = @adapter.entries(nil, 'test_branch',
188 options = {:report_last_commit => true})
187 assert entries1
189 assert entries1
188 assert_equal 4, entries1.size
190 assert_equal 4, entries1.size
189 assert_equal 'sources', entries1[1].name
191 assert_equal 'sources', entries1[1].name
190 assert_equal 'sources', entries1[1].path
192 assert_equal 'sources', entries1[1].path
191 assert_equal 'dir', entries1[1].kind
193 assert_equal 'dir', entries1[1].kind
192 readme = entries1[2]
194 readme = entries1[2]
193 assert_equal 'README', readme.name
195 assert_equal 'README', readme.name
194 assert_equal 'README', readme.path
196 assert_equal 'README', readme.path
195 assert_equal 'file', readme.kind
197 assert_equal 'file', readme.kind
196 assert_equal 159, readme.size
198 assert_equal 159, readme.size
197 assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier
199 assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier
198 assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time
200 assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time
199 end
201 end
200
202
201 def test_entries_latin_1_files
203 def test_entries_latin_1_files
202 entries1 = @adapter.entries('latin-1-dir', '64f1f3e8')
204 entries1 = @adapter.entries('latin-1-dir', '64f1f3e8')
203 assert entries1
205 assert entries1
204 assert_equal 3, entries1.size
206 assert_equal 3, entries1.size
205 f1 = entries1[1]
207 f1 = entries1[1]
206 assert_equal "test-#{@char_1}-2.txt", f1.name
208 assert_equal "test-#{@char_1}-2.txt", f1.name
207 assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path
209 assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path
208 assert_equal 'file', f1.kind
210 assert_equal 'file', f1.kind
209 end
211 end
210
212
211 def test_entries_latin_1_dir
213 def test_entries_latin_1_dir
212 if WINDOWS_PASS
214 if WINDOWS_PASS
213 #
215 #
214 else
216 else
215 entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir",
217 entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir",
216 '1ca7f5ed')
218 '1ca7f5ed')
217 assert entries1
219 assert entries1
218 assert_equal 3, entries1.size
220 assert_equal 3, entries1.size
219 f1 = entries1[1]
221 f1 = entries1[1]
220 assert_equal "test-#{@char_1}-2.txt", f1.name
222 assert_equal "test-#{@char_1}-2.txt", f1.name
221 assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path
223 assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path
222 assert_equal 'file', f1.kind
224 assert_equal 'file', f1.kind
223 end
225 end
224 end
226 end
225
227
226 private
228 private
227
229
228 def test_scm_version_for(scm_command_version, version)
230 def test_scm_version_for(scm_command_version, version)
229 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
231 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
230 assert_equal version, @adapter.class.scm_command_version
232 assert_equal version, @adapter.class.scm_command_version
231 end
233 end
232
234
233 else
235 else
234 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
236 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
235 def test_fake; assert true end
237 def test_fake; assert true end
236 end
238 end
237 end
239 end
238
240
239 rescue LoadError
241 rescue LoadError
240 class GitMochaFake < ActiveSupport::TestCase
242 class GitMochaFake < ActiveSupport::TestCase
241 def test_fake; assert(false, "Requires mocha to run those tests") end
243 def test_fake; assert(false, "Requires mocha to run those tests") end
242 end
244 end
243 end
245 end
244
246
General Comments 0
You need to be logged in to leave comments. Login now