~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2011-12-19 19:15:58 UTC
  • mfrom: (6388 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6404.
  • Revision ID: jelmer@canonical.com-20111219191558-p1k7cvhjq8l6v2gm
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2010 Canonical Ltd
 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""External tests of 'bzr ls'"""
 
18
 
 
19
import os
 
20
 
 
21
from bzrlib import ignores
 
22
from bzrlib.tests import TestCaseWithTransport
 
23
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
24
 
 
25
 
 
26
class TestLS(TestCaseWithTransport):
 
27
 
 
28
    def setUp(self):
 
29
        super(TestLS, self).setUp()
 
30
 
 
31
        # Create a simple branch that can be used in testing
 
32
        ignores._set_user_ignores(['user-ignore'])
 
33
 
 
34
        self.wt = self.make_branch_and_tree('.')
 
35
        self.build_tree_contents([
 
36
                                 ('.bzrignore', '*.pyo\n'),
 
37
                                 ('a', 'hello\n'),
 
38
                                 ])
 
39
 
 
40
    def ls_equals(self, value, args=None, recursive=True):
 
41
        command = 'ls'
 
42
        if args is not None:
 
43
            command += ' ' + args
 
44
        if recursive:
 
45
            command += ' -R'
 
46
        out, err = self.run_bzr(command)
 
47
        self.assertEqual('', err)
 
48
        self.assertEqualDiff(value, out)
 
49
 
 
50
    def test_ls_null_verbose(self):
 
51
        # Can't supply both
 
52
        self.run_bzr_error(['Cannot set both --verbose and --null'],
 
53
                           'ls --verbose --null')
 
54
 
 
55
    def test_ls_basic(self):
 
56
        """Test the abilities of 'bzr ls'"""
 
57
        self.ls_equals('.bzrignore\na\n')
 
58
        self.ls_equals('.bzrignore\na\n', './')
 
59
        self.ls_equals('?        .bzrignore\n'
 
60
                       '?        a\n',
 
61
                       '--verbose')
 
62
        self.ls_equals('.bzrignore\n'
 
63
                       'a\n',
 
64
                       '--unknown')
 
65
        self.ls_equals('', '--ignored')
 
66
        self.ls_equals('', '--versioned')
 
67
        self.ls_equals('', '-V')
 
68
        self.ls_equals('.bzrignore\n'
 
69
                       'a\n',
 
70
                       '--unknown --ignored --versioned')
 
71
        self.ls_equals('.bzrignore\n'
 
72
                       'a\n',
 
73
                       '--unknown --ignored -V')
 
74
        self.ls_equals('', '--ignored --versioned')
 
75
        self.ls_equals('', '--ignored -V')
 
76
        self.ls_equals('.bzrignore\0a\0', '--null')
 
77
 
 
78
    def test_ls_added(self):
 
79
        self.wt.add(['a'])
 
80
        self.ls_equals('?        .bzrignore\n'
 
81
                       'V        a\n',
 
82
                       '--verbose')
 
83
        self.wt.commit('add')
 
84
 
 
85
        self.build_tree(['subdir/'])
 
86
        self.ls_equals('?        .bzrignore\n'
 
87
                       'V        a\n'
 
88
                       '?        subdir/\n'
 
89
                       , '--verbose')
 
90
        self.build_tree(['subdir/b'])
 
91
        self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
 
92
        self.ls_equals('V        .bzrignore\n'
 
93
                       'V        a\n'
 
94
                       'V        subdir/\n'
 
95
                       'V        subdir/b\n'
 
96
                       , '--verbose')
 
97
 
 
98
    def test_show_ids(self):
 
99
        self.build_tree(['subdir/'])
 
100
        self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
 
101
        self.ls_equals(
 
102
            '.bzrignore                                         \n'
 
103
            'a                                                  a-id\n'
 
104
            'subdir/                                            subdir-id\n',
 
105
            '--show-ids')
 
106
        self.ls_equals(
 
107
            '?        .bzrignore\n'
 
108
            'V        a                                         a-id\n'
 
109
            'V        subdir/                                   subdir-id\n',
 
110
            '--show-ids --verbose')
 
111
        self.ls_equals('.bzrignore\0\0'
 
112
                       'a\0a-id\0'
 
113
                       'subdir\0subdir-id\0', '--show-ids --null')
 
114
 
 
115
    def test_ls_no_recursive(self):
 
116
        self.build_tree(['subdir/', 'subdir/b'])
 
117
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
 
118
 
 
119
        self.ls_equals('.bzrignore\n'
 
120
                       'a\n'
 
121
                       'subdir/\n'
 
122
                       , recursive=False)
 
123
 
 
124
        self.ls_equals('V        .bzrignore\n'
 
125
                       'V        a\n'
 
126
                       'V        subdir/\n'
 
127
                       , '--verbose', recursive=False)
 
128
 
 
129
        # Check what happens in a sub-directory
 
130
        os.chdir('subdir')
 
131
        self.ls_equals('b\n')
 
132
        self.ls_equals('b\0'
 
133
                  , '--null')
 
134
        self.ls_equals('subdir/b\n'
 
135
                       , '--from-root')
 
136
        self.ls_equals('subdir/b\0'
 
137
                       , '--from-root --null')
 
138
        self.ls_equals('subdir/b\n'
 
139
                       , '--from-root', recursive=False)
 
140
 
 
141
    def test_ls_path(self):
 
142
        """If a path is specified, files are listed with that prefix"""
 
143
        self.build_tree(['subdir/', 'subdir/b'])
 
144
        self.wt.add(['subdir', 'subdir/b'])
 
145
        self.ls_equals('subdir/b\n' ,
 
146
                       'subdir')
 
147
        os.chdir('subdir')
 
148
        self.ls_equals('../.bzrignore\n'
 
149
                       '../a\n'
 
150
                       '../subdir/\n'
 
151
                       '../subdir/b\n' ,
 
152
                       '..')
 
153
        self.ls_equals('../.bzrignore\0'
 
154
                       '../a\0'
 
155
                       '../subdir\0'
 
156
                       '../subdir/b\0' ,
 
157
                       '.. --null')
 
158
        self.ls_equals('?        ../.bzrignore\n'
 
159
                       '?        ../a\n'
 
160
                       'V        ../subdir/\n'
 
161
                       'V        ../subdir/b\n' ,
 
162
                       '.. --verbose')
 
163
        self.run_bzr_error(['cannot specify both --from-root and PATH'],
 
164
                           'ls --from-root ..')
 
165
 
 
166
    def test_ls_revision(self):
 
167
        self.wt.add(['a'])
 
168
        self.wt.commit('add')
 
169
 
 
170
        self.build_tree(['subdir/'])
 
171
 
 
172
        # Check what happens when we supply a specific revision
 
173
        self.ls_equals('a\n', '--revision 1')
 
174
        self.ls_equals('V        a\n'
 
175
                       , '--verbose --revision 1')
 
176
 
 
177
        os.chdir('subdir')
 
178
        self.ls_equals('', '--revision 1')
 
179
 
 
180
    def test_ls_branch(self):
 
181
        """If a branch is specified, files are listed from it"""
 
182
        self.build_tree(['subdir/', 'subdir/b'])
 
183
        self.wt.add(['subdir', 'subdir/b'])
 
184
        self.wt.commit('committing')
 
185
        branch = self.make_branch('branchdir')
 
186
        branch.pull(self.wt.branch)
 
187
        self.ls_equals('branchdir/subdir/\n'
 
188
                       'branchdir/subdir/b\n',
 
189
                       'branchdir')
 
190
        self.ls_equals('branchdir/subdir/\n'
 
191
                       'branchdir/subdir/b\n',
 
192
                       'branchdir --revision 1')
 
193
 
 
194
    def test_ls_ignored(self):
 
195
        # Now try to do ignored files.
 
196
        self.wt.add(['a', '.bzrignore'])
 
197
 
 
198
        self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
 
199
        self.ls_equals('.bzrignore\n'
 
200
                       'a\n'
 
201
                       'blah.py\n'
 
202
                       'blah.pyo\n'
 
203
                       'user-ignore\n'
 
204
                       )
 
205
        self.ls_equals('V        .bzrignore\n'
 
206
                       'V        a\n'
 
207
                       '?        blah.py\n'
 
208
                       'I        blah.pyo\n'
 
209
                       'I        user-ignore\n'
 
210
                       , '--verbose')
 
211
        self.ls_equals('blah.pyo\n'
 
212
                       'user-ignore\n'
 
213
                       , '--ignored')
 
214
        self.ls_equals('blah.py\n'
 
215
                       , '--unknown')
 
216
        self.ls_equals('.bzrignore\n'
 
217
                       'a\n'
 
218
                       , '--versioned')
 
219
        self.ls_equals('.bzrignore\n'
 
220
                       'a\n'
 
221
                       , '-V')
 
222
 
 
223
    def test_kinds(self):
 
224
        self.build_tree(['subdir/'])
 
225
        self.ls_equals('.bzrignore\n'
 
226
                       'a\n',
 
227
                       '--kind=file')
 
228
        self.ls_equals('subdir/\n',
 
229
                       '--kind=directory')
 
230
        self.ls_equals('',
 
231
                       '--kind=symlink')
 
232
        self.run_bzr_error(['invalid kind specified'], 'ls --kind=pile')
 
233
 
 
234
    def test_ls_path_nonrecursive(self):
 
235
        self.ls_equals('%s/.bzrignore\n'
 
236
                       '%s/a\n'
 
237
                       % (self.test_dir, self.test_dir),
 
238
                       self.test_dir, recursive=False)
 
239
 
 
240
    def test_ls_directory(self):
 
241
        """Test --directory option"""
 
242
        self.wt = self.make_branch_and_tree('dir')
 
243
        self.build_tree(['dir/sub/', 'dir/sub/file'])
 
244
        self.wt.add(['sub', 'sub/file'])
 
245
        self.wt.commit('commit')
 
246
        self.ls_equals('sub/\nsub/file\n', '--directory=dir')
 
247
        self.ls_equals('sub/file\n', '-d dir sub')
 
248
 
 
249
 
 
250
class TestSmartServerLs(TestCaseWithTransport):
 
251
 
 
252
    def test_simple_ls(self):
 
253
        self.setup_smart_server_with_call_log()
 
254
        t = self.make_branch_and_tree('branch')
 
255
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
256
        t.add("foo")
 
257
        t.commit("message")
 
258
        self.reset_smart_call_log()
 
259
        out, err = self.run_bzr(['ls', self.get_url('branch')])
 
260
        # This figure represent the amount of work to perform this use case. It
 
261
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
262
        # being too low. If rpc_count increases, more network roundtrips have
 
263
        # become necessary for this use case. Please do not adjust this number
 
264
        # upwards without agreement from bzr's network support maintainers.
 
265
        self.assertLength(6, self.hpss_calls)
 
266
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)