~bzr-pqm/bzr/bzr.dev

2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
#
17
18
"""Tests of the 'bzr add' command."""
19
20
import os
21
22
from bzrlib.tests.blackbox import ExternalBase
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
23
from bzrlib.tests.test_win32utils import NeedsGlobExpansionFeature
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
24
25
26
class TestAdd(ExternalBase):
27
        
28
    def test_add_reports(self):
29
        """add command prints the names of added files."""
2664.3.1 by Daniel Watkins
tests.blackbox.test_add now uses internals where appropriate.
30
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
31
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
1765.1.1 by Robert Collins
Remove the default ignores list from bzr, lowering the minimum overhead in bzr add.
32
        self.build_tree_contents([('.bzrignore', 'CVS\n')])
2581.1.2 by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls
33
        out = self.run_bzr('add')[0]
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
34
        # the ordering is not defined at the moment
35
        results = sorted(out.rstrip('\n').split('\n'))
36
        self.assertEquals(['If you wish to add some of these files, please'\
37
                           ' add them by name.',
1765.1.1 by Robert Collins
Remove the default ignores list from bzr, lowering the minimum overhead in bzr add.
38
                           'added .bzrignore',
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
39
                           'added dir',
40
                           'added dir/sub.txt',
41
                           'added top.txt',
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
42
                           'ignored 1 file(s).'],
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
43
                          results)
2581.1.2 by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls
44
        out = self.run_bzr('add -v')[0]
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
45
        results = sorted(out.rstrip('\n').split('\n'))
46
        self.assertEquals(['If you wish to add some of these files, please'\
47
                           ' add them by name.',
48
                           'ignored CVS matching "CVS"'],
49
                          results)
50
51
    def test_add_quiet_is(self):
52
        """add -q does not print the names of added files."""
2664.3.1 by Daniel Watkins
tests.blackbox.test_add now uses internals where appropriate.
53
        tree = self.make_branch_and_tree('.') 
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
54
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
2581.1.2 by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls
55
        out = self.run_bzr('add -q')[0]
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
56
        # the ordering is not defined at the moment
57
        results = sorted(out.rstrip('\n').split('\n'))
58
        self.assertEquals([''], results)
59
60
    def test_add_in_unversioned(self):
61
        """Try to add a file in an unversioned directory.
62
63
        "bzr add" should add the parent(s) as necessary.
64
        """
2664.3.1 by Daniel Watkins
tests.blackbox.test_add now uses internals where appropriate.
65
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
66
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
67
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
68
        self.run_bzr('add inertiatic/esp')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
69
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
70
71
        # Multiple unversioned parents
72
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
73
        self.assertEquals(self.run_bzr('unknowns')[0], 'veil\n')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
74
        self.run_bzr('add veil/cerpin/taxt')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
75
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
76
77
        # Check whacky paths work
78
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
79
        self.assertEquals(self.run_bzr('unknowns')[0], 'cicatriz\n')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
80
        self.run_bzr('add inertiatic/../cicatriz/esp')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
81
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
82
83
    def test_add_in_versioned(self):
84
        """Try to add a file in a versioned directory.
85
86
        "bzr add" should do this happily.
87
        """
2664.3.1 by Daniel Watkins
tests.blackbox.test_add now uses internals where appropriate.
88
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
89
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
90
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
91
        self.run_bzr('add --no-recurse inertiatic')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
92
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
93
        self.run_bzr('add inertiatic/esp')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
94
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
95
96
    def test_subdir_add(self):
97
        """Add in subdirectory should add only things from there down"""
98
        from bzrlib.workingtree import WorkingTree
1836.1.16 by John Arbash Meinel
Cleanup some tests which don't expect .bazaar/ to show up. Some still fail.
99
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
100
        eq = self.assertEqual
1836.1.16 by John Arbash Meinel
Cleanup some tests which don't expect .bazaar/ to show up. Some still fail.
101
        ass = self.assertTrue
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
102
        chdir = os.chdir
103
        
104
        t = self.make_branch_and_tree('.')
105
        b = t.branch
106
        self.build_tree(['src/', 'README'])
107
        
108
        eq(sorted(t.unknowns()),
109
           ['README', 'src'])
110
        
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
111
        self.run_bzr('add src')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
112
        
113
        self.build_tree(['src/foo.c'])
114
        
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
115
        # add with no arguments in a subdirectory gets only files below that
116
        # subdirectory
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
117
        chdir('src')
118
        self.run_bzr('add')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
119
        self.assertEquals(self.run_bzr('unknowns')[0], 'README\n')
2255.2.176 by Martin Pool
Merge dirstate and some small cleanups
120
        # reopen to see the new changes
121
        t = t.bzrdir.open_workingtree()
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
122
        versioned = [path for path, entry in t.iter_entries_by_dir()]
