~bzr/ubuntu/lucid/bzr/beta-ppa

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2010-08-18 04:26:39 UTC
  • mfrom: (129.1.8 packaging-karmic)
  • Revision ID: mbp@sourcefrog.net-20100818042639-mjoxtngyjwiu05fo
* PPA rebuild for lucid.
* PPA rebuild for karmic.
* PPA rebuild onto jaunty.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 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.tests.blackbox import ExternalBase
 
22
from bzrlib import (
 
23
    osutils,
 
24
    tests,
 
25
    )
23
26
from bzrlib.tests import CaseInsCasePresFilenameFeature, KnownFailure
24
27
from bzrlib.osutils import canonical_relpath, pathjoin
25
 
 
26
 
class TestCICPBase(ExternalBase):
 
28
from bzrlib.tests.script import run_script
 
29
 
 
30
 
 
31
class TestCICPBase(tests.TestCaseWithTransport):
27
32
    """Base class for tests on a case-insensitive, case-preserving filesystem.
28
33
    """
29
34
 
40
45
                                 ])
41
46
        return wt
42
47
 
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
48
 
54
49
class TestAdd(TestCICPBase):
55
50
 
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'])
61
 
 
62
 
        self.check_output('adding CamelCase\n', 'add camelcase')
 
56
        run_script(self, """
 
57
            $ bzr add camelcase
 
58
            adding CamelCase
 
59
            """)
63
60
 
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'])
69
 
 
70
 
        self.check_output('adding CamelCaseParent\n'
71
 
                          'adding CamelCaseParent/CamelCase\n',
72
 
                          'add camelcaseparent/camelcase')
 
66
        run_script(self, """
 
67
            $ bzr add camelcaseparent/camelcase
 
68
            adding CamelCaseParent
 
69
            adding CamelCaseParent/CamelCase
 
70
            """)
73
71
 
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'])
79
 
 
80
 
        self.check_output('adding CamelCaseParent\n'
81
 
                          'adding CamelCaseParent/CamelCase\n',
82
 
                          'add')
 
77
        run_script(self, """
 
78
            $ bzr add
 
79
            adding CamelCaseParent
 
80
            adding CamelCaseParent/CamelCase
 
81
            """)
83
82
 
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')
 
89
        run_script(self, """
 
90
            $ bzr add MixedCase
 
91
            adding MixedCase
 
92
            """)
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
        run_script(self, """
 
96
            $ bzr add mixedcase
 
97
            """)
94
98
 
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')
 
106
        run_script(self, """
 
107
            $ bzr add MixedCaseParent
 
108
            adding MixedCaseParent
 
109
            adding MixedCaseParent/MixedCase
 
110
            """)
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')
 
113
        run_script(self, """
 
114
            $ bzr add mixedcaseparent
 
115
            """)
108
116
 
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')
 
123
        run_script(self, """
 
124
            $ bzr add mixedcaseparent/notfound
 
125
            2>bzr: ERROR: No such file: %s
 
126
            """ % (repr(expected_fname),))
117
127
 
118
128
 
119
129
class TestMove(TestCICPBase):
 
130
 
120
131
    def test_mv_newname(self):
121
132
        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')
 
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
            """)
128
139
 
129
140
    def test_mv_newname_after(self):
130
141
        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
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.
137
 
        self.check_output(
138
 
            'CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase\n',
139
 
            '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
            """)
140
151
 
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')
 
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
            """)
149
163
 
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')
 
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
            """)
163
180
 
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')
168
 
 
169
 
        self.check_output('CamelCaseParent => NewCamelCaseParent\n',
170
 
                          'mv camelcaseparent NewCamelCaseParent')
 
185
        run_script(self, """
 
186
            $ bzr mv camelcaseparent NewCamelCaseParent
 
187
            CamelCaseParent => NewCamelCaseParent
 
188
            """)
171
189
 
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')
177
 
 
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')
 
196
        run_script(self, """
 
197
            $ mv CamelCaseParent NewCamelCaseParent
 
198
            $ bzr mv --after camelcaseparent NewCamelCaseParent
 
199
            CamelCaseParent => NewCamelCaseParent
 
200
            """)
182
201
 
183
202
    def test_mv_newcase(self):
184
203
        wt = self._make_mixed_case_tree()
187
206
 
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')
 
209
        run_script(self, """
 
210
            $ bzr mv camelcaseparent/camelcase camelcaseparent/camelCase
 
211
            CamelCaseParent/CamelCase => CamelCaseParent/camelCase
 
212
            """)
192
213
        self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
193
214
                             'CamelCaseParent/camelCase')
194
215
 
199
220
 
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')
 
224
        run_script(self, """
 
225
            $ bzr mv --after camelcaseparent/camelcase camelcaseparent/camelCase
 
226
            CamelCaseParent/CamelCase => CamelCaseParent/camelCase
 
227
            """)
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')
 
236
        run_script(self, """
 
237
            $ bzr mv LOWercaseparent/LOWercase LOWercaseparent/MIXEDCase camelcaseparent
 
238
            lowercaseparent/lowercase => CamelCaseParent/lowercase
 
239
            lowercaseparent/mixedCase => CamelCaseParent/mixedCase
 
240
            """)
216
241
 
217
242
 
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')
223
 
 
224
 
        self.check_output(
225
 
            """added:
226
 
  CamelCaseParent/
227
 
  CamelCaseParent/CamelCase
228
 
  lowercaseparent/
229
 
  lowercaseparent/lowercase
230
 
""",
231
 
            '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
            """)
232
256
 
233
257
    def test_ci(self):
234
258
        wt = self._make_mixed_case_tree()