~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2009-08-04 10:06:30 UTC
  • mto: This revision was merged to the branch mainline in revision 4589.
  • Revision ID: bialix@ukr.net-20090804100630-w8qiper6rucyglri
Bundle imageformats plugins for PyQt4 into bzr.exe installer to enable support of many image formats in QBzr.

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