~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 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 import (
23
 
    osutils,
24
 
    tests,
25
 
    )
26
 
from bzrlib.tests import KnownFailure
27
 
from bzrlib.osutils import canonical_relpath, pathjoin
28
 
from bzrlib.tests.script import run_script
29
 
from bzrlib.tests.features import (
30
 
    CaseInsCasePresFilenameFeature,
31
 
    )
32
 
 
33
 
 
34
 
 
35
 
class TestCICPBase(tests.TestCaseWithTransport):
36
 
    """Base class for tests on a case-insensitive, case-preserving filesystem.
37
 
    """
38
 
 
39
 
    _test_needs_features = [CaseInsCasePresFilenameFeature]
40
 
 
41
 
    def _make_mixed_case_tree(self):
42
 
        """Make a working tree with mixed-case filenames."""
43
 
        wt = self.make_branch_and_tree('.')
44
 
        # create a file on disk with the mixed-case parent and base name
45
 
        self.build_tree(['CamelCaseParent/', 'lowercaseparent/'])
46
 
        self.build_tree_contents([('CamelCaseParent/CamelCase', 'camel case'),
47
 
                                  ('lowercaseparent/lowercase', 'lower case'),
48
 
                                  ('lowercaseparent/mixedCase', 'mixedCasecase'),
49
 
                                 ])
50
 
        return wt
51
 
 
52
 
 
53
 
class TestAdd(TestCICPBase):
54
 
 
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'])
60
 
        run_script(self, """
61
 
            $ bzr add camelcase
62
 
            adding CamelCase
63
 
            """)
64
 
 
65
 
    def test_add_subdir(self):
66
 
        """test_add_simple but with subdirectories tested too."""
67
 
        wt = self.make_branch_and_tree('.')
68
 
        # create a file on disk with the mixed-case parent and base name
69
 
        self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase'])
70
 
        run_script(self, """
71
 
            $ bzr add camelcaseparent/camelcase
72
 
            adding CamelCaseParent
73
 
            adding CamelCaseParent/CamelCase
74
 
            """)
75
 
 
76
 
    def test_add_implied(self):
77
 
        """test add with no args sees the correct names."""
78
 
        wt = self.make_branch_and_tree('.')
79
 
        # create a file on disk with the mixed-case parent and base name
80
 
        self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase'])
81
 
        run_script(self, """
82
 
            $ bzr add
83
 
            adding CamelCaseParent
84
 
            adding CamelCaseParent/CamelCase
85
 
            """)
86
 
 
87
 
    def test_re_add(self):
88
 
        """Test than when a file has 'unintentionally' changed case, we can't
89
 
        add a new entry using the new case."""
90
 
        wt = self.make_branch_and_tree('.')
91
 
        # create a file on disk with the mixed-case name
92
 
        self.build_tree(['MixedCase'])
93
 
        run_script(self, """
94
 
            $ bzr add MixedCase
95
 
            adding MixedCase
96
 
            """)
97
 
        # 'accidently' rename the file on disk
98
 
        osutils.rename('MixedCase', 'mixedcase')
99
 
        run_script(self, """
100
 
            $ bzr add mixedcase
101
 
            """)
102
 
 
103
 
    def test_re_add_dir(self):
104
 
        # like re-add, but tests when the operation is on a directory.
105
 
        """Test than when a file has 'unintentionally' changed case, we can't
106
 
        add a new entry using the new case."""
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
 
        run_script(self, """
111
 
            $ bzr add MixedCaseParent
112
 
            adding MixedCaseParent
113
 
            adding MixedCaseParent/MixedCase
114
 
            """)
115
 
        # 'accidently' rename the directory on disk
116
 
        osutils.rename('MixedCaseParent', 'mixedcaseparent')
117
 
        run_script(self, """
118
 
            $ bzr add mixedcaseparent
119
 
            """)
120
 
 
121
 
    def test_add_not_found(self):
