~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Ian Clatworthy
  • Date: 2009-09-09 15:30:59 UTC
  • mto: (4634.37.2 prepare-2.0)
  • mto: This revision was merged to the branch mainline in revision 4689.
  • Revision ID: ian.clatworthy@canonical.com-20090909153059-sb038agvd38ci2q8
more link fixes in the User Guide

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
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()
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, recursive=True):
41
40
        command = 'ls'
42
41
        if args is not None:
43
42
            command += ' ' + args
44
43
        if recursive:
45
44
            command += ' -R'
46
 
        out, err = self.run_bzr(command, working_dir=working_dir)
 
45
        out, err = self.run_bzr(command)
47
46
        self.assertEqual('', err)
48
47
        self.assertEqualDiff(value, out)
49
48
 
55
54
    def test_ls_basic(self):
56
55
        """Test the abilities of 'bzr ls'"""
57
56
        self.ls_equals('.bzrignore\na\n')
58
 
        self.ls_equals('.bzrignore\na\n', './')
59
57
        self.ls_equals('?        .bzrignore\n'
60
58
                       '?        a\n',
61
59
                       '--verbose')
127
125
                       , '--verbose', recursive=False)
128
126
 
129
127
        # 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')
 
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)
137
138
 
138
139
    def test_ls_path(self):
139
140
        """If a path is specified, files are listed with that prefix"""
141
142
        self.wt.add(['subdir', 'subdir/b'])
142
143
        self.ls_equals('subdir/b\n' ,
143
144
                       'subdir')
 
145
        os.chdir('subdir')
144
146
        self.ls_equals('../.bzrignore\n'
145
147
                       '../a\n'
146
148
                       '../subdir/\n'
147
149
                       '../subdir/b\n' ,
148
 
                       '..', working_dir='subdir')
 
150
                       '..')
149
151
        self.ls_equals('../.bzrignore\0'
150
152
                       '../a\0'
151
153
                       '../subdir\0'
152
154
                       '../subdir/b\0' ,
153
 
                       '.. --null', working_dir='subdir')
 
155
                       '.. --null')
154
156
        self.ls_equals('?        ../.bzrignore\n'
155
157
                       '?        ../a\n'
156
158
                       'V        ../subdir/\n'
157
159
                       'V        ../subdir/b\n' ,
158
 
                       '.. --verbose', working_dir='subdir')
 
160
                       '.. --verbose')
159
161
        self.run_bzr_error(['cannot specify both --from-root and PATH'],
160
 
                           'ls --from-root ..', working_dir='subdir')
 
162
                           'ls --from-root ..')
161
163
 
162
164
    def test_ls_revision(self):
163
165
        self.wt.add(['a'])
170
172
        self.ls_equals('V        a\n'
171
173
                       , '--verbose --revision 1')
172
174
 
173
 
        self.ls_equals('', '--revision 1', working_dir='subdir')
 
175
        os.chdir('subdir')
 
176
        self.ls_equals('', '--revision 1')
174
177
 
175
178
    def test_ls_branch(self):
176
179
        """If a branch is specified, files are listed from it"""
231
234
                       '%s/a\n'
232
235
                       % (self.test_dir, self.test_dir),
233
236
                       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)