##// END OF EJS Templates
scm: cvs: update test repository....
Toshi MARUYAMA -
r5331:d43bc98a497a
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
@@ -1,67 +1,67
1 1 require File.expand_path('../../../../../../test_helper', __FILE__)
2 2 begin
3 3 require 'mocha'
4 4
5 5 class CvsAdapterTest < ActiveSupport::TestCase
6 6
7 7 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository'
8 8 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
9 9 MODULE_NAME = 'test'
10 10
11 11 if File.directory?(REPOSITORY_PATH)
12 12 def setup
13 13 @adapter = Redmine::Scm::Adapters::CvsAdapter.new(MODULE_NAME, REPOSITORY_PATH)
14 14 end
15 15
16 16 def test_scm_version
17 17 to_test = { "\nConcurrent Versions System (CVS) 1.12.13 (client/server)\n" => [1,12,13],
18 18 "\r\n1.12.12\r\n1.12.11" => [1,12,12],
19 19 "1.12.11\r\n1.12.10\r\n" => [1,12,11]}
20 20 to_test.each do |s, v|
21 21 test_scm_version_for(s, v)
22 22 end
23 23 end
24 24
25 25 def test_revisions_all
26 26 cnt = 0
27 27 @adapter.revisions('', nil, nil, :with_paths => true) do |revision|
28 28 cnt += 1
29 29 end
30 assert_equal 14, cnt
30 assert_equal 16, cnt
31 31 end
32 32
33 33 def test_revisions_from_rev3
34 34 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
35 35 cnt = 0
36 36 @adapter.revisions('', rev3_committed_on, nil, :with_paths => true) do |revision|
37 37 cnt += 1
38 38 end
39 assert_equal 2, cnt
39 assert_equal 4, cnt
40 40 end
41 41
42 42 def test_entries_rev3
43 43 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
44 44 entries = @adapter.entries('sources', rev3_committed_on)
45 45 assert_equal 2, entries.size
46 46 assert_equal entries[0].name, "watchers_controller.rb"
47 47 assert_equal entries[0].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
48 48 end
49 49
50 50 private
51 51
52 52 def test_scm_version_for(scm_command_version, version)
53 53 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
54 54 assert_equal version, @adapter.class.scm_command_version
55 55 end
56 56 else
57 57 puts "Cvs test repository NOT FOUND. Skipping unit tests !!!"
58 58 def test_fake; assert true end
59 59 end
60 60 end
61 61
62 62 rescue LoadError
63 63 class CvsMochaFake < ActiveSupport::TestCase
64 64 def test_fake; assert(false, "Requires mocha to run those tests") end
65 65 end
66 66 end
67 67
@@ -1,168 +1,169
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'pp'
20 20 class RepositoryCvsTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 # No '..' in the repository path
24 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository'
25 25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
26 26 # CVS module
27 27 MODULE_NAME = 'test'
28 CHANGESETS_NUM = 7
28 29
29 30 def setup
30 31 @project = Project.find(3)
31 32 @repository = Repository::Cvs.create(:project => @project,
32 33 :root_url => REPOSITORY_PATH,
33 34 :url => MODULE_NAME,
34 35 :log_encoding => 'UTF-8')
35 36 assert @repository
36 37 end
37 38
38 39 if File.directory?(REPOSITORY_PATH)
39 40 def test_fetch_changesets_from_scratch
40 41 assert_equal 0, @repository.changesets.count
41 42 @repository.fetch_changesets
42 43 @repository.reload
43 44
44 assert_equal 5, @repository.changesets.count
45 assert_equal 14, @repository.changes.count
45 assert_equal CHANGESETS_NUM, @repository.changesets.count
46 assert_equal 16, @repository.changes.count
46 47 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
47 48
48 49 r2 = @repository.changesets.find_by_revision('2')
49 50 assert_equal 'v1-20071213-162510', r2.scmid
50 51 end
51 52
52 53 def test_fetch_changesets_incremental
53 54 assert_equal 0, @repository.changesets.count
54 55 @repository.fetch_changesets
55 56 # Remove changesets with revision > 3
56 57 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
57 58 @repository.reload
58 59 assert_equal 3, @repository.changesets.count
59 60 assert_equal %w|3 2 1|, @repository.changesets.collect(&:revision)
60 61
61 62 rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
62 63 assert_equal '3', rev3_commit.revision
63 64 # 2007-12-14 01:27:22 +0900
64 65 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
65 66 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
66 67 assert_equal rev3_committed_on, rev3_commit.committed_on
67 68 latest_rev = @repository.latest_changeset
68 69 assert_equal rev3_committed_on, latest_rev.committed_on
69 70
70 71 @repository.fetch_changesets
71 72 @repository.reload
72 assert_equal 5, @repository.changesets.count
73 assert_equal CHANGESETS_NUM, @repository.changesets.count
73 74
74 assert_equal %w|5 4 3 2 1|, @repository.changesets.collect(&:revision)
75 rev5_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
75 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.collect(&:revision)
76 rev5_commit = @repository.changesets.find_by_revision('5')
76 77 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
77 78 # 2007-12-14 01:30:01 +0900
78 79 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
79 80 assert_equal rev5_committed_on, rev5_commit.committed_on
80 81 end
81 82
82 83 def test_deleted_files_should_not_be_listed
83 84 assert_equal 0, @repository.changesets.count
84 85 @repository.fetch_changesets
85 86 @repository.reload
86 assert_equal 5, @repository.changesets.count
87 assert_equal CHANGESETS_NUM, @repository.changesets.count
87 88
88 89 entries = @repository.entries('sources')
89 90 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
90 91 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
91 92 end
92 93
93 94 def test_entries_rev3
94 95 @repository.fetch_changesets
95 96 @repository.reload
96 97 entries = @repository.entries('', '3')
97 98 assert_equal 3, entries.size
98 99 assert_equal entries[2].name, "README"
99 100 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
100 101 assert_equal entries[2].lastrev.identifier, '3'
101 102 assert_equal entries[2].lastrev.revision, '3'
102 103 assert_equal entries[2].lastrev.author, 'LANG'
103 104 end
104 105
105 106 def test_entries_invalid_path
106 107 @repository.fetch_changesets
107 108 @repository.reload
108 109 assert_nil @repository.entries('missing')
109 110 assert_nil @repository.entries('missing', '3')
110 111 end
111 112
112 113 def test_entries_invalid_revision
113 114 @repository.fetch_changesets
114 115 @repository.reload
115 116 assert_nil @repository.entries('', '123')
116 117 end
117 118
118 119 def test_cat
119 120 @repository.fetch_changesets
120 121 @repository.reload
121 122 buf = @repository.cat('README')
122 123 assert buf
123 124 lines = buf.split("\n")
124 assert_equal 2, lines.length
125 assert_equal 3, lines.length
125 126 buf = lines[1].gsub(/\r$/, "")
126 127 assert_equal 'with one change', buf
127 128 buf = @repository.cat('README', '1')
128 129 assert buf
129 130 lines = buf.split("\n")
130 131 assert_equal 1, lines.length
131 132 buf = lines[0].gsub(/\r$/, "")
132 133 assert_equal 'CVS test repository', buf
133 134 assert_nil @repository.cat('missing.rb')
134 135
135 136 # sources/welcome_controller.rb is removed at revision 5.
136 137 assert @repository.cat('sources/welcome_controller.rb', '4')
137 138 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
138 139
139 140 # invalid revision
140 141 assert @repository.cat('README', '123').blank?
141 142 end
142 143
143 144 def test_annotate
144 145 @repository.fetch_changesets
145 146 @repository.reload
146 147 ann = @repository.annotate('README')
147 148 assert ann
148 assert_equal 2, ann.revisions.length
149 assert_equal 3, ann.revisions.length
149 150 assert_equal '1.2', ann.revisions[1].revision
150 151 assert_equal 'LANG', ann.revisions[1].author
151 152 assert_equal 'with one change', ann.lines[1]
152 153
153 154 ann = @repository.annotate('README', '1')
154 155 assert ann
155 156 assert_equal 1, ann.revisions.length
156 157 assert_equal '1.1', ann.revisions[0].revision
157 158 assert_equal 'LANG', ann.revisions[0].author
158 159 assert_equal 'CVS test repository', ann.lines[0]
159 160
160 161 # invalid revision
161 162 assert_nil @repository.annotate('README', '123')
162 163 end
163 164
164 165 else
165 166 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
166 167 def test_fake; assert true end
167 168 end
168 169 end
General Comments 0
You need to be logged in to leave comments. Login now