122
 
        """Test add when the input file doesn't exist."""
123
 
        wt = self.make_branch_and_tree('.')
124
 
        # create a file on disk with the mixed-case name
125
 
        self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase'])
126
 
        expected_fname = pathjoin(wt.basedir, "MixedCaseParent", "notfound")
127
 
        run_script(self, """
128
 
            $ bzr add mixedcaseparent/notfound
129
 
            2>bzr: ERROR: No such file: %s
130
 
            """ % (repr(expected_fname),))
131
 
 
132
 
 
133
 
class TestMove(TestCICPBase):
134
 
 
135
 
    def test_mv_newname(self):
136
 
        wt = self._make_mixed_case_tree()
137
 
        run_script(self, """
138
 
            $ bzr add -q
139
 
            $ bzr ci -qm message
140
 
            $ bzr mv camelcaseparent/camelcase camelcaseparent/NewCamelCase
141
 
            CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase
142
 
            """)
143
 
 
144
 
    def test_mv_newname_after(self):
145
 
        wt = self._make_mixed_case_tree()
146
 
        # In this case we can specify the incorrect case for the destination,
147
 
        # as we use --after, so the file-system is sniffed.
148
 
        run_script(self, """
149
 
            $ bzr add -q
150
 
            $ bzr ci -qm message
151
 
            $ mv CamelCaseParent/CamelCase CamelCaseParent/NewCamelCase
152
 
            $ bzr mv --after camelcaseparent/camelcase camelcaseparent/newcamelcase
153
 
            CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase
154
 
            """)
155
 
 
156
 
    def test_mv_newname_exists(self):
157
 
        # test a mv, but when the target already exists with a name that
158
 
        # differs only by case.
159
 
        wt = self._make_mixed_case_tree()
160
 
        self.run_bzr('add')
161
 
        self.run_bzr('ci -m message')
162
 
        run_script(self, """
163
 
            $ bzr mv camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
164
 
            2>bzr: ERROR: Could not move CamelCase => lowercase: \
165
 
lowercaseparent/lowercase is already versioned.
166
 
            """)
167
 
 
168
 
    def test_mv_newname_exists_after(self):
169
 
        # test a 'mv --after', but when the target already exists with a name
170
 
        # that differs only by case.  Note that this is somewhat unlikely
171
 
        # but still reasonable.
172
 
        wt = self._make_mixed_case_tree()
173
 
        self.run_bzr('add')
174
 
        self.run_bzr('ci -m message')
175
 
        # Remove the source and create a destination file on disk with a different case.
176
 
        # bzr should report that the filename is already versioned.
177
 
        os.unlink('CamelCaseParent/CamelCase')
178
 
        osutils.rename('lowercaseparent/lowercase', 'lowercaseparent/LOWERCASE')
179
 
        run_script(self, """
180
 
            $ bzr mv --after camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
181
 
            2>bzr: ERROR: Could not move CamelCase => lowercase: \
182
 
lowercaseparent/lowercase is already versioned.
183
 
            """)
184
 
 
185
 
    def test_mv_newname_root(self):
186
 
        wt = self._make_mixed_case_tree()
187
 
        self.run_bzr('add')
188
 
        self.run_bzr('ci -m message')
189
 
        run_script(self, """
190
 
            $ bzr mv camelcaseparent NewCamelCaseParent
191
 
            CamelCaseParent => NewCamelCaseParent
192
 
            """)
193
 
 
194
 
    def test_mv_newname_root_after(self):
195
 
        wt = self._make_mixed_case_tree()
196
 
        self.run_bzr('add')
197
 
        self.run_bzr('ci -m message')
198
 
        # In this case we can specify the incorrect case for the destination,
199
 
        # as we use --after, so the file-system is sniffed.
