~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2007-08-13 14:00:59 UTC
  • mto: (2681.5.3 bzr-mail)
  • mto: This revision was merged to the branch mainline in revision 2736.
  • Revision ID: abentley@panoramicfeedback.com-20070813140059-04k01bfueilqvg10
Update text, fix whitespace issues

Show diffs side-by-side

added added

removed removed

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