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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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):
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'])
61
self.check_output('added CamelCase\n', 'add camelcase')
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'])
69
self.check_output('added CamelCaseParent\nadded CamelCaseParent/CamelCase\n',
70
'add camelcaseparent/camelcase')
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'])
78
self.check_output('added CamelCaseParent\nadded CamelCaseParent/CamelCase\n',
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')
90
self.check_empty_output('add mixedcase')
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')
103
self.check_empty_output('add mixedcaseparent')
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')
115
class TestMove(TestCICPBase):
116
def test_mv_newname(self):
117
wt = self._make_mixed_case_tree()
119
self.run_bzr('ci -m message')
121
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
122
'mv camelcaseparent/camelcase camelcaseparent/NewCamelCase')
124
def test_mv_newname_after(self):
125
wt = self._make_mixed_case_tree()
127
self.run_bzr('ci -m message')
128
os.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/NewCamelCase')
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')
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()
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')
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()
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')
158
def test_mv_newname_root(self):
159
wt = self._make_mixed_case_tree()
161
self.run_bzr('ci -m message')
163
self.check_output('CamelCaseParent => NewCamelCaseParent\n',
164
'mv camelcaseparent NewCamelCaseParent')
166
def test_mv_newname_root_after(self):
167
wt = self._make_mixed_case_tree()
169
self.run_bzr('ci -m message')
170
os.rename('CamelCaseParent', 'NewCamelCaseParent')
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')
177
def test_mv_newcase(self):
178
wt = self._make_mixed_case_tree()
180
self.run_bzr('ci -m message')
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')
189
def test_mv_newcase_after(self):
190
wt = self._make_mixed_case_tree()
192
self.run_bzr('ci -m message')
194
# perform a mv to the new case - we must ensure the file-system has the
196
os.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/camelCase')
197
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/camelCase\n',
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')
203
def test_mv_multiple(self):
204
wt = self._make_mixed_case_tree()
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')
212
class TestMisc(TestCICPBase):
213
def test_status(self):
214
wt = self._make_mixed_case_tree()
217
self.check_output('added:\n CamelCaseParent/CamelCase\n lowercaseparent/lowercase\n',
218
'status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE')
221
wt = self._make_mixed_case_tree()
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')
230
wt = self._make_mixed_case_tree()
232
self.run_bzr('ci -m message')
234
got = self.run_bzr('rm camelcaseparent LOWERCASEPARENT')[1]
235
for expected in ['lowercaseparent/lowercase', 'CamelCaseParent/CamelCase']:
236
self.assertContainsRe(got, 'deleted ' + expected + '\n')
239
# The following commands need tests and/or cicp lovin':
240
# update, remove, file_id, file_path, diff, log, touching_revisions, ls,
241
# ignore, cat, revert, resolve.