/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_filesystem_cicp.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
 
24
from bzrlib.osutils import canonical_relpath, pathjoin
 
25
 
 
26
class TestCICPBase(ExternalBase):
 
27
    """Base class for tests on a case-insensitive, case-preserving filesystem.
 
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
 
 
43
    def check_error_output(self, retcode, output, *args):
 
44
        got = self.run_bzr(retcode=retcode, *args)[1]
 
45
        self.failUnlessEqual(got, output)
 
46
 
 
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
 
 
54
class TestAdd(TestCICPBase):
 
55
 
 
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'])
 
61
 
 
62
        self.check_output('adding CamelCase\n', 'add camelcase')
 
63
 
 
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'])
 
69
 
 
70
        self.check_output('adding CamelCaseParent\n'
 
71
                          'adding CamelCaseParent/CamelCase\n',
 
72
                          'add camelcaseparent/camelcase')
 
73
 
 
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'])
 
79
 
 
80
        self.check_output('adding CamelCaseParent\n'
 
81
                          'adding CamelCaseParent/CamelCase\n',
 
82
                          'add')
 
83
 
 
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')
 
94
 
 
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')
 
108
 
 
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')
 
117
 
 
118
 
 
119
class TestMove(TestCICPBase):
 
120
    def test_mv_newname(self):
 
121
        wt = self._make_mixed_case_tree()
 
122
        self.run_bzr('add')
 
123
        self.run_bzr('ci -m message')
 
124
 
 
125
        self.check_output(
 
126
            'CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
 
127
            'mv camelcaseparent/camelcase camelcaseparent/NewCamelCase')
 
128
 
 
129
    def test_mv_newname_after(self):
 
130
        wt = self._make_mixed_case_tree()
 
131
        self.run_bzr('add')
 
132
        self.run_bzr('ci -m message')
 
133
        os.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/NewCamelCase')
 
134
 
 
135
        # In this case we can specify the incorrect case for the destination,
 
136
        # as we use --after, so the file-system is sniffed.
 
137
        self.check_output(
 
138
            'CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
 
139
            'mv --after camelcaseparent/camelcase camelcaseparent/newcamelcase')
 
140
 
 
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()
 
145
        self.run_bzr('add')
 
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')
 
149
 
 
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()
 
155
        self.run_bzr('add')
 
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')
 
163
 
 
164
    def test_mv_newname_root(self):
 
165
        wt = self._make_mixed_case_tree()
 
166
        self.run_bzr('add')
 
167
        self.run_bzr('ci -m message')
 
168
 
 
169
        self.check_output('CamelCaseParent => NewCamelCaseParent\n',
 
170
                          'mv camelcaseparent NewCamelCaseParent')
 
171
 
 
172
    def test_mv_newname_root_after(self):
 
173
        wt = self._make_mixed_case_tree()
 
174
        self.run_bzr('add')
 
175
        self.run_bzr('ci -m message')
 
176
        os.rename('CamelCaseParent', 'NewCamelCaseParent')
 
177
 
 
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')
 
182
 
 
183
    def test_mv_newcase(self):
 
184
        wt = self._make_mixed_case_tree()
 
185
        self.run_bzr('add')
 
186
        self.run_bzr('ci -m message')
 
187
 
 
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')
 
194
 
 
195
    def test_mv_newcase_after(self):
 
196
        wt = self._make_mixed_case_tree()
 
197
        self.run_bzr('add')
 
198
        self.run_bzr('ci -m message')
 
199
 
 
200
        # perform a mv to the new case - we must ensure the file-system has the
 
201
        # 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')
 
205
        # bzr should not have renamed the file to a different case
 
206
        self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
 
207
                             'CamelCaseParent/camelCase')
 
208
 
 
209
    def test_mv_multiple(self):
 
210
        wt = self._make_mixed_case_tree()
 
211
        self.run_bzr('add')
 
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')
 
216
 
 
217
 
 
218
class TestMisc(TestCICPBase):
 
219
 
 
220
    def test_status(self):
 
221
        wt = self._make_mixed_case_tree()
 
222
        self.run_bzr('add')
 
223
 
 
224
        self.check_output(
 
225
            """added:
 
226
  CamelCaseParent/
 
227
  CamelCaseParent/CamelCase
 
228
  lowercaseparent/
 
229
  lowercaseparent/lowercase
 
230
""",
 
231
            'status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE')
 
232
 
 
233
    def test_ci(self):
 
234
        wt = self._make_mixed_case_tree()
 
235
        self.run_bzr('add')
 
236
 
 
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')
 
241
 
 
242
    def test_rm(self):
 
243
        wt = self._make_mixed_case_tree()
 
244
        self.run_bzr('add')
 
245
        self.run_bzr('ci -m message')
 
246
 
 
247
        got = self.run_bzr('rm camelcaseparent LOWERCASEPARENT')[1]
 
248
        for expected in ['lowercaseparent/lowercase', 'CamelCaseParent/CamelCase']:
 
249
            self.assertContainsRe(got, 'deleted ' + expected + '\n')
 
250
 
 
251
 
 
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.