123
        self.assertEquals(versioned,
124
            ['', 'src', 'src/foo.c'])
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
125
                
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
126
        # add from the parent directory should pick up all file names
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
127
        chdir('..')
128
        self.run_bzr('add')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
129
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
130
        self.run_bzr('check')
1757.2.1 by Robert Collins
Add an explicit test that adding a missing file barfs.
131
132
    def test_add_missing(self):
133
        """bzr add foo where foo is missing should error."""
134
        self.make_branch_and_tree('.')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
135
        self.run_bzr('add missing-file', retcode=3)
1911.3.2 by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree
136
137
    def test_add_from(self):
138
        base_tree = self.make_branch_and_tree('base')
139
        self.build_tree(['base/a', 'base/b/', 'base/b/c'])
140
        base_tree.add(['a', 'b', 'b/c'])
141
        base_tree.commit('foo')
142
143
        new_tree = self.make_branch_and_tree('new')
144
        self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
145
146
        os.chdir('new')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
147
        out, err = self.run_bzr('add --file-ids-from ../base')
1911.3.2 by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree
148
        self.assertEqual('', err)
149
        self.assertEqualDiff('added a w/ file id from a\n'
150
                             'added b w/ file id from b\n'
151
                             'added b/c w/ file id from b/c\n',
152
                             out)
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
153
        new_tree = new_tree.bzrdir.open_workingtree()
1911.3.2 by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree
154
        self.assertEqual(base_tree.path2id('a'), new_tree.path2id('a'))
155
        self.assertEqual(base_tree.path2id('b'), new_tree.path2id('b'))
156
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('b/c'))
157
158
    def test_add_from_subdir(self):
159
        base_tree = self.make_branch_and_tree('base')
160
        self.build_tree(['base/a', 'base/b/', 'base/b/c', 'base/b/d'])
161
        base_tree.add(['a', 'b', 'b/c', 'b/d'])
162
        base_tree.commit('foo')
163
164
        new_tree = self.make_branch_and_tree('new')
165
        self.build_tree(['new/c', 'new/d'])
166
167
        os.chdir('new')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
168
        out, err = self.run_bzr('add --file-ids-from ../base/b')
1911.3.2 by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree
169
        self.assertEqual('', err)
170
        self.assertEqualDiff('added c w/ file id from b/c\n'
171
                             'added d w/ file id from b/d\n',
172
                             out)
173
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
174
        new_tree = new_tree.bzrdir.open_workingtree()
1911.3.2 by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree
175
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
176
        self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
1928.1.1 by Alexander Belchenko
blackbox test for 'bzr add --dry-run'
177
178
    def test_add_dry_run(self):
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
179
        """Test a dry run add, make sure nothing is added."""
180
        wt = self.make_branch_and_tree('.')
181
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
182
        self.assertEqual(list(wt.unknowns()), ['inertiatic'])
183
        self.run_bzr('add --dry-run')
184
        self.assertEqual(list(wt.unknowns()), ['inertiatic'])
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
185
186
    def test_add_control_dir(self):
187
        """The control dir and its content should be refused."""
2279.6.1 by Alexander Belchenko
Instead of __str__ method for FastPath object we use .raw_path attribute (note from Aaron).
188
        self.make_branch_and_tree('.')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
189
        err = self.run_bzr('add .bzr', retcode=3)[1]
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
190
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
191
        err = self.run_bzr('add .bzr/README', retcode=3)[1]
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
192
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
193
        self.build_tree(['.bzr/crescent'])
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
194
        err = self.run_bzr('add .bzr/crescent', retcode=3)[1]
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
195
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
2617.5.3 by Kuno Meyer
Blackbox test for adding with wildcards (Win32).
196
197
    def test_add_with_wildcards(self):
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
198
        self.requireFeature(NeedsGlobExpansionFeature)
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
199
        self.make_branch_and_tree('.')
2617.5.3 by Kuno Meyer
Blackbox test for adding with wildcards (Win32).
200
        self.build_tree(['a1', 'a2', 'b', 'c33'])
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
201
        self.run_bzr(['add', 'a?', 'c*'])
2617.5.3 by Kuno Meyer
Blackbox test for adding with wildcards (Win32).
202
        self.assertEquals(self.run_bzr('unknowns')[0], 'b\n')
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
203
204
    def test_add_with_wildcards_unicode(self):
205
        self.requireFeature(NeedsGlobExpansionFeature)
206
        self.make_branch_and_tree('.')
207
        self.build_tree([u'\u1234A', u'\u1235A', u'\u1235AA', 'cc'])
208
        self.run_bzr(['add', u'\u1234?', u'\u1235*'])
209
        self.assertEquals(self.run_bzr('unknowns')[0], 'cc\n')