~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge cleanup into first-try

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2010 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
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
19
19
 
20
20
import os
21
21
 
22
 
from bzrlib import (osutils,
 
22
from bzrlib import (
 
23
    osutils,
 
24
    tests,
23
25
    )
24
 
from bzrlib.tests.blackbox import ExternalBase
25
26
from bzrlib.tests import CaseInsCasePresFilenameFeature, KnownFailure
26
27
from bzrlib.osutils import canonical_relpath, pathjoin
27
 
 
28
 
class TestCICPBase(ExternalBase):
 
28
from bzrlib.tests.script import run_script
 
29
 
 
30
 
 
31
class TestCICPBase(tests.TestCaseWithTransport):
29
32
    """Base class for tests on a case-insensitive, case-preserving filesystem.
30
33
    """
31
34
 
42
45
                                 ])
43
46
        return wt
44
47
 
45
 
    def check_error_output(self, retcode, output, *args):
46
 
        got = self.run_bzr(retcode=retcode, *args)[1]
47
 
        self.failUnlessEqual(got, output)
48
 
 
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)
52
 
        self.failIf(out)
53
 
        self.failIf(err)
54
 
 
55
48
 
56
49
class TestAdd(TestCICPBase):
57
50
 
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'])
63
 
 
64
 
        self.check_output('adding CamelCase\n', 'add camelcase')
 
56
        run_script(self, """
 
57
            $ bzr add camelcase
 
58
            adding CamelCase
 
59
            """)
65
60
 
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'])
71
 
 
72
 
        self.check_output('adding CamelCaseParent\n'
73
 
                          'adding CamelCaseParent/CamelCase\n',
74
 
                          'add camelcaseparent/camelcase')
 
66
        run_script(self, """
 
67
            $ bzr add camelcaseparent/camelcase
 
68
            adding CamelCaseParent
 
69
            adding CamelCaseParent/CamelCase
 
70
            """)
75
71
 
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'])
81
 
 
82
 
        self.check_output('adding CamelCaseParent\n'
83
 
                          'adding CamelCaseParent/CamelCase\n',
84
 
                          'add')
 
77
        run_script(self, """
 
78
            $ bzr add
 
79
            adding CamelCaseParent
 
80
            adding CamelCaseParent/CamelCase
 
81
            """)
85
82
 
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')
 
89
        run_script(self, """
 
90
            $ bzr add MixedCase
 
91
            adding MixedCase
 
92
            """)
93
93
        # 'accidently' rename the file on disk
94
94
        osutils.rename('MixedCase', 'mixedcase')
95
 
        self.check_empty_output('add mixedcase')
 
95
        run_script(self, """
 
96
            $ bzr add mixedcase
 
97
            """)
96
98
 
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')
 
106
        run_script(self, """
 
107
            $ bzr add MixedCaseParent
 
108
            adding MixedCaseParent
 
109
            adding MixedCaseParent/MixedCase
 
110
            """)
107
111
        # 'accidently' rename the directory on disk
108
112
        osutils.rename('MixedCaseParent', 'mixedcaseparent')
109
 
        self.check_empty_output('add mixedcaseparent')
 
113
        run_script(self, """
 
114
            $ bzr add mixedcaseparent
 
115
            """)
110
116
 
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')
 
123
        run_script(self, """
 
124
            $ bzr add mixedcaseparent/notfound
 
125
            2>bzr: ERROR: No such file: %s
 
126
            """ % (repr(expected_fname),))
119
127
 
120
128
 
121
129
class TestMove(TestCICPBase):
 
130
 
122
131
    def test_mv_newname(self):
123
132
        wt = self._make_mixed_case_tree()
124
 
        self.run_bzr('add')
125
 
        self.run_bzr('ci -m message')
126
 
 
127
 
        self.check_output(
128
 
            'CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
129
 
            'mv camelcaseparent/camelcase camelcaseparent/NewCamelCase')
 
