~bzr-pqm/bzr/bzr.dev

4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2006-2010 Canonical Ltd
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
16
17
"""External tests of 'bzr ls'"""
18
19
import os
20
1551.9.25 by Aaron Bentley
Remove unneeded import
21
from bzrlib import ignores
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
22
from bzrlib.tests import TestCaseWithTransport
23
24
25
class TestLS(TestCaseWithTransport):
26
27
    def setUp(self):
28
        super(TestLS, self).setUp()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
29
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
30
        # Create a simple branch that can be used in testing
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
31
        ignores._set_user_ignores(['user-ignore'])
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
32
33
        self.wt = self.make_branch_and_tree('.')
34
        self.build_tree_contents([
35
                                 ('.bzrignore', '*.pyo\n'),
36
                                 ('a', 'hello\n'),
37
                                 ])
38
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
39
    def ls_equals(self, value, args=None, recursive=True):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
40
        command = 'ls'
41
        if args is not None:
42
            command += ' ' + args
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
43
        if recursive:
44
            command += ' -R'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
45
        out, err = self.run_bzr(command)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
46
        self.assertEqual('', err)
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
47
        self.assertEqualDiff(value, out)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
48
49
    def test_ls_null_verbose(self):
50
        # Can't supply both
51
        self.run_bzr_error(['Cannot set both --verbose and --null'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
52
                           'ls --verbose --null')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
53
54
    def test_ls_basic(self):
55
        """Test the abilities of 'bzr ls'"""
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
56
        self.ls_equals('.bzrignore\na\n')
4832.1.1 by Benjamin Peterson
avoid getting extra slashes in the output when ls' argument ends with a slash
57
        self.ls_equals('.bzrignore\na\n', './')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
58
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
59
                       '?        a\n',
60
                       '--verbose')
61
        self.ls_equals('.bzrignore\n'
62
                       'a\n',
63
                       '--unknown')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
64
        self.ls_equals('', '--ignored')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
65
        self.ls_equals('', '--versioned')
3382.2.2 by Jerad Cramp
Added tests for 'ls -V'.
66
        self.ls_equals('', '-V')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
67
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
68
                       'a\n',
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
69
                       '--unknown --ignored --versioned')
3382.2.2 by Jerad Cramp
Added tests for 'ls -V'.
70
        self.ls_equals('.bzrignore\n'
71
                       'a\n',
72
                       '--unknown --ignored -V')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
73
        self.ls_equals('', '--ignored --versioned')
3382.2.2 by Jerad Cramp
Added tests for 'ls -V'.
74
        self.ls_equals('', '--ignored -V')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
75
        self.ls_equals('.bzrignore\0a\0', '--null')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
76
77
    def test_ls_added(self):
78
        self.wt.add(['a'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
79
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
80
                       'V        a\n',
81
                       '--verbose')
82
        self.wt.commit('add')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
83
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
84
        self.build_tree(['subdir/'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
85
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
86
                       'V        a\n'
87
                       '?        subdir/\n'
88
                       , '--verbose')
89
        self.build_tree(['subdir/b'])
90
        self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
91
        self.ls_equals('V        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
92
                       'V        a\n'
93
                       'V        subdir/\n'
94
                       'V        subdir/b\n'
95
                       , '--verbose')
96
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
97
    def test_show_ids(self):
98
        self.build_tree(['subdir/'])
99
        self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
100
        self.ls_equals(
101
            '.bzrignore                                         \n'
102
            'a                                                  a-id\n'
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
103
            'subdir/                                            subdir-id\n',
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
104
            '--show-ids')
105
        self.ls_equals(
106
            '?        .bzrignore\n'
107
            'V        a                                         a-id\n'
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
108
            'V        subdir/                                   subdir-id\n',
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
109
            '--show-ids --verbose')
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
110
        self.ls_equals('.bzrignore\0\0'
111
                       'a\0a-id\0'
3883.1.6 by Gordon P. Hemsley
Revert added slash for null-separated output of 'bzr ls'.
112
                       'subdir\0subdir-id\0', '--show-ids --null')
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
113
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
114
    def test_ls_no_recursive(self):
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
115
        self.build_tree(['subdir/', 'subdir/b'])
116
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
117
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
118
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
119
                       'a\n'
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
120
                       'subdir/\n'
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
121
                       , recursive=False)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
122
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
123
        self.ls_equals('V        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
124
                       'V        a\n'
125
                       'V        subdir/\n'
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
126
                       , '--verbose', recursive=False)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
127
128
        # Check what happens in a sub-directory
129
        os.chdir('subdir')
130
        self.ls_equals('b\n')
131
        self.ls_equals('b\0'
132
                  , '--null')
4370.6.1 by Ian Clatworthy
refactor ls command to use new APIs
133
        self.ls_equals('subdir/b\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
134
                       , '--from-root')
4370.6.1 by Ian Clatworthy
refactor ls command to use new APIs
135
        self.ls_equals('subdir/b\0'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
136
                       , '--from-root --null')
4370.6.1 by Ian Clatworthy
refactor ls command to use new APIs
137
        self.ls_equals('subdir/b\n'
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
138
                       , '--from-root', recursive=False)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
139
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
140
    def test_ls_path(self):
141
        """If a path is specified, files are listed with that prefix"""
142
        self.build_tree(['subdir/', 'subdir/b'])
143
        self.wt.add(['subdir', 'subdir/b'])
144
        self.ls_equals('subdir/b\n' ,
145
                       'subdir')
146
        os.chdir('subdir')
147
        self.ls_equals('../.bzrignore\n'
148
                       '../a\n'
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
149
                       '../subdir/\n'
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
150
                       '../subdir/b\n' ,
151
                       '..')
152
        self.ls_equals('../.bzrignore\0'
153
                       '../a\0'
3883.1.6 by Gordon P. Hemsley
Revert added slash for null-separated output of 'bzr ls'.
154
                       '../subdir\0'
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
155
                       '../subdir/b\0' ,
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
156
                       '.. --null')
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
157
        self.ls_equals('?        ../.bzrignore\n'
158
                       '?        ../a\n'
159
                       'V        ../subdir/\n'
160
                       'V        ../subdir/b\n' ,
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
161
                       '.. --verbose')
4325.4.6 by Vincent Ladeuil
Fixed as per John's and Markus reviews.
162
        self.run_bzr_error(['cannot specify both --from-root and PATH'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
163
                           'ls --from-root ..')
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
164
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
165
    def test_ls_revision(self):
166
        self.wt.add(['a'])
167
        self.wt.commit('add')
168
169
        self.build_tree(['subdir/'])
170
171
        # Check what happens when we supply a specific revision
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
172
        self.ls_equals('a\n', '--revision 1')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
173
        self.ls_equals('V        a\n'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
174
                       , '--verbose --revision 1')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
175
176
        os.chdir('subdir')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
177
        self.ls_equals('', '--revision 1')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
178
2215.3.3 by Aaron Bentley
Get ls working on branches
179
    def test_ls_branch(self):
180
        """If a branch is specified, files are listed from it"""
181
        self.build_tree(['subdir/', 'subdir/b'])
182
        self.wt.add(['subdir', 'subdir/b'])
183
        self.wt.commit('committing')
184
        branch = self.make_branch('branchdir')
185
        branch.pull(self.wt.branch)
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
186
        self.ls_equals('branchdir/subdir/\n'
2215.3.3 by Aaron Bentley
Get ls working on branches
187
                       'branchdir/subdir/b\n',
188
                       'branchdir')
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
189
        self.ls_equals('branchdir/subdir/\n'
2215.3.3 by Aaron Bentley
Get ls working on branches
190
                       'branchdir/subdir/b\n',
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
191
                       'branchdir --revision 1')
2215.3.3 by Aaron Bentley
Get ls working on branches
192
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
193
    def test_ls_ignored(self):
194
        # Now try to do ignored files.
195
        self.wt.add(['a', '.bzrignore'])
196
197
        self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
198
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
199
                       'a\n'
200
                       'blah.py\n'
201
                       'blah.pyo\n'
202
                       'user-ignore\n'
203
                       )
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
204
        self.ls_equals('V        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
205
                       'V        a\n'
206
                       '?        blah.py\n'
207
                       'I        blah.pyo\n'
208
                       'I        user-ignore\n'
209
                       , '--verbose')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
210
        self.ls_equals('blah.pyo\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
211
                       'user-ignore\n'
212
                       , '--ignored')
213
        self.ls_equals('blah.py\n'
214
                       , '--unknown')
215
        self.ls_equals('.bzrignore\n'
216
                       'a\n'
217
                       , '--versioned')
3382.2.2 by Jerad Cramp
Added tests for 'ls -V'.
218
        self.ls_equals('.bzrignore\n'
219
                       'a\n'
220
                       , '-V')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
221
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
222
    def test_kinds(self):
223
        self.build_tree(['subdir/'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
224
        self.ls_equals('.bzrignore\n'
225
                       'a\n',
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
226
                       '--kind=file')
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
227
        self.ls_equals('subdir/\n',
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
228
                       '--kind=directory')
229
        self.ls_equals('',
230
                       '--kind=symlink')
4325.4.6 by Vincent Ladeuil
Fixed as per John's and Markus reviews.
231
        self.run_bzr_error(['invalid kind specified'], 'ls --kind=pile')
4272.1.1 by Jelmer Vernooij
non-recursive bzr ls now works properly when a path is specified.
232
233
    def test_ls_path_nonrecursive(self):
4272.1.2 by Jelmer Vernooij
Fix formatting per Johns comments.
234
        self.ls_equals('%s/.bzrignore\n'
235
                       '%s/a\n'
236
                       % (self.test_dir, self.test_dir),
4272.1.1 by Jelmer Vernooij
non-recursive bzr ls now works properly when a path is specified.
237
                       self.test_dir, recursive=False)