1
# Copyright (C) 2008 Canonical Ltd
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Tests variations of case-insensitive and case-preserving file-systems."""
22
from bzrlib.tests.blackbox import ExternalBase
23
from bzrlib.tests import CaseInsCasePresFilenameFeature, KnownFailure
24
from bzrlib.osutils import canonical_relpath, pathjoin
26
class TestCICPBase(ExternalBase):
27
"""Base class for tests on a case-insensitive, case-preserving filesystem.
30
_test_needs_features = [CaseInsCasePresFilenameFeature]
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'),
43
def check_error_output(self, retcode, output, *args):
44
got = self.run_bzr(retcode=retcode, *args)[1]
45
self.failUnlessEqual(got, output)
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)
54
class TestAdd(TestCICPBase):
56
def test_add_simple(self):
57
"""Test add always uses the case of the filename reported by the os."""
58
wt = self.make_branch_and_tree('.')
59
# create a file on disk with the mixed-case name
60
self.build_tree(['CamelCase'])
62
self.check_output('adding CamelCase\n', 'add camelcase')
64
def test_add_subdir(self):
65
"""test_add_simple but with subdirectories tested too."""
66
wt = self.make_branch_and_tree('.')
67
# create a file on disk with the mixed-case parent and base name
68
self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase'])
70
self.check_output('adding CamelCaseParent\n'
71
'adding CamelCaseParent/CamelCase\n',
72
'add camelcaseparent/camelcase')
74
def test_add_implied(self):
75
"""test add with no args sees the correct names."""
76
wt = self.make_branch_and_tree('.')
77
# create a file on disk with the mixed-case parent and base name
78
self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase'])
80
self.check_output('adding CamelCaseParent\n'
81
'adding CamelCaseParent/CamelCase\n',
84
def test_re_add(self):
85
"""Test than when a file has 'unintentionally' changed case, we can't
86
add a new entry using the new case."""
87
wt = self.make_branch_and_tree('.')
88
# create a file on disk with the mixed-case name
89
self.build_tree(['MixedCase'])
90
self.check_output('adding MixedCase\n', 'add MixedCase')
91
# 'accidently' rename the file on disk
92
os.rename('MixedCase', 'mixedcase')
93
self.check_empty_output('add mixedcase')
95
def test_re_add_dir(self):
96
# like re-add, but tests when the operation is on a directory.
97
"""Test than when a file has 'unintentionally' changed case, we can't
98
add a new entry using the new case."""
99
wt = self.make_branch_and_tree('.')
100
# create a file on disk with the mixed-case name
101
self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase'])
102
self.check_output('adding MixedCaseParent\n'
103
'adding MixedCaseParent/MixedCase\n',
104
'add MixedCaseParent')
105
# 'accidently' rename the directory on disk
106
os.rename('MixedCaseParent', 'mixedcaseparent')
107
self.check_empty_output('add mixedcaseparent')
109
def test_add_not_found(self):
110
"""Test add when the input file doesn't exist."""
111
wt = self.make_branch_and_tree('.')
112
# create a file on disk with the mixed-case name
113
self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase'])
114
expected_fname = pathjoin(wt.basedir, "MixedCaseParent", "notfound")
115
expected_msg = "bzr: ERROR: No such file: %r\n" % expected_fname
116
self.check_error_output(3, expected_msg, 'add mixedcaseparent/notfound')
119
class TestMove(TestCICPBase):
120
def test_mv_newname(self):
121
wt = self._make_mixed_case_tree()
123
self.run_bzr('ci -m message')
126
'CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
127
'mv camelcaseparent/camelcase camelcaseparent/NewCamelCase')
129
def test_mv_newname_after(self):
130
wt = self._make_mixed_case_tree()
132
self.run_bzr('ci -m message')
133
os.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/NewCamelCase')
135
# In this case we can specify the incorrect case for the destination,
136
# as we use --after, so the file-system is sniffed.
138
'CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
139
'mv --after camelcaseparent/camelcase camelcaseparent/newcamelcase')
141
def test_mv_newname_exists(self):
142
# test a mv, but when the target already exists with a name that
143
# differs only by case.
144
wt = self._make_mixed_case_tree()
146
self.run_bzr('ci -m message')
147
ex = 'bzr: ERROR: Could not move CamelCase => lowercase: lowercaseparent/lowercase is already versioned.\n'
148
self.check_error_output(3, ex, 'mv camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE')
150
def test_mv_newname_exists_after(self):
151
# test a 'mv --after', but when the target already exists with a name
152
# that differs only by case. Note that this is somewhat unlikely
153
# but still reasonable.
154
wt = self._make_mixed_case_tree()
156
self.run_bzr('ci -m message')
157
# Remove the source and create a destination file on disk with a different case.
158
# bzr should report that the filename is already versioned.
159
os.unlink('CamelCaseParent/CamelCase')
160
os.rename('lowercaseparent/lowercase', 'lowercaseparent/LOWERCASE')
161
ex = 'bzr: ERROR: Could not move CamelCase => lowercase: lowercaseparent/lowercase is already versioned.\n'
162
self.check_error_output(3, ex, 'mv --after camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE')
164
def test_mv_newname_root(self):
165
wt = self._make_mixed_case_tree()
167
self.run_bzr('ci -m message')
169
self.check_output('CamelCaseParent => NewCamelCaseParent\n',
170
'mv camelcaseparent NewCamelCaseParent')
172
def test_mv_newname_root_after(self):
173
wt = self._make_mixed_case_tree()
175
self.run_bzr('ci -m message')
176
os.rename('CamelCaseParent', 'NewCamelCaseParent')
178
# In this case we can specify the incorrect case for the destination,
179
# as we use --after, so the file-system is sniffed.
180
self.check_output('CamelCaseParent => NewCamelCaseParent\n',
181
'mv --after camelcaseparent newcamelcaseparent')
183
def test_mv_newcase(self):
184
wt = self._make_mixed_case_tree()
186
self.run_bzr('ci -m message')
188
# perform a mv to the new case - we expect bzr to accept the new
189
# name, as specified, and rename the file on the file-system too.
190
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/camelCase\n',
191
'mv camelcaseparent/camelcase camelcaseparent/camelCase')
192
self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
193
'CamelCaseParent/camelCase')
195
def test_mv_newcase_after(self):
196
wt = self._make_mixed_case_tree()
198
self.run_bzr('ci -m message')
200
# perform a mv to the new case - we must ensure the file-system has the
202
os.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/camelCase')
203
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/camelCase\n',
204
'mv --after camelcaseparent/camelcase camelcaseparent/camelCase')
205
# bzr should not have renamed the file to a different case
206
self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
207
'CamelCaseParent/camelCase')
209
def test_mv_multiple(self):
210
wt = self._make_mixed_case_tree()
212
self.run_bzr('ci -m message')
213
self.check_output('lowercaseparent/lowercase => CamelCaseParent/lowercase\n'
214
'lowercaseparent/mixedCase => CamelCaseParent/mixedCase\n',
215
'mv LOWercaseparent/LOWercase LOWercaseparent/MIXEDCase camelcaseparent')
218
class TestMisc(TestCICPBase):
220
def test_status(self):
221
wt = self._make_mixed_case_tree()
227
CamelCaseParent/CamelCase
229
lowercaseparent/lowercase
231
'status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE')
234
wt = self._make_mixed_case_tree()
237
got = self.run_bzr('ci -m message camelcaseparent LOWERCASEPARENT')[1]
238
for expected in ['CamelCaseParent', 'lowercaseparent',
239
'CamelCaseParent/CamelCase', 'lowercaseparent/lowercase']:
240
self.assertContainsRe(got, 'added ' + expected + '\n')
243
wt = self._make_mixed_case_tree()
245
self.run_bzr('ci -m message')
247
got = self.run_bzr('rm camelcaseparent LOWERCASEPARENT')[1]
248
for expected in ['lowercaseparent/lowercase', 'CamelCaseParent/CamelCase']:
249
self.assertContainsRe(got, 'deleted ' + expected + '\n')
252
# The following commands need tests and/or cicp lovin':
253
# update, remove, file_id, file_path, diff, log, touching_revisions, ls,
254
# ignore, cat, revert, resolve.