133
        run_script(self, """
 
134
            $ bzr add
 
135
            $ bzr ci -m message
 
136
            $ bzr mv camelcaseparent/camelcase camelcaseparent/NewCamelCase
 
137
            CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase
 
138
            """)
130
139
 
131
140
    def test_mv_newname_after(self):
132
141
        wt = self._make_mixed_case_tree()
133
 
        self.run_bzr('add')
134
 
        self.run_bzr('ci -m message')
135
 
        osutils.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/NewCamelCase')
136
 
 
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.
139
 
        self.check_output(
140
 
            'CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
141
 
            'mv --after camelcaseparent/camelcase camelcaseparent/newcamelcase')
 
144
        run_script(self, """
 
145
            $ bzr add 
 
146
            $ bzr ci -m message
 
147
            $ mv CamelCaseParent/CamelCase CamelCaseParent/NewCamelCase
 
148
            $ bzr mv --after camelcaseparent/camelcase camelcaseparent/newcamelcase
 
149
            CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase
 
150
            """)
142
151
 
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')
 
158
        run_script(self, """
 
159
            $ bzr mv camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
 
160
            2>bzr: ERROR: Could not move CamelCase => lowercase: \
 
161
lowercaseparent/lowercase is already versioned.
 
162
            """)
151
163
 
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')
 
175
        run_script(self, """
 
176
            $ bzr mv --after camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
 
177
            2>bzr: ERROR: Could not move CamelCase => lowercase: \
 
178
lowercaseparent/lowercase is already versioned.
 
179
            """)
165
180
 
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')
170
 
 
171
 
        self.check_output('CamelCaseParent => NewCamelCaseParent\n',
172
 
                          'mv camelcaseparent NewCamelCaseParent')
 
185
        run_script(self, """
 
186
            $ bzr mv camelcaseparent NewCamelCaseParent
 
187
            CamelCaseParent => NewCamelCaseParent
 
188
            """)
173
189
 
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')
179
 
 
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')
 
196
        run_script(self, """
 
197
            $ mv CamelCaseParent NewCamelCaseParent
 
198
            $ bzr mv --after camelcaseparent NewCamelCaseParent
 
199
            CamelCaseParent => NewCamelCaseParent
 
200
            """)
184
201
 
185
202
    def test_mv_newcase(self):
186
203
        wt = self._make_mixed_case_tree()
189
206
 
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')
 
209
        run_script(self, """
 
210
            $ bzr mv camelcaseparent/camelcase camelcaseparent/camelCase
 
211
            CamelCaseParent/CamelCase => CamelCaseParent/camelCase
 
212
            """)
194
213
        self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
195
214
                             'CamelCaseParent/camelCase')
196
215
 
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')
 
224
        run_script(self, """
 
225
            $ bzr mv --after camelcaseparent/camelcase camelcaseparent/camelCase
 
226
            CamelCaseParent/CamelCase => CamelCaseParent/camelCase
 
227
            """)
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')
 
236
        run_script(self, """
 
237
            $ bzr mv LOWercaseparent/LOWercase LOWercaseparent/MIXEDCase camelcaseparent
 
238
            lowercaseparent/lowercase => CamelCaseParent/lowercase
 
239
            lowercaseparent/mixedCase => CamelCaseParent/mixedCase
 
240
            """)
218
241
 
219
242
 
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')
225
 
 
226
 
        self.check_output(
227
 
            """added:
228
 
  CamelCaseParent/
229
 
  CamelCaseParent/CamelCase
230
 
  lowercaseparent/
231
 
  lowercaseparent/lowercase
232
 
""",
233
 
            'status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE')
 
248
        run_script(self, """
 
249
            $ bzr status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
 
250
            added:
 
251
              CamelCaseParent/
 
252
              CamelCaseParent/CamelCase
 
253
              lowercaseparent/
 
254
              lowercaseparent/lowercase
 
255
            """)
234
256
 
235
257
    def test_ci(self):
236
258
        wt = self._make_mixed_case_tree()