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