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