~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-02-24 12:17:19 UTC
  • mto: (5676.1.5 per_interrepo-extra)
  • mto: This revision was merged to the branch mainline in revision 5686.
  • Revision ID: jelmer@samba.org-20110224121719-nvhwz19krifo3xov
Consistent naming.

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, osutils
 
22
from bzrlib.tests import TestCaseWithTransport
 
23
 
 
24
 
 
25
class TestLS(TestCaseWithTransport):
 
26
 
 
27
    def setUp(self):
 
28
        super(TestLS, self).setUp()
 
29
 
 
30
        # Create a simple branch that can be used in testing
 
31
        ignores._set_user_ignores(['user-ignore'])
 
32
 
 
33
        self.wt = self.make_branch_and_tree('.')
 
34
        self.build_tree_contents([
 
35
                                 ('.bzrignore', '*.pyo\n'),
 
36
                                 ('a', 'hello\n'),
 
37
                                 ])
 
38
 
 
39
    def ls_equals(self, value, args=None, recursive=True):
 
40
        command = 'ls'
 
41
        if args is not None:
 
42
            command += ' ' + args
 
43
        if recursive:
 
44
            command += ' -R'
 
45
        out, err = self.run_bzr(command)
 
46
        self.assertEqual('', err)
 
47
        self.assertEqualDiff(value, out)
 
48
 
 
49
    def test_ls_null_verbose(self):
 
50
        # Can't supply both
 
51
        self.run_bzr_error(['Cannot set both --verbose and --null'],
 
52
                           'ls --verbose --null')
 
53
 
 
54
    def test_ls_basic(self):
 
55
        """Test the abilities of 'bzr ls'"""
 
56
        self.ls_equals('.bzrignore\na\n')
 
57
        self.ls_equals('.bzrignore\na\n', './')
 
58
        self.ls_equals('?        .bzrignore\n'
 
59
                       '?        a\n',
 
60
                       '--verbose')
 
61
        self.ls_equals('.bzrignore\n'
 
62
                       'a\n',
 
63
                       '--unknown')
 
64
        self.ls_equals('', '--ignored')
 
65
        self.ls_equals('', '--versioned')
 
66
        self.ls_equals('', '-V')
 
67
        self.ls_equals('.bzrignore\n'
 
68
                       'a\n',
 
69
                       '--unknown --ignored --versioned')
 
70
        self.ls_equals('.bzrignore\n'
 
71
                       'a\n',
 
72
                       '--unknown --ignored -V')
 
73
        self.ls_equals('', '--ignored --versioned')
 
74
        self.ls_equals('', '--ignored -V')
 
75
        self.ls_equals('.bzrignore\0a\0', '--null')
 
76
 
 
77
    def test_ls_added(self):
 
78
        self.wt.add(['a'])
 
79
        self.ls_equals('?        .bzrignore\n'
 
80
                       'V        a\n',
 
81
                       '--verbose')
 
82
        self.wt.commit('add')
 
83
 
 
84
        self.build_tree(['subdir/'])
 
85
        self.ls_equals('?        .bzrignore\n'
 
86
                       'V        a\n'
 
87
                       '?        subdir/\n'
 
88
                       , '--verbose')
 
89
        self.build_tree(['subdir/b'])
 
90
        self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
 
91
        self.ls_equals('V        .bzrignore\n'
 
92
                       'V        a\n'
 
93
                       'V        subdir/\n'
 
94
                       'V        subdir/b\n'
 
95
                       , '--verbose')
 
96
 
 
97
    def test_show_ids(self):
 
98
        self.build_tree(['subdir/'])
 
99
        self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
 
100
        self.ls_equals(
 
101
            '.bzrignore                                         \n'
 
102
            'a                                                  a-id\n'
 
103
            'subdir/                                            subdir-id\n',
 
104
            '--show-ids')
 
105
        self.ls_equals(
 
106
            '?        .bzrignore\n'
 
107
            'V        a                                         a-id\n'
 
108
            'V        subdir/                                   subdir-id\n',
 
109
            '--show-ids --verbose')
 
110
        self.ls_equals('.bzrignore\0\0'
 
111
                       'a\0a-id\0'
 
112
                       'subdir\0subdir-id\0', '--show-ids --null')
 
113
 
 
114
    def test_ls_no_recursive(self):
 
115
        self.build_tree(['subdir/', 'subdir/b'])
 
116
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
 
117
 
 
118
        self.ls_equals('.bzrignore\n'
 
119
                       'a\n'
 
120
                       'subdir/\n'
 
121
                       , recursive=False)
 