200
 
        run_script(self, """
201
 
            $ mv CamelCaseParent NewCamelCaseParent
202
 
            $ bzr mv --after camelcaseparent NewCamelCaseParent
203
 
            CamelCaseParent => NewCamelCaseParent
204
 
            """)
205
 
 
206
 
    def test_mv_newcase(self):
207
 
        wt = self._make_mixed_case_tree()
208
 
        self.run_bzr('add')
209
 
        self.run_bzr('ci -m message')
210
 
 
211
 
        # perform a mv to the new case - we expect bzr to accept the new
212
 
        # name, as specified, and rename the file on the file-system too.
213
 
        run_script(self, """
214
 
            $ bzr mv camelcaseparent/camelcase camelcaseparent/camelCase
215
 
            CamelCaseParent/CamelCase => CamelCaseParent/camelCase
216
 
            """)
217
 
        self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
218
 
                             'CamelCaseParent/camelCase')
219
 
 
220
 
    def test_mv_newcase_after(self):
221
 
        wt = self._make_mixed_case_tree()
222
 
        self.run_bzr('add')
223
 
        self.run_bzr('ci -m message')
224
 
 
225
 
        # perform a mv to the new case - we must ensure the file-system has the
226
 
        # new case first.
227
 
        osutils.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/camelCase')
228
 
        run_script(self, """
229
 
            $ bzr mv --after camelcaseparent/camelcase camelcaseparent/camelCase
230
 
            CamelCaseParent/CamelCase => CamelCaseParent/camelCase
231
 
            """)
232
 
        # bzr should not have renamed the file to a different case
233
 
        self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
234
 
                             'CamelCaseParent/camelCase')
235
 
 
236
 
    def test_mv_multiple(self):
237
 
        wt = self._make_mixed_case_tree()
238
 
        self.run_bzr('add')
239
 
        self.run_bzr('ci -m message')
240
 
        run_script(self, """
241
 
            $ bzr mv LOWercaseparent/LOWercase LOWercaseparent/MIXEDCase camelcaseparent
242
 
            lowercaseparent/lowercase => CamelCaseParent/lowercase
243
 
            lowercaseparent/mixedCase => CamelCaseParent/mixedCase
244
 
            """)
245
 
 
246
 
 
247
 
class TestMisc(TestCICPBase):
248
 
 
249
 
    def test_status(self):
250
 
        wt = self._make_mixed_case_tree()
251
 
        self.run_bzr('add')
252
 
        run_script(self, """
253
 
            $ bzr status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
254
 
            added:
255
 
              CamelCaseParent/
256
 
              CamelCaseParent/CamelCase
257
 
              lowercaseparent/
258
 
              lowercaseparent/lowercase
259
 
            """)
260
 
 
261
 
    def test_ci(self):
262
 
        wt = self._make_mixed_case_tree()
263
 
        self.run_bzr('add')
264
 
 
265
 
        got = self.run_bzr('ci -m message camelcaseparent LOWERCASEPARENT')[1]
266
 
        for expected in ['CamelCaseParent', 'lowercaseparent',
267
 
                         'CamelCaseParent/CamelCase', 'lowercaseparent/lowercase']:
268
 
            self.assertContainsRe(got, 'added ' + expected + '\n')
269
 
 
270
 
    def test_rm(self):
271
 
        wt = self._make_mixed_case_tree()
272
 
        self.run_bzr('add')
273
 
        self.run_bzr('ci -m message')
274
 
 
275
 
        got = self.run_bzr('rm camelcaseparent LOWERCASEPARENT')[1]
276
 
        for expected in ['lowercaseparent/lowercase', 'CamelCaseParent/CamelCase']:
277
 
            self.assertContainsRe(got, 'deleted ' + expected + '\n')
278
 
 
279
 
 
280
 
    # The following commands need tests and/or cicp lovin':
281
 
    # update, remove, file_id, file_path, diff, log, touching_revisions, ls,
282
 
    # ignore, cat, revert, resolve.