##// END OF EJS Templates
scm: git: split unit adapter revisions test to with time or not (#7146, #6013)....
Toshi MARUYAMA -
r5540:1ea1606007b7
parent child
Show More
@@ -1,245 +1,247
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 end
84
85
86 def test_revisions_reverse_with_time
85 since2 = Time.gm(2010, 9, 30, 0, 0, 0)
87 since2 = Time.gm(2010, 9, 30, 0, 0, 0)
86 revs2 = @adapter.revisions('',nil,nil,{:all => true, :since => since2, :reverse => true })
88 revs2 = @adapter.revisions('',nil,nil,{:all => true, :since => since2, :reverse => true })
87 assert_equal 6, revs2.length
89 assert_equal 6, revs2.length
88 assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', revs2[0].identifier
90 assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', revs2[0].identifier
89 assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[5].identifier
91 assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[5].identifier
90 end
92 end
91
93
92 def test_getting_revisions_with_spaces_in_filename
94 def test_getting_revisions_with_spaces_in_filename
93 assert_equal 1, @adapter.revisions("filemane with spaces.txt",
95 assert_equal 1, @adapter.revisions("filemane with spaces.txt",
94 nil, nil, :all => true).length
96 nil, nil, :all => true).length
95 end
97 end
96
98
97 def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
99 def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
98 assert_equal " filename with a leading space.txt ",
100 assert_equal " filename with a leading space.txt ",
99 @adapter.revisions(" filename with a leading space.txt ",
101 @adapter.revisions(" filename with a leading space.txt ",
100 nil, nil, :all => true)[0].paths[0][:path]
102 nil, nil, :all => true)[0].paths[0][:path]
101 end
103 end
102
104
103 def test_getting_entries_with_leading_and_trailing_spaces_in_filename
105 def test_getting_entries_with_leading_and_trailing_spaces_in_filename
104 assert_equal " filename with a leading space.txt ",
106 assert_equal " filename with a leading space.txt ",
105 @adapter.entries('',
107 @adapter.entries('',
106 '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
108 '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
107 end
109 end
108
110
109 def test_annotate
111 def test_annotate
110 annotate = @adapter.annotate('sources/watchers_controller.rb')
112 annotate = @adapter.annotate('sources/watchers_controller.rb')
111 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
113 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
112 assert_equal 41, annotate.lines.size
114 assert_equal 41, annotate.lines.size
113 assert_equal "# This program is free software; you can redistribute it and/or",
115 assert_equal "# This program is free software; you can redistribute it and/or",
114 annotate.lines[4].strip
116 annotate.lines[4].strip
115 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
117 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
116 annotate.revisions[4].identifier
118 annotate.revisions[4].identifier
117 assert_equal "jsmith", annotate.revisions[4].author
119 assert_equal "jsmith", annotate.revisions[4].author
118 end
120 end
119
121
120 def test_annotate_moved_file
122 def test_annotate_moved_file
121 annotate = @adapter.annotate('renamed_test.txt')
123 annotate = @adapter.annotate('renamed_test.txt')
122 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
124 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
123 assert_equal 2, annotate.lines.size
125 assert_equal 2, annotate.lines.size
124 end
126 end
125
127
126 def test_last_rev
128 def test_last_rev
127 last_rev = @adapter.lastrev("README",
129 last_rev = @adapter.lastrev("README",
128 "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
130 "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
129 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
131 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
130 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
132 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
131 assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
133 assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
132 assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
134 assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
133 end
135 end
134
136
135 def test_last_rev_with_spaces_in_filename
137 def test_last_rev_with_spaces_in_filename
136 last_rev = @adapter.lastrev("filemane with spaces.txt",
138 last_rev = @adapter.lastrev("filemane with spaces.txt",
137 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
139 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
138 str_felix_utf8 = FELIX_UTF8.dup
140 str_felix_utf8 = FELIX_UTF8.dup
139 str_felix_hex = FELIX_HEX.dup
141 str_felix_hex = FELIX_HEX.dup
140 last_rev_author = last_rev.author
142 last_rev_author = last_rev.author
141 if last_rev_author.respond_to?(:force_encoding)
143 if last_rev_author.respond_to?(:force_encoding)
142 last_rev_author.force_encoding('UTF-8')
144 last_rev_author.force_encoding('UTF-8')
143 end
145 end
144 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
146 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
145 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
147 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
146 assert_equal "#{str_felix_utf8} <felix@fachschaften.org>",
148 assert_equal "#{str_felix_utf8} <felix@fachschaften.org>",
147 last_rev.author
149 last_rev.author
148 assert_equal "#{str_felix_hex} <felix@fachschaften.org>",
150 assert_equal "#{str_felix_hex} <felix@fachschaften.org>",
149 last_rev.author
151 last_rev.author
150 assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
152 assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
151 end
153 end
152
154
153 def test_latin_1_path
155 def test_latin_1_path
154 if WINDOWS_PASS
156 if WINDOWS_PASS
155 #
157 #
156 else
158 else
157 p2 = "latin-1-dir/test-#{@char_1}-2.txt"
159 p2 = "latin-1-dir/test-#{@char_1}-2.txt"
158 ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1|
160 ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1|
159 assert @adapter.diff(p2, r1)
161 assert @adapter.diff(p2, r1)
160 assert @adapter.cat(p2, r1)
162 assert @adapter.cat(p2, r1)
161 assert_equal 1, @adapter.annotate(p2, r1).lines.length
163 assert_equal 1, @adapter.annotate(p2, r1).lines.length
162 ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2|
164 ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2|
163 assert @adapter.diff(p2, r1, r2)
165 assert @adapter.diff(p2, r1, r2)
164 end
166 end
165 end
167 end
166 end
168 end
167 end
169 end
168
170
169 def test_entries_tag
171 def test_entries_tag
170 entries1 = @adapter.entries(nil, 'tag01.annotated',
172 entries1 = @adapter.entries(nil, 'tag01.annotated',
171 options = {:report_last_commit => true})
173 options = {:report_last_commit => true})
172 assert entries1
174 assert entries1
173 assert_equal 3, entries1.size
175 assert_equal 3, entries1.size
174 assert_equal 'sources', entries1[1].name
176 assert_equal 'sources', entries1[1].name
175 assert_equal 'sources', entries1[1].path
177 assert_equal 'sources', entries1[1].path
176 assert_equal 'dir', entries1[1].kind
178 assert_equal 'dir', entries1[1].kind
177 readme = entries1[2]
179 readme = entries1[2]
178 assert_equal 'README', readme.name
180 assert_equal 'README', readme.name
179 assert_equal 'README', readme.path
181 assert_equal 'README', readme.path
180 assert_equal 'file', readme.kind
182 assert_equal 'file', readme.kind
181 assert_equal 27, readme.size
183 assert_equal 27, readme.size
182 assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier
184 assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier
183 assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
185 assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
184 end
186 end
185
187
186 def test_entries_branch
188 def test_entries_branch
187 entries1 = @adapter.entries(nil, 'test_branch',
189 entries1 = @adapter.entries(nil, 'test_branch',
188 options = {:report_last_commit => true})
190 options = {:report_last_commit => true})
189 assert entries1
191 assert entries1
190 assert_equal 4, entries1.size
192 assert_equal 4, entries1.size
191 assert_equal 'sources', entries1[1].name
193 assert_equal 'sources', entries1[1].name
192 assert_equal 'sources', entries1[1].path
194 assert_equal 'sources', entries1[1].path
193 assert_equal 'dir', entries1[1].kind
195 assert_equal 'dir', entries1[1].kind
194 readme = entries1[2]
196 readme = entries1[2]
195 assert_equal 'README', readme.name
197 assert_equal 'README', readme.name
196 assert_equal 'README', readme.path
198 assert_equal 'README', readme.path
197 assert_equal 'file', readme.kind
199 assert_equal 'file', readme.kind
198 assert_equal 159, readme.size
200 assert_equal 159, readme.size
199 assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier
201 assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier
200 assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time
202 assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time
201 end
203 end
202
204
203 def test_entries_latin_1_files
205 def test_entries_latin_1_files
204 entries1 = @adapter.entries('latin-1-dir', '64f1f3e8')
206 entries1 = @adapter.entries('latin-1-dir', '64f1f3e8')
205 assert entries1
207 assert entries1
206 assert_equal 3, entries1.size
208 assert_equal 3, entries1.size
207 f1 = entries1[1]
209 f1 = entries1[1]
208 assert_equal "test-#{@char_1}-2.txt", f1.name
210 assert_equal "test-#{@char_1}-2.txt", f1.name
209 assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path
211 assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path
210 assert_equal 'file', f1.kind
212 assert_equal 'file', f1.kind
211 end
213 end
212
214
213 def test_entries_latin_1_dir
215 def test_entries_latin_1_dir
214 if WINDOWS_PASS
216 if WINDOWS_PASS
215 #
217 #
216 else
218 else
217 entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir",
219 entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir",
218 '1ca7f5ed')
220 '1ca7f5ed')
219 assert entries1
221 assert entries1
220 assert_equal 3, entries1.size
222 assert_equal 3, entries1.size
221 f1 = entries1[1]
223 f1 = entries1[1]
222 assert_equal "test-#{@char_1}-2.txt", f1.name
224 assert_equal "test-#{@char_1}-2.txt", f1.name
223 assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path
225 assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path
224 assert_equal 'file', f1.kind
226 assert_equal 'file', f1.kind
225 end
227 end
226 end
228 end
227
229
228 private
230 private
229
231
230 def test_scm_version_for(scm_command_version, version)
232 def test_scm_version_for(scm_command_version, version)
231 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
233 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
232 assert_equal version, @adapter.class.scm_command_version
234 assert_equal version, @adapter.class.scm_command_version
233 end
235 end
234
236
235 else
237 else
236 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
238 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
237 def test_fake; assert true end
239 def test_fake; assert true end
238 end
240 end
239 end
241 end
240
242
241 rescue LoadError
243 rescue LoadError
242 class GitMochaFake < ActiveSupport::TestCase
244 class GitMochaFake < ActiveSupport::TestCase
243 def test_fake; assert(false, "Requires mocha to run those tests") end
245 def test_fake; assert(false, "Requires mocha to run those tests") end
244 end
246 end
245 end
247 end
General Comments 0
You need to be logged in to leave comments. Login now