122
 
 
123
        self.ls_equals('V        .bzrignore\n'
 
124
                       'V        a\n'
 
125
                       'V        subdir/\n'
 
126
                       , '--verbose', recursive=False)
 
127
 
 
128
        # Check what happens in a sub-directory
 
129
        os.chdir('subdir')
 
130
        self.ls_equals('b\n')
 
131
        self.ls_equals('b\0'
 
132
                  , '--null')
 
133
        self.ls_equals('subdir/b\n'
 
134
                       , '--from-root')
 
135
        self.ls_equals('subdir/b\0'
 
136
                       , '--from-root --null')
 
137
        self.ls_equals('subdir/b\n'
 
138
                       , '--from-root', recursive=False)
 
139
 
 
140
    def test_ls_path(self):
 
141
        """If a path is specified, files are listed with that prefix"""
 
142
        self.build_tree(['subdir/', 'subdir/b'])
 
143
        self.wt.add(['subdir', 'subdir/b'])
 
144
        self.ls_equals('subdir/b\n' ,
 
145
                       'subdir')
 
146
        os.chdir('subdir')
 
147
        self.ls_equals('../.bzrignore\n'
 
148
                       '../a\n'
 
149
                       '../subdir/\n'
 
150
                       '../subdir/b\n' ,
 
151
                       '..')
 
152
        self.ls_equals('../.bzrignore\0'
 
153
                       '../a\0'
 
154
                       '../subdir\0'
 
155
                       '../subdir/b\0' ,
 
156
                       '.. --null')
 
157
        self.ls_equals('?        ../.bzrignore\n'
 
158
                       '?        ../a\n'
 
159
                       'V        ../subdir/\n'
 
160
                       'V        ../subdir/b\n' ,
 
161
                       '.. --verbose')
 
162
        self.run_bzr_error(['cannot specify both --from-root and PATH'],
 
163
                           'ls --from-root ..')
 
164
 
 
165
    def test_ls_revision(self):
 
166
        self.wt.add(['a'])
 
167
        self.wt.commit('add')
 
168
 
 
169
        self.build_tree(['subdir/'])
 
170
 
 
171
        # Check what happens when we supply a specific revision
 
172
        self.ls_equals('a\n', '--revision 1')
 
173
        self.ls_equals('V        a\n'
 
174
                       , '--verbose --revision 1')
 
175
 
 
176
        os.chdir('subdir')
 
177
        self.ls_equals('', '--revision 1')
 
178
 
 
179
    def test_ls_branch(self):
 
180
        """If a branch is specified, files are listed from it"""
 
181
        self.build_tree(['subdir/', 'subdir/b'])
 
182
        self.wt.add(['subdir', 'subdir/b'])
 
183
        self.wt.commit('committing')
 
184
        branch = self.make_branch('branchdir')
 
185
        branch.pull(self.wt.branch)
 
186
        self.ls_equals('branchdir/subdir/\n'
 
187
                       'branchdir/subdir/b\n',
 
188
                       'branchdir')
 
189
        self.ls_equals('branchdir/subdir/\n'
 
190
                       'branchdir/subdir/b\n',
 
191
                       'branchdir --revision 1')
 
192
 
 
193
    def test_ls_ignored(self):
 
194
        # Now try to do ignored files.
 
195
        self.wt.add(['a', '.bzrignore'])
 
196
 
 
197
        self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
 
198
        self.ls_equals('.bzrignore\n'
 
199
                       'a\n'
 
200
                       'blah.py\n'
 
201
                       'blah.pyo\n'
 
202
                       'user-ignore\n'
 
203
                       )
 
204
        self.ls_equals('V        .bzrignore\n'
 
205
                       'V        a\n'
 
206
                       '?        blah.py\n'
 
207
                       'I        blah.pyo\n'
 
208
                       'I        user-ignore\n'
 
209
                       , '--verbose')
 
210
        self.ls_equals('blah.pyo\n'
 
211
                       'user-ignore\n'
 
212
                       , '--ignored')
 
213
        self.ls_equals('blah.py\n'
 
214
                       , '--unknown')
 
215
        self.ls_equals('.bzrignore\n'
 
216
                       'a\n'
 
217
                       , '--versioned')
 
218
        self.ls_equals('.bzrignore\n'
 
219
                       'a\n'
 
220
                       , '-V')
 
221
 
 
222
    def test_kinds(self):
 
223
        self.build_tree(['subdir/'])
 
224
        self.ls_equals('.bzrignore\n'
 
225
                       'a\n',
 
226
                       '--kind=file')
 
227
        self.ls_equals('subdir/\n',
 
228
                       '--kind=directory')
 
229
        self.ls_equals('',
 
230
                       '--kind=symlink')
 
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')