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