~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""External tests of 'bzr ls'"""
18
18
 
19
19
import os
20
20
 
21
 
from bzrlib import ignores
 
21
from bzrlib import ignores, osutils
22
22
from bzrlib.tests import TestCaseWithTransport
23
23
 
24
24
 
26
26
 
27
27
    def setUp(self):
28
28
        super(TestLS, self).setUp()
29
 
        
 
29
 
30
30
        # Create a simple branch that can be used in testing
31
31
        ignores._set_user_ignores(['user-ignore'])
32
32
 
36
36
                                 ('a', 'hello\n'),
37
37
                                 ])
38
38
 
39
 
    def ls_equals(self, value, args=None):
 
39
    def ls_equals(self, value, args=None, recursive=True):
40
40
        command = 'ls'
41
41
        if args is not None:
42
42
            command += ' ' + args
 
43
        if recursive:
 
44
            command += ' -R'
43
45
        out, err = self.run_bzr(command)
44
46
        self.assertEqual('', err)
45
47
        self.assertEqualDiff(value, out)
52
54
    def test_ls_basic(self):
53
55
        """Test the abilities of 'bzr ls'"""
54
56
        self.ls_equals('.bzrignore\na\n')
 
57
        self.ls_equals('.bzrignore\na\n', './')
55
58
        self.ls_equals('?        .bzrignore\n'
56
59
                       '?        a\n',
57
60
                       '--verbose')
77
80
                       'V        a\n',
78
81
                       '--verbose')
79
82
        self.wt.commit('add')
80
 
        
 
83
 
81
84
        self.build_tree(['subdir/'])
82
85
        self.ls_equals('?        .bzrignore\n'
83
86
                       'V        a\n'
97
100
        self.ls_equals(
98
101
            '.bzrignore                                         \n'
99
102
            'a                                                  a-id\n'
100
 
            'subdir                                             subdir-id\n', 
 
103
            'subdir/                                            subdir-id\n',
101
104
            '--show-ids')
102
105
        self.ls_equals(
103
106
            '?        .bzrignore\n'
104
107
            'V        a                                         a-id\n'
105
 
            'V        subdir/                                   subdir-id\n', 
 
108
            'V        subdir/                                   subdir-id\n',
106
109
            '--show-ids --verbose')
107
110
        self.ls_equals('.bzrignore\0\0'
108
111
                       'a\0a-id\0'
109
112
                       'subdir\0subdir-id\0', '--show-ids --null')
110
113
 
111
 
    def test_ls_recursive(self):
 
114
    def test_ls_no_recursive(self):
112
115
        self.build_tree(['subdir/', 'subdir/b'])
113
116
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
114
117
 
115
118
        self.ls_equals('.bzrignore\n'
116
119
                       'a\n'
117
 
                       'subdir\n'
118
 
                       , '--non-recursive')
 
120
                       'subdir/\n'
 
121
                       , recursive=False)
119
122
 
120
123
        self.ls_equals('V        .bzrignore\n'
121
124
                       'V        a\n'
122
125
                       'V        subdir/\n'
123
 
                       , '--verbose --non-recursive')
 
126
                       , '--verbose', recursive=False)
124
127
 
125
128
        # Check what happens in a sub-directory
126
129
        os.chdir('subdir')
127
130
        self.ls_equals('b\n')
128
131
        self.ls_equals('b\0'
129
132
                  , '--null')
130
 
        self.ls_equals('.bzrignore\n'
131
 
                       'a\n'
132
 
                       'subdir\n'
133
 
                       'subdir/b\n'
 
133
        self.ls_equals('subdir/b\n'
134
134
                       , '--from-root')
135
 
        self.ls_equals('.bzrignore\0'
136
 
                       'a\0'
137
 
                       'subdir\0'
138
 
                       'subdir/b\0'
 
135
        self.ls_equals('subdir/b\0'
139
136
                       , '--from-root --null')
140
 
        self.ls_equals('.bzrignore\n'
141
 
                       'a\n'
142
 
                       'subdir\n'
143
 
                       , '--from-root --non-recursive')
 
137
        self.ls_equals('subdir/b\n'
 
138
                       , '--from-root', recursive=False)
144
139
 
145
140
    def test_ls_path(self):
146
141
        """If a path is specified, files are listed with that prefix"""
151
146
        os.chdir('subdir')
152
147
        self.ls_equals('../.bzrignore\n'
153
148
                       '../a\n'
154
 
                       '../subdir\n'
 
149
                       '../subdir/\n'
155
150
                       '../subdir/b\n' ,
156
151
                       '..')
157
152
        self.ls_equals('../.bzrignore\0'
164
159
                       'V        ../subdir/\n'
165
160
                       'V        ../subdir/b\n' ,
166
161
                       '.. --verbose')
167
 
        self.run_bzr_error('cannot specify both --from-root and PATH',
 
162
        self.run_bzr_error(['cannot specify both --from-root and PATH'],
168
163
                           'ls --from-root ..')
169
164
 
170
165
    def test_ls_revision(self):
188
183
        self.wt.commit('committing')
189
184
        branch = self.make_branch('branchdir')
190
185
        branch.pull(self.wt.branch)
191
 
        self.ls_equals('branchdir/subdir\n'
 
186
        self.ls_equals('branchdir/subdir/\n'
192
187
                       'branchdir/subdir/b\n',
193
188
                       'branchdir')
194
 
        self.ls_equals('branchdir/subdir\n'
 
189
        self.ls_equals('branchdir/subdir/\n'
195
190
                       'branchdir/subdir/b\n',
196
191
                       'branchdir --revision 1')
197
192
 
226
221
 
227
222
    def test_kinds(self):
228
223
        self.build_tree(['subdir/'])
229
 
        self.ls_equals('.bzrignore\n' 
230
 
                       'a\n', 
 
224
        self.ls_equals('.bzrignore\n'
 
225
                       'a\n',
231
226
                       '--kind=file')
232
 
        self.ls_equals('subdir\n',
 
227
        self.ls_equals('subdir/\n',
233
228
                       '--kind=directory')
234
229
        self.ls_equals('',
235
230
                       '--kind=symlink')
236
 
        self.run_bzr_error('invalid kind specified', 'ls --kind=pile')
 
231
        self.run_bzr_error(['invalid kind specified'], 'ls --kind=pile')
 
232
 
 
233
    def test_ls_path_nonrecursive(self):
 
234
        self.ls_equals('%s/.bzrignore\n'
 
235
                       '%s/a\n'
 
236
                       % (self.test_dir, self.test_dir),
 
237
                       self.test_dir, recursive=False)
 
238
 
 
239
    def test_ls_directory(self):
 
240
        """Test --directory option"""
 
241
        self.wt = self.make_branch_and_tree('dir')
 
242
        self.build_tree(['dir/sub/', 'dir/sub/file'])
 
243
        self.wt.add(['sub', 'sub/file'])
 
244
        self.wt.commit('commit')
 
245
        self.ls_equals('sub/\nsub/file\n', '--directory=dir')
 
246
        self.ls_equals('sub/file\n', '-d dir sub')