1
# Copyright (C) 2008 Canonical Ltd
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
22
from bzrlib.tests.blackbox import ExternalBase
23
26
from bzrlib.tests import CaseInsCasePresFilenameFeature, KnownFailure
24
27
from bzrlib.osutils import canonical_relpath, pathjoin
26
class TestCICPBase(ExternalBase):
28
from bzrlib.tests.script import run_script
31
class TestCICPBase(tests.TestCaseWithTransport):
27
32
"""Base class for tests on a case-insensitive, case-preserving filesystem.
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
49
class TestAdd(TestCICPBase):
58
53
wt = self.make_branch_and_tree('.')
59
54
# create a file on disk with the mixed-case name
60
55
self.build_tree(['CamelCase'])
62
self.check_output('adding CamelCase\n', 'add camelcase')
64
61
def test_add_subdir(self):
65
62
"""test_add_simple but with subdirectories tested too."""
66
63
wt = self.make_branch_and_tree('.')
67
64
# create a file on disk with the mixed-case parent and base name
68
65
self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase'])
70
self.check_output('adding CamelCaseParent\n'
71
'adding CamelCaseParent/CamelCase\n',
72
'add camelcaseparent/camelcase')
67
$ bzr add camelcaseparent/camelcase
68
adding CamelCaseParent
69
adding CamelCaseParent/CamelCase
74
72
def test_add_implied(self):
75
73
"""test add with no args sees the correct names."""
76
74
wt = self.make_branch_and_tree('.')
77
75
# create a file on disk with the mixed-case parent and base name
78
76
self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase'])
80
self.check_output('adding CamelCaseParent\n'
81
'adding CamelCaseParent/CamelCase\n',
79
adding CamelCaseParent
80
adding CamelCaseParent/CamelCase
84
83
def test_re_add(self):
85
84
"""Test than when a file has 'unintentionally' changed case, we can't
87
86
wt = self.make_branch_and_tree('.')
88
87
# create a file on disk with the mixed-case name
89
88
self.build_tree(['MixedCase'])
90
self.check_output('adding MixedCase\n', 'add MixedCase')
91
93
# 'accidently' rename the file on disk
92
os.rename('MixedCase', 'mixedcase')
93
self.check_empty_output('add mixedcase')
94
osutils.rename('MixedCase', 'mixedcase')
95
99
def test_re_add_dir(self):
96
100
# like re-add, but tests when the operation is on a directory.
99
103
wt = self.make_branch_and_tree('.')
100
104
# create a file on disk with the mixed-case name
101
105
self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase'])
102
self.check_output('adding MixedCaseParent\n'
103
'adding MixedCaseParent/MixedCase\n',
104
'add MixedCaseParent')
107
$ bzr add MixedCaseParent
108
adding MixedCaseParent
109
adding MixedCaseParent/MixedCase
105
111
# 'accidently' rename the directory on disk
106
os.rename('MixedCaseParent', 'mixedcaseparent')
107
self.check_empty_output('add mixedcaseparent')
112
osutils.rename('MixedCaseParent', 'mixedcaseparent')
114
$ bzr add mixedcaseparent
109
117
def test_add_not_found(self):
110
118
"""Test add when the input file doesn't exist."""
112
120
# create a file on disk with the mixed-case name
113
121
self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase'])
114
122
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')
124
$ bzr add mixedcaseparent/notfound
125
2>bzr: ERROR: No such file: %s
126
""" % (repr(expected_fname),))
119
129
class TestMove(TestCICPBase):
120
131
def test_mv_newname(self):
121
132
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')
136
$ bzr mv camelcaseparent/camelcase camelcaseparent/NewCamelCase
137
CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase
129
140
def test_mv_newname_after(self):
130
141
wt = self._make_mixed_case_tree()
132
self.run_bzr('ci -m message')
133
os.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/NewCamelCase')
135
142
# In this case we can specify the incorrect case for the destination,
136
143
# as we use --after, so the file-system is sniffed.
138
'CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
139
'mv --after camelcaseparent/camelcase camelcaseparent/newcamelcase')
147
$ mv CamelCaseParent/CamelCase CamelCaseParent/NewCamelCase
148
$ bzr mv --after camelcaseparent/camelcase camelcaseparent/newcamelcase
149
CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase
141
152
def test_mv_newname_exists(self):
142
153
# test a mv, but when the target already exists with a name that
144
155
wt = self._make_mixed_case_tree()
145
156
self.run_bzr('add')
146
157
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')
159
$ bzr mv camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
160
2>bzr: ERROR: Could not move CamelCase => lowercase: \
161
lowercaseparent/lowercase is already versioned.
150
164
def test_mv_newname_exists_after(self):
151
165
# test a 'mv --after', but when the target already exists with a name
157
171
# Remove the source and create a destination file on disk with a different case.
158
172
# bzr should report that the filename is already versioned.
159
173
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')
174
osutils.rename('lowercaseparent/lowercase', 'lowercaseparent/LOWERCASE')
176
$ bzr mv --after camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
177
2>bzr: ERROR: Could not move CamelCase => lowercase: \
178
lowercaseparent/lowercase is already versioned.
164
181
def test_mv_newname_root(self):
165
182
wt = self._make_mixed_case_tree()
166
183
self.run_bzr('add')
167
184
self.run_bzr('ci -m message')
169
self.check_output('CamelCaseParent => NewCamelCaseParent\n',
170
'mv camelcaseparent NewCamelCaseParent')
186
$ bzr mv camelcaseparent NewCamelCaseParent
187
CamelCaseParent => NewCamelCaseParent
172
190
def test_mv_newname_root_after(self):
173
191
wt = self._make_mixed_case_tree()
174
192
self.run_bzr('add')
175
193
self.run_bzr('ci -m message')
176
os.rename('CamelCaseParent', 'NewCamelCaseParent')
178
194
# In this case we can specify the incorrect case for the destination,
179
195
# as we use --after, so the file-system is sniffed.
180
self.check_output('CamelCaseParent => NewCamelCaseParent\n',
181
'mv --after camelcaseparent newcamelcaseparent')
197
$ mv CamelCaseParent NewCamelCaseParent
198
$ bzr mv --after camelcaseparent NewCamelCaseParent
199
CamelCaseParent => NewCamelCaseParent
183
202
def test_mv_newcase(self):
184
203
wt = self._make_mixed_case_tree()
188
207
# perform a mv to the new case - we expect bzr to accept the new
189
208
# 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')
210
$ bzr mv camelcaseparent/camelcase camelcaseparent/camelCase
211
CamelCaseParent/CamelCase => CamelCaseParent/camelCase
192
213
self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
193
214
'CamelCaseParent/camelCase')
200
221
# perform a mv to the new case - we must ensure the file-system has the
201
222
# new case first.
202
os.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/camelCase')
203
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/camelCase\n',
204
'mv --after camelcaseparent/camelcase camelcaseparent/camelCase')
223
osutils.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/camelCase')
225
$ bzr mv --after camelcaseparent/camelcase camelcaseparent/camelCase
226
CamelCaseParent/CamelCase => CamelCaseParent/camelCase
205
228
# bzr should not have renamed the file to a different case
206
229
self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
207
230
'CamelCaseParent/camelCase')
210
233
wt = self._make_mixed_case_tree()
211
234
self.run_bzr('add')
212
235
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')
237
$ bzr mv LOWercaseparent/LOWercase LOWercaseparent/MIXEDCase camelcaseparent
238
lowercaseparent/lowercase => CamelCaseParent/lowercase
239
lowercaseparent/mixedCase => CamelCaseParent/mixedCase
218
243
class TestMisc(TestCICPBase):
220
245
def test_status(self):
221
246
wt = self._make_mixed_case_tree()
222
247
self.run_bzr('add')
227
CamelCaseParent/CamelCase
229
lowercaseparent/lowercase
231
'status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE')
249
$ bzr status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
252
CamelCaseParent/CamelCase
254
lowercaseparent/lowercase
233
257
def test_ci(self):
234
258
wt = self._make_mixed_case_tree()