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