/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_add.py

  • Committer: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
#
17
17
 
18
 
"""Tests of the 'brz add' command."""
 
18
"""Tests of the 'bzr add' command."""
19
19
 
20
20
import os
21
21
 
22
 
from breezy import (
 
22
from bzrlib import (
23
23
    osutils,
24
24
    tests,
25
25
    )
26
 
from breezy.tests import (
27
 
    features,
28
 
    script,
29
 
    )
30
 
from breezy.tests.scenarios import load_tests_apply_scenarios
31
 
 
32
 
 
33
 
load_tests = load_tests_apply_scenarios
34
 
 
35
 
 
36
 
class TestAdd(tests.TestCaseWithTransport):
37
 
 
 
26
 
 
27
 
 
28
def load_tests(standard_tests, module, loader):
 
29
    """Parameterize tests for view-aware vs not."""
 
30
    to_adapt, result = tests.split_suite_by_condition(
 
31
        standard_tests, tests.condition_isinstance(TestAdd))
38
32
    scenarios = [
39
33
        ('pre-views', {'branch_tree_format': 'pack-0.92'}),
40
 
        ('view-aware', {'branch_tree_format': '2a'}),
 
34
        ('view-aware', {'branch_tree_format': 'development6-rich-root'}),
41
35
        ]
 
36
    return tests.multiply_tests(to_adapt, scenarios, result)
 
37
 
 
38
 
 
39
class TestAdd(tests.TestCaseWithTransport):
42
40
 
43
41
    def make_branch_and_tree(self, dir):
44
42
        return super(TestAdd, self).make_branch_and_tree(
48
46
        """add command prints the names of added files."""
49
47
        tree = self.make_branch_and_tree('.')
50
48
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
51
 
        self.build_tree_contents([('.bzrignore', b'CVS\n')])
 
49
        self.build_tree_contents([('.bzrignore', 'CVS\n')])
52
50
        out = self.run_bzr('add')[0]
53
51
        # the ordering is not defined at the moment
54
52
        results = sorted(out.rstrip('\n').split('\n'))
55
 
        self.assertEqual(['adding .bzrignore',
56
 
                          'adding dir',
57
 
                          'adding dir/sub.txt',
58
 
                          'adding top.txt'],
59
 
                         results)
 
53
        self.assertEquals(['adding .bzrignore',
 
54
                           'adding dir',
 
55
                           'adding dir/sub.txt',
 
56
                           'adding top.txt'],
 
57
                          results)
60
58
        out = self.run_bzr('add -v')[0]
61
59
        results = sorted(out.rstrip('\n').split('\n'))
62
 
        self.assertEqual(['ignored CVS matching "CVS"'],
63
 
                         results)
 
60
        self.assertEquals(['ignored CVS matching "CVS"'],
 
61
                          results)
64
62
 
65
63
    def test_add_quiet_is(self):
66
64
        """add -q does not print the names of added files."""
69
67
        out = self.run_bzr('add -q')[0]
70
68
        # the ordering is not defined at the moment
71
69
        results = sorted(out.rstrip('\n').split('\n'))
72
 
        self.assertEqual([''], results)
 
70
        self.assertEquals([''], results)
73
71
 
74
72
    def test_add_in_unversioned(self):
75
73
        """Try to add a file in an unversioned directory.
76
74
 
77
 
        "brz add" should add the parent(s) as necessary.
 
75
        "bzr add" should add the parent(s) as necessary.
78
76
        """
79
77
        tree = self.make_branch_and_tree('.')
80
78
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
81
 
        self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic\n')
 
79
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
82
80
        self.run_bzr('add inertiatic/esp')
83
 
        self.assertEqual(self.run_bzr('unknowns')[0], '')
 
81
        self.assertEquals(self.run_bzr('unknowns')[0], '')
84
82
 
85
83
        # Multiple unversioned parents
86
84
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
87
 
        self.assertEqual(self.run_bzr('unknowns')[0], 'veil\n')
 
85
        self.assertEquals(self.run_bzr('unknowns')[0], 'veil\n')
88
86
        self.run_bzr('add veil/cerpin/taxt')
89
 
        self.assertEqual(self.run_bzr('unknowns')[0], '')
 
87
        self.assertEquals(self.run_bzr('unknowns')[0], '')
90
88
 
91
89
        # Check whacky paths work
92
90
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
93
 
        self.assertEqual(self.run_bzr('unknowns')[0], 'cicatriz\n')
 
91
        self.assertEquals(self.run_bzr('unknowns')[0], 'cicatriz\n')
94
92
        self.run_bzr('add inertiatic/../cicatriz/esp')
95
 
        self.assertEqual(self.run_bzr('unknowns')[0], '')
96
 
 
97
 
    def test_add_no_recurse(self):
98
 
        tree = self.make_branch_and_tree('.')
99
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
100
 
        self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic\n')
101
 
        self.run_bzr('add -N inertiatic')
102
 
        self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
 
93
        self.assertEquals(self.run_bzr('unknowns')[0], '')
103
94
 
104
95
    def test_add_in_versioned(self):
105
96
        """Try to add a file in a versioned directory.
106
97
 
107
 
        "brz add" should do this happily.
 
98
        "bzr add" should do this happily.
108
99
        """
109
100
        tree = self.make_branch_and_tree('.')
110
101
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
111
 
        self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic\n')
 
102
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
112
103
        self.run_bzr('add --no-recurse inertiatic')
113
 
        self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
 
104
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
114
105
        self.run_bzr('add inertiatic/esp')
115
 
        self.assertEqual(self.run_bzr('unknowns')[0], '')
 
106
        self.assertEquals(self.run_bzr('unknowns')[0], '')
116
107
 
117
108
    def test_subdir_add(self):
118
109
        """Add in subdirectory should add only things from there down"""
 
110
        from bzrlib.workingtree import WorkingTree
 
111
 
119
112
        eq = self.assertEqual
120
113
        ass = self.assertTrue
121
114
 
133
126
        # add with no arguments in a subdirectory gets only files below that
134
127
        # subdirectory
135
128
        self.run_bzr('add', working_dir='src')
136
 
        self.assertEqual('README\n',
137
 
                         self.run_bzr('unknowns', working_dir='src')[0])
 
129
        self.assertEquals('README\n',
 
130
                          self.run_bzr('unknowns', working_dir='src')[0])
138
131
        # reopen to see the new changes
139
 
        t = t.controldir.open_workingtree('src')
 
132
        t = t.bzrdir.open_workingtree('src')
140
133
        versioned = [path for path, entry in t.iter_entries_by_dir()]
141
 
        self.assertEqual(versioned, ['', 'src', 'src/foo.c'])
 
134
        self.assertEquals(versioned, ['', 'src', 'src/foo.c'])
142
135
 
143
136
        # add from the parent directory should pick up all file names
144
137
        self.run_bzr('add')
145
 
        self.assertEqual(self.run_bzr('unknowns')[0], '')
 
138
        self.assertEquals(self.run_bzr('unknowns')[0], '')
146
139
        self.run_bzr('check')
147
140
 
148
141
    def test_add_missing(self):
149
 
        """brz add foo where foo is missing should error."""
 
142
        """bzr add foo where foo is missing should error."""
150
143
        self.make_branch_and_tree('.')
151
144
        self.run_bzr('add missing-file', retcode=3)
152
145
 
159
152
        new_tree = self.make_branch_and_tree('new')
160
153
        self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
161
154
 
162
 
        out, err = self.run_bzr('add --file-ids-from ../base',
163
 
                                working_dir='new')
 
155
        os.chdir('new')
 
156
        out, err = self.run_bzr('add --file-ids-from ../base')
164
157
        self.assertEqual('', err)
165
158
        self.assertEqualDiff('adding a w/ file id from a\n'
166
159
                             'adding b w/ file id from b\n'
167
160
                             'adding b/c w/ file id from b/c\n',
168
161
                             out)
169
 
        new_tree = new_tree.controldir.open_workingtree()
 
162
        new_tree = new_tree.bzrdir.open_workingtree()
170
163
        self.assertEqual(base_tree.path2id('a'), new_tree.path2id('a'))
171
164
        self.assertEqual(base_tree.path2id('b'), new_tree.path2id('b'))
172
165
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('b/c'))
180
173
        new_tree = self.make_branch_and_tree('new')
181
174
        self.build_tree(['new/c', 'new/d'])
182
175
 
183
 
        out, err = self.run_bzr('add --file-ids-from ../base/b',
184
 
                                working_dir='new')
 
176
        os.chdir('new')
 
177
        out, err = self.run_bzr('add --file-ids-from ../base/b')
185
178
        self.assertEqual('', err)
186
179
        self.assertEqualDiff('adding c w/ file id from b/c\n'
187
180
                             'adding d w/ file id from b/d\n',
188
181
                             out)
189
182
 
190
 
        new_tree = new_tree.controldir.open_workingtree('new')
 
183
        new_tree = new_tree.bzrdir.open_workingtree()
191
184
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
192
185
        self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
193
186
 
211
204
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
212
205
 
213
206
    def test_add_via_symlink(self):
214
 
        self.requireFeature(features.SymlinkFeature)
 
207
        self.requireFeature(tests.SymlinkFeature)
215
208
        self.make_branch_and_tree('source')
216
209
        self.build_tree(['source/top.txt'])
217
210
        os.symlink('source', 'link')
218
211
        out = self.run_bzr(['add', 'link/top.txt'])[0]
219
 
        self.assertEqual(out, 'adding top.txt\n')
 
212
        self.assertEquals(out, 'adding top.txt\n')
220
213
 
221
214
    def test_add_symlink_to_abspath(self):
222
 
        self.requireFeature(features.SymlinkFeature)
 
215
        self.requireFeature(tests.SymlinkFeature)
223
216
        self.make_branch_and_tree('tree')
224
217
        os.symlink(osutils.abspath('target'), 'tree/link')
225
218
        out = self.run_bzr(['add', 'tree/link'])[0]
226
 
        self.assertEqual(out, 'adding link\n')
227
 
 
228
 
    def test_add_not_child(self):
229
 
        # https://bugs.launchpad.net/bzr/+bug/98735
230
 
        sr = script.ScriptRunner()
231
 
        self.make_branch_and_tree('tree1')
232
 
        self.make_branch_and_tree('tree2')
233
 
        self.build_tree(['tree1/a', 'tree2/b'])
234
 
        sr.run_script(self, '''
235
 
        $ brz add tree1/a tree2/b
236
 
        2>brz: ERROR: Path "...tree2/b" is not a child of path "...tree1"
237
 
        ''')
238
 
 
239
 
    def test_add_multiple_files_in_unicode_cwd(self):
240
 
        """Adding multiple files in a non-ascii cwd, see lp:686611"""
241
 
        self.requireFeature(features.UnicodeFilenameFeature)
242
 
        self.make_branch_and_tree(u"\xA7")
243
 
        self.build_tree([u"\xA7/a", u"\xA7/b"])
244
 
        out, err = self.run_bzr(["add", "a", "b"], working_dir=u"\xA7")
245
 
        self.assertEqual(out, "adding a\n" "adding b\n")
246
 
        self.assertEqual(err, "")
247
 
 
248
 
    def test_add_skip_large_files(self):
249
 
        """Test skipping files larger than add.maximum_file_size"""
250
 
        tree = self.make_branch_and_tree('.')
251
 
        self.build_tree(['small.txt', 'big.txt', 'big2.txt'])
252
 
        self.build_tree_contents([('small.txt', b'0\n')])
253
 
        self.build_tree_contents([('big.txt', b'01234567890123456789\n')])
254
 
        self.build_tree_contents([('big2.txt', b'01234567890123456789\n')])
255
 
        tree.branch.get_config_stack().set('add.maximum_file_size', 5)
256
 
        out = self.run_bzr('add')[0]
257
 
        results = sorted(out.rstrip('\n').split('\n'))
258
 
        self.assertEqual(['adding small.txt'], results)
259
 
        # named items never skipped, even if over max
260
 
        out, err = self.run_bzr(["add", "big2.txt"])
261
 
        results = sorted(out.rstrip('\n').split('\n'))
262
 
        self.assertEqual(['adding big2.txt'], results)
263
 
        self.assertEqual("", err)
264
 
        tree.branch.get_config_stack().set('add.maximum_file_size', 30)
265
 
        out = self.run_bzr('add')[0]
266
 
        results = sorted(out.rstrip('\n').split('\n'))
267
 
        self.assertEqual(['adding big.txt'], results)
268
 
 
269
 
    def test_add_backslash(self):
270
 
        # pad.lv/165151
271
 
        if os.path.sep == '\\':
272
 
            # TODO(jelmer): Test that backslashes are appropriately
273
 
            # ignored?
274
 
            raise tests.TestNotApplicable(
275
 
                'unable to add filenames with backslashes where '
276
 
                ' it is the path separator')
277
 
        tree = self.make_branch_and_tree('.')
278
 
        self.build_tree(['\\'])
279
 
        self.assertEqual('adding \\\n', self.run_bzr('add \\\\')[0])
280
 
        self.assertEqual('\\\n', self.run_bzr('ls --versioned')[0])
 
219
        self.assertEquals(out, 'adding link\n')