bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
3794.5.9
by Mark Hammond
Correct line-endings. |
1 |
# Copyright (C) 2008 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
#
|
|
17 |
||
18 |
"""Tests variations of case-insensitive and case-preserving file-systems."""
|
|
19 |
||
20 |
import os |
|
21 |
||
22 |
from bzrlib.tests.blackbox import ExternalBase |
|
23 |
from bzrlib.tests import CaseInsCasePresFilenameFeature, KnownFailure |
|
|
3794.5.36
by Mark Hammond
test for, and fix problem with canonical_relpath when the tail does not exist. |
24 |
from bzrlib.osutils import canonical_relpath, pathjoin |
|
3794.5.21
by Mark Hammond
More cicp-filesystem tests |
25 |
|
|
3794.5.23
by Mark Hammond
reoganize tests into categories. |
26 |
class TestCICPBase(ExternalBase): |
27 |
"""Base class for tests on a case-insensitive, case-preserving filesystem. |
|
|
3794.5.9
by Mark Hammond
Correct line-endings. |
28 |
"""
|
29 |
||
30 |
_test_needs_features = [CaseInsCasePresFilenameFeature] |
|
31 |
||
32 |
def _make_mixed_case_tree(self): |
|
33 |
"""Make a working tree with mixed-case filenames.""" |
|
34 |
wt = self.make_branch_and_tree('.') |
|
35 |
# create a file on disk with the mixed-case parent and base name
|
|
36 |
self.build_tree(['CamelCaseParent/', 'lowercaseparent/']) |
|
37 |
self.build_tree_contents([('CamelCaseParent/CamelCase', 'camel case'), |
|
38 |
('lowercaseparent/lowercase', 'lower case'), |
|
39 |
('lowercaseparent/mixedCase', 'mixedCasecase'), |
|
40 |
])
|
|
41 |
return wt |
|
42 |
||
|
3794.5.21
by Mark Hammond
More cicp-filesystem tests |
43 |
def check_error_output(self, retcode, output, *args): |
44 |
got = self.run_bzr(retcode=retcode, *args)[1] |
|
45 |
self.failUnlessEqual(got, output) |
|
|
3794.5.23
by Mark Hammond
reoganize tests into categories. |
46 |
|
|
3794.5.31
by Mark Hammond
bulk of the simple review comments from igc. |
47 |
def check_empty_output(self, *args): |
48 |
"""Check a bzr command generates no output anywhere and exits with 0""" |
|
49 |
out, err = self.run_bzr(retcode=0, *args) |
|
50 |
self.failIf(out) |
|
51 |
self.failIf(err) |
|
52 |
||
53 |
||
|
3794.5.23
by Mark Hammond
reoganize tests into categories. |
54 |
class TestAdd(TestCICPBase): |
|
3794.5.9
by Mark Hammond
Correct line-endings. |
55 |
def test_add_simple(self): |
56 |
"""Test add always uses the case of the filename reported by the os.""" |
|
57 |
wt = self.make_branch_and_tree('.') |
|
58 |
# create a file on disk with the mixed-case name
|
|
59 |
self.build_tree(['CamelCase']) |
|
60 |
||
61 |
self.check_output('added CamelCase\n', 'add camelcase') |
|
62 |
||
63 |
def test_add_subdir(self): |
|
64 |
"""test_add_simple but with subdirectories tested too.""" |
|
65 |
wt = self.make_branch_and_tree('.') |
|
66 |
# create a file on disk with the mixed-case parent and base name
|
|
67 |
self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase']) |
|
68 |
||
69 |
self.check_output('added CamelCaseParent\nadded CamelCaseParent/CamelCase\n', |
|
70 |
'add camelcaseparent/camelcase') |
|
71 |
||
72 |
def test_add_implied(self): |
|
73 |
"""test add with no args sees the correct names.""" |
|
74 |
wt = self.make_branch_and_tree('.') |
|
75 |
# create a file on disk with the mixed-case parent and base name
|
|
76 |
self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase']) |
|
77 |
||
78 |
self.check_output('added CamelCaseParent\nadded CamelCaseParent/CamelCase\n', |
|
79 |
'add') |
|
80 |
||
|
3794.5.23
by Mark Hammond
reoganize tests into categories. |
81 |
def test_re_add(self): |
82 |
"""Test than when a file has 'unintentionally' changed case, we can't |
|
83 |
add a new entry using the new case."""
|
|
84 |
wt = self.make_branch_and_tree('.') |
|
85 |
# create a file on disk with the mixed-case name
|
|
86 |
self.build_tree(['MixedCase']) |
|
87 |
self.check_output('added MixedCase\n', 'add MixedCase') |
|
88 |
# 'accidently' rename the file on disk
|
|
89 |
os.rename('MixedCase', 'mixedcase') |
|
|
3794.5.31
by Mark Hammond
bulk of the simple review comments from igc. |
90 |
self.check_empty_output('add mixedcase') |
|
3794.5.23
by Mark Hammond
reoganize tests into categories. |
91 |
|
92 |
def test_re_add_dir(self): |
|
93 |
# like re-add, but tests when the operation is on a directory.
|
|
94 |
"""Test than when a file has 'unintentionally' changed case, we can't |
|
95 |
add a new entry using the new case."""
|
|
96 |
wt = self.make_branch_and_tree('.') |
|
97 |
# create a file on disk with the mixed-case name
|
|
98 |
self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase']) |
|
99 |
self.check_output('added MixedCaseParent\nadded MixedCaseParent/MixedCase\n', |
|
100 |
'add MixedCaseParent') |
|
101 |
# 'accidently' rename the directory on disk
|
|
102 |
os.rename('MixedCaseParent', 'mixedcaseparent') |
|
|
3794.5.31
by Mark Hammond
bulk of the simple review comments from igc. |
103 |
self.check_empty_output('add mixedcaseparent') |
|
3794.5.23
by Mark Hammond
reoganize tests into categories. |
104 |
|
|
3794.5.36
by Mark Hammond
test for, and fix problem with canonical_relpath when the tail does not exist. |
105 |
def test_add_not_found(self): |
106 |
"""Test add when the input file doesn't exist.""" |
|
107 |
wt = self.make_branch_and_tree('.') |
|
108 |
# create a file on disk with the mixed-case name
|
|
109 |
self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase']) |
|
110 |
expected_fname = pathjoin(wt.basedir, "MixedCaseParent", "notfound") |
|
111 |
expected_msg = "bzr: ERROR: No such file: %r\n" % expected_fname |
|
112 |
self.check_error_output(3, expected_msg, 'add mixedcaseparent/notfound') |
|
113 |
||
|
3794.5.23
by Mark Hammond
reoganize tests into categories. |
114 |
|
115 |
class TestMove(TestCICPBase): |
|
|
3794.5.9
by Mark Hammond
Correct line-endings. |
116 |
def test_mv_newname(self): |
117 |
wt = self._make_mixed_case_tree() |
|
118 |
self.run_bzr('add') |
|
119 |
self.run_bzr('ci -m message') |
|
120 |
||
121 |
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n', |
|
122 |
'mv camelcaseparent/camelcase camelcaseparent/NewCamelCase') |
|
123 |
||
124 |
def test_mv_newname_after(self): |
|
125 |
wt = self._make_mixed_case_tree() |
|
126 |
self.run_bzr('add') |
|
127 |
self.run_bzr('ci -m message') |
|
128 |
os.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/NewCamelCase') |
|
129 |
||
130 |
# In this case we can specify the incorrect case for the destination,
|
|
131 |
# as we use --after, so the file-system is sniffed.
|
|
132 |
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n', |
|
133 |
'mv --after camelcaseparent/camelcase camelcaseparent/newcamelcase') |
|
134 |
||
|
3794.5.21
by Mark Hammond
More cicp-filesystem tests |
135 |
def test_mv_newname_exists(self): |
136 |
# test a mv, but when the target already exists with a name that
|
|
137 |
# differs only by case.
|
|
138 |
wt = self._make_mixed_case_tree() |
|
139 |
self.run_bzr('add') |
|
140 |
self.run_bzr('ci -m message') |
|
141 |
ex = 'bzr: ERROR: Could not move CamelCase => lowercase: lowercaseparent/lowercase is already versioned.\n' |
|
142 |
self.check_error_output(3, ex, 'mv camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE') |
|
143 |
||
144 |
def test_mv_newname_exists_after(self): |
|
145 |
# test a 'mv --after', but when the target already exists with a name
|
|
146 |
# that differs only by case. Note that this is somewhat unlikely
|
|
147 |
# but still reasonable.
|
|
148 |
wt = self._make_mixed_case_tree() |
|
149 |
self.run_bzr('add') |
|
150 |
self.run_bzr('ci -m message') |
|
151 |
# Remove the source and create a destination file on disk with a different case.
|
|
152 |
# bzr should report that the filename is already versioned.
|
|
153 |
os.unlink('CamelCaseParent/CamelCase') |
|
154 |
os.rename('lowercaseparent/lowercase', 'lowercaseparent/LOWERCASE') |
|
155 |
ex = 'bzr: ERROR: Could not move CamelCase => lowercase: lowercaseparent/lowercase is already versioned.\n' |
|
156 |
self.check_error_output(3, ex, 'mv --after camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE') |
|
157 |
||
|
3794.5.9
by Mark Hammond
Correct line-endings. |
158 |
def test_mv_newname_root(self): |
159 |
wt = self._make_mixed_case_tree() |
|
160 |
self.run_bzr('add') |
|
161 |
self.run_bzr('ci -m message') |
|
162 |
||
163 |
self.check_output('CamelCaseParent => NewCamelCaseParent\n', |
|
164 |
'mv camelcaseparent NewCamelCaseParent') |
|
165 |
||
166 |
def test_mv_newname_root_after(self): |
|
167 |
wt = self._make_mixed_case_tree() |
|
168 |
self.run_bzr('add') |
|
169 |
self.run_bzr('ci -m message') |
|
170 |
os.rename('CamelCaseParent', 'NewCamelCaseParent') |
|
171 |
||
172 |
# In this case we can specify the incorrect case for the destination,
|
|
173 |
# as we use --after, so the file-system is sniffed.
|
|
174 |
self.check_output('CamelCaseParent => NewCamelCaseParent\n', |
|
175 |
'mv --after camelcaseparent newcamelcaseparent') |
|
176 |
||
177 |
def test_mv_newcase(self): |
|
178 |
wt = self._make_mixed_case_tree() |
|
179 |
self.run_bzr('add') |
|
180 |
self.run_bzr('ci -m message') |
|
181 |
||
|
3794.5.21
by Mark Hammond
More cicp-filesystem tests |
182 |
# perform a mv to the new case - we expect bzr to accept the new
|
183 |
# name, as specified, and rename the file on the file-system too.
|
|
184 |
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/camelCase\n', |
|
185 |
'mv camelcaseparent/camelcase camelcaseparent/camelCase') |
|
186 |
self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'), |
|
187 |
'CamelCaseParent/camelCase') |
|
188 |
||
189 |
def test_mv_newcase_after(self): |
|
190 |
wt = self._make_mixed_case_tree() |
|
191 |
self.run_bzr('add') |
|
192 |
self.run_bzr('ci -m message') |
|
193 |
||
|
3794.5.9
by Mark Hammond
Correct line-endings. |
194 |
# perform a mv to the new case - we must ensure the file-system has the
|
195 |
# new case first.
|
|
196 |
os.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/camelCase') |
|
197 |
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/camelCase\n', |
|
|
3794.5.21
by Mark Hammond
More cicp-filesystem tests |
198 |
'mv --after camelcaseparent/camelcase camelcaseparent/camelCase') |
199 |
# bzr should not have renamed the file to a different case
|
|
200 |
self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'), |
|
201 |
'CamelCaseParent/camelCase') |
|
|
3794.5.9
by Mark Hammond
Correct line-endings. |
202 |
|
203 |
def test_mv_multiple(self): |
|
204 |
wt = self._make_mixed_case_tree() |
|
205 |
self.run_bzr('add') |
|
206 |
self.run_bzr('ci -m message') |
|
207 |
self.check_output('lowercaseparent/lowercase => CamelCaseParent/lowercase\n' |
|
208 |
'lowercaseparent/mixedCase => CamelCaseParent/mixedCase\n', |
|
209 |
'mv LOWercaseparent/LOWercase LOWercaseparent/MIXEDCase camelcaseparent') |
|
210 |
||
|
3794.5.23
by Mark Hammond
reoganize tests into categories. |
211 |
|
212 |
class TestMisc(TestCICPBase): |
|
213 |
def test_status(self): |
|
214 |
wt = self._make_mixed_case_tree() |
|
215 |
self.run_bzr('add') |
|
216 |
||
217 |
self.check_output('added:\n CamelCaseParent/CamelCase\n lowercaseparent/lowercase\n', |
|
218 |
'status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE') |
|
219 |
||
220 |
def test_ci(self): |
|
221 |
wt = self._make_mixed_case_tree() |
|
222 |
self.run_bzr('add') |
|
223 |
||
224 |
got = self.run_bzr('ci -m message camelcaseparent LOWERCASEPARENT')[1] |
|
225 |
for expected in ['CamelCaseParent', 'lowercaseparent', |
|
226 |
'CamelCaseParent/CamelCase', 'lowercaseparent/lowercase']: |
|
227 |
self.assertContainsRe(got, 'added ' + expected + '\n') |
|
228 |
||
229 |
def test_rm(self): |
|
230 |
wt = self._make_mixed_case_tree() |
|
231 |
self.run_bzr('add') |
|
232 |
self.run_bzr('ci -m message') |
|
233 |
||
234 |
got = self.run_bzr('rm camelcaseparent LOWERCASEPARENT')[1] |
|
235 |
for expected in ['lowercaseparent/lowercase', 'CamelCaseParent/CamelCase']: |
|
236 |
self.assertContainsRe(got, 'deleted ' + expected + '\n') |
|
237 |
||
|
3794.5.10
by Mark Hammond
Add comments about commands that should still get love. |
238 |
|
239 |
# The following commands need tests and/or cicp lovin':
|
|
240 |
# update, remove, file_id, file_path, diff, log, touching_revisions, ls,
|
|
|
3794.5.31
by Mark Hammond
bulk of the simple review comments from igc. |
241 |
# ignore, cat, revert, resolve.
|