~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2008-12-12 03:53:56 UTC
  • mto: This revision was merged to the branch mainline in revision 3900.
  • Revision ID: andrew.bennetts@canonical.com-20081212035356-uqcu89gy4nqf017x
Fix compilation error in _dirstate_helpers_c on SunOS/Solaris. (Jari Aalto)

Show diffs side-by-side

added added

removed removed

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