~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil, Patch Queue Manager, Jelmer Vernooij
  • Date: 2017-01-17 16:20:41 UTC
  • mfrom: (6619.1.2 trunk)
  • Revision ID: tarmac-20170117162041-oo62uk1qsmgc9j31
Merge 2.7 into trunk including fixes for bugs #1622039, #1644003, #1579093 and #1645017. [r=vila]

Show diffs side-by-side

added added

removed removed

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