1
# Copyright (C) 2008, 2010 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 import (osutils,
24
from bzrlib.tests.blackbox import ExternalBase
25
26
from bzrlib.tests import CaseInsCasePresFilenameFeature, KnownFailure
26
27
from bzrlib.osutils import canonical_relpath, pathjoin
28
class TestCICPBase(ExternalBase):
28
from bzrlib.tests.script import run_script
31
class TestCICPBase(tests.TestCaseWithTransport):
29
32
"""Base class for tests on a case-insensitive, case-preserving filesystem.
45
def check_error_output(self, retcode, output, *args):
46
got = self.run_bzr(retcode=retcode, *args)[1]
47
self.failUnlessEqual(got, output)
49
def check_empty_output(self, *args):
50
"""Check a bzr command generates no output anywhere and exits with 0"""
51
out, err = self.run_bzr(retcode=0, *args)
56
49
class TestAdd(TestCICPBase):
60
53
wt = self.make_branch_and_tree('.')
61
54
# create a file on disk with the mixed-case name
62
55
self.build_tree(['CamelCase'])
64
self.check_output('adding CamelCase\n', 'add camelcase')
66
61
def test_add_subdir(self):
67
62
"""test_add_simple but with subdirectories tested too."""
68
63
wt = self.make_branch_and_tree('.')
69
64
# create a file on disk with the mixed-case parent and base name
70
65
self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase'])
72
self.check_output('adding CamelCaseParent\n'
73
'adding CamelCaseParent/CamelCase\n',
74
'add camelcaseparent/camelcase')
67
$ bzr add camelcaseparent/camelcase
68
adding CamelCaseParent
69
adding CamelCaseParent/CamelCase
76
72
def test_add_implied(self):
77
73
"""test add with no args sees the correct names."""
78
74
wt = self.make_branch_and_tree('.')
79
75
# create a file on disk with the mixed-case parent and base name
80
76
self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase'])
82
self.check_output('adding CamelCaseParent\n'
83
'adding CamelCaseParent/CamelCase\n',
79
adding CamelCaseParent
80
adding CamelCaseParent/CamelCase
86
83
def test_re_add(self):
87
84
"""Test than when a file has 'unintentionally' changed case, we can't
89
86
wt = self.make_branch_and_tree('.')
90
87
# create a file on disk with the mixed-case name
91
88
self.build_tree(['MixedCase'])
92
self.check_output('adding MixedCase\n', 'add MixedCase')
93
93
# 'accidently' rename the file on disk
94
94
osutils.rename('MixedCase', 'mixedcase')
95
self.check_empty_output('add mixedcase')
97
99
def test_re_add_dir(self):
98
100
# like re-add, but tests when the operation is on a directory.
101
103
wt = self.make_branch_and_tree('.')
102
104
# create a file on disk with the mixed-case name
103
105
self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase'])
104
self.check_output('adding MixedCaseParent\n'
105
'adding MixedCaseParent/MixedCase\n',
106
'add MixedCaseParent')
107
$ bzr add MixedCaseParent
108
adding MixedCaseParent
109
adding MixedCaseParent/MixedCase
107
111
# 'accidently' rename the directory on disk
108
112
osutils.rename('MixedCaseParent', 'mixedcaseparent')
109
self.check_empty_output('add mixedcaseparent')
114
$ bzr add mixedcaseparent
111
117
def test_add_not_found(self):
112
118
"""Test add when the input file doesn't exist."""
114
120
# create a file on disk with the mixed-case name
115
121
self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase'])
116
122
expected_fname = pathjoin(wt.basedir, "MixedCaseParent", "notfound")
117
expected_msg = "bzr: ERROR: No such file: %r\n" % expected_fname
118
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),))
121
129
class TestMove(TestCICPBase):
122
131
def test_mv_newname(self):
123
132
wt = self._make_mixed_case_tree()
125
self.run_bzr('ci -m message')
128
'CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
129
'mv camelcaseparent/camelcase camelcaseparent/NewCamelCase')
136
$ bzr mv camelcaseparent/camelcase camelcaseparent/NewCamelCase
137
CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase
131
140
def test_mv_newname_after(self):
132
141
wt = self._make_mixed_case_tree()
134
self.run_bzr('ci -m message')
135
osutils.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/NewCamelCase')
137
142
# In this case we can specify the incorrect case for the destination,
138
143
# as we use --after, so the file-system is sniffed.
140
'CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
141
'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
143
152
def test_mv_newname_exists(self):
144
153
# test a mv, but when the target already exists with a name that
146
155
wt = self._make_mixed_case_tree()
147
156
self.run_bzr('add')
148
157
self.run_bzr('ci -m message')
149
ex = 'bzr: ERROR: Could not move CamelCase => lowercase: lowercaseparent/lowercase is already versioned.\n'
150
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.
152
164
def test_mv_newname_exists_after(self):
153
165
# test a 'mv --after', but when the target already exists with a name
160
172
# bzr should report that the filename is already versioned.
161
173
os.unlink('CamelCaseParent/CamelCase')
162
174
osutils.rename('lowercaseparent/lowercase', 'lowercaseparent/LOWERCASE')
163
ex = 'bzr: ERROR: Could not move CamelCase => lowercase: lowercaseparent/lowercase is already versioned.\n'
164
self.check_error_output(3, ex, 'mv --after camelcaseparent/camelcase 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.
166
181
def test_mv_newname_root(self):
167
182
wt = self._make_mixed_case_tree()
168
183
self.run_bzr('add')
169
184
self.run_bzr('ci -m message')
171
self.check_output('CamelCaseParent => NewCamelCaseParent\n',
172
'mv camelcaseparent NewCamelCaseParent')
186
$ bzr mv camelcaseparent NewCamelCaseParent
187
CamelCaseParent => NewCamelCaseParent
174
190
def test_mv_newname_root_after(self):
175
191
wt = self._make_mixed_case_tree()
176
192
self.run_bzr('add')
177
193
self.run_bzr('ci -m message')
178
osutils.rename('CamelCaseParent', 'NewCamelCaseParent')
180
194
# In this case we can specify the incorrect case for the destination,
181
195
# as we use --after, so the file-system is sniffed.
182
self.check_output('CamelCaseParent => NewCamelCaseParent\n',
183
'mv --after camelcaseparent newcamelcaseparent')
197
$ mv CamelCaseParent NewCamelCaseParent
198
$ bzr mv --after camelcaseparent NewCamelCaseParent
199
CamelCaseParent => NewCamelCaseParent
185
202
def test_mv_newcase(self):
186
203
wt = self._make_mixed_case_tree()
190
207
# perform a mv to the new case - we expect bzr to accept the new
191
208
# name, as specified, and rename the file on the file-system too.
192
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/camelCase\n',
193
'mv camelcaseparent/camelcase camelcaseparent/camelCase')
210
$ bzr mv camelcaseparent/camelcase camelcaseparent/camelCase
211
CamelCaseParent/CamelCase => CamelCaseParent/camelCase
194
213
self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
195
214
'CamelCaseParent/camelCase')
202
221
# perform a mv to the new case - we must ensure the file-system has the
203
222
# new case first.
204
223
osutils.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/camelCase')
205
self.check_output('CamelCaseParent/CamelCase => CamelCaseParent/camelCase\n',
206
'mv --after camelcaseparent/camelcase camelcaseparent/camelCase')
225
$ bzr mv --after camelcaseparent/camelcase camelcaseparent/camelCase
226
CamelCaseParent/CamelCase => CamelCaseParent/camelCase
207
228
# bzr should not have renamed the file to a different case
208
229
self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
209
230
'CamelCaseParent/camelCase')
212
233
wt = self._make_mixed_case_tree()
213
234
self.run_bzr('add')
214
235
self.run_bzr('ci -m message')
215
self.check_output('lowercaseparent/lowercase => CamelCaseParent/lowercase\n'
216
'lowercaseparent/mixedCase => CamelCaseParent/mixedCase\n',
217
'mv LOWercaseparent/LOWercase LOWercaseparent/MIXEDCase camelcaseparent')
237
$ bzr mv LOWercaseparent/LOWercase LOWercaseparent/MIXEDCase camelcaseparent
238
lowercaseparent/lowercase => CamelCaseParent/lowercase
239
lowercaseparent/mixedCase => CamelCaseParent/mixedCase
220
243
class TestMisc(TestCICPBase):
222
245
def test_status(self):
223
246
wt = self._make_mixed_case_tree()
224
247
self.run_bzr('add')
229
CamelCaseParent/CamelCase
231
lowercaseparent/lowercase
233
'status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE')
249
$ bzr status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
252
CamelCaseParent/CamelCase
254
lowercaseparent/lowercase
235
257
def test_ci(self):
236
258
wt = self._make_mixed_case_tree()