~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 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')
57
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
58
                       '?        a\n',
59
                       '--verbose')
60
        self.ls_equals('.bzrignore\n'
61
                       'a\n',
62
                       '--unknown')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
63
        self.ls_equals('', '--ignored')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
64
        self.ls_equals('', '--versioned')
3382.2.2 by Jerad Cramp
Added tests for 'ls -V'.
65
        self.ls_equals('', '-V')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
66
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
67
                       'a\n',
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
68
                       '--unknown --ignored --versioned')
3382.2.2 by Jerad Cramp
Added tests for 'ls -V'.
69
        self.ls_equals('.bzrignore\n'
70
                       'a\n',
71
                       '--unknown --ignored -V')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
72
        self.ls_equals('', '--ignored --versioned')
3382.2.2 by Jerad Cramp
Added tests for 'ls -V'.
73
        self.ls_equals('', '--ignored -V')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
74
        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.
75
76
    def test_ls_added(self):
77
        self.wt.add(['a'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
78
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
79
                       'V        a\n',
80
                       '--verbose')
81
        self.wt.commit('add')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
82
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
83
        self.build_tree(['subdir/'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
84
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
85
                       'V        a\n'
86
                       '?        subdir/\n'
87
                       , '--verbose')
88
        self.build_tree(['subdir/b'])
89
        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
90
        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.
91
                       'V        a\n'
92
                       'V        subdir/\n'
93
                       'V        subdir/b\n'
94
                       , '--verbose')
95
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
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'
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
102
            'subdir/                                            subdir-id\n',
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
103
            '--show-ids')
104
        self.ls_equals(
105
            '?        .bzrignore\n'
106
            'V        a                                         a-id\n'
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
107
            'V        subdir/                                   subdir-id\n',
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
108
            '--show-ids --verbose')
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
109
        self.ls_equals('.bzrignore\0\0'
110
                       'a\0a-id\0'
3883.1.6 by Gordon P. Hemsley
Revert added slash for null-separated output of 'bzr ls'.
111
                       'subdir\0subdir-id\0', '--show-ids --null')
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
112
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
113
    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.
114
        self.build_tree(['subdir/', 'subdir/b'])
115
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
116
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
117
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
118
                       'a\n'
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
119
                       'subdir/\n'
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
120
                       , recursive=False)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
121
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
122
        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.
123
                       'V        a\n'
124
                       'V        subdir/\n'
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
125
                       , '--verbose', recursive=False)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
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')
4370.6.1 by Ian Clatworthy
refactor ls command to use new APIs
132
        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.
133
                       , '--from-root')
4370.6.1 by Ian Clatworthy
refactor ls command to use new APIs
134
        self.ls_equals('subdir/b\0'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
135
                       , '--from-root --null')
4370.6.1 by Ian Clatworthy
refactor ls command to use new APIs
136
        self.ls_equals('subdir/b\n'
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
137
                       , '--from-root', recursive=False)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
138
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
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'
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
148
                       '../subdir/\n'
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
149
                       '../subdir/b\n' ,
150
                       '..')
151
        self.ls_equals('../.bzrignore\0'
152
                       '../a\0'
3883.1.6 by Gordon P. Hemsley
Revert added slash for null-separated output of 'bzr ls'.
153
                       '../subdir\0'
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
154
                       '../subdir/b\0' ,
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
155
                       '.. --null')
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
156
        self.ls_equals('?        ../.bzrignore\n'
157
                       '?        ../a\n'
158
                       'V        ../subdir/\n'
159
                       'V        ../subdir/b\n' ,
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
160
                       '.. --verbose')
4325.4.6 by Vincent Ladeuil
Fixed as per John's and Markus reviews.
161
        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.
162
                           'ls --from-root ..')
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
163
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
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
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
171
        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.
172
        self.ls_equals('V        a\n'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
173
                       , '--verbose --revision 1')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
174
175
        os.chdir('subdir')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
176
        self.ls_equals('', '--revision 1')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
177
2215.3.3 by Aaron Bentley
Get ls working on branches
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)
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
185
        self.ls_equals('branchdir/subdir/\n'
2215.3.3 by Aaron Bentley
Get ls working on branches
186
                       'branchdir/subdir/b\n',
187
                       'branchdir')
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
188
        self.ls_equals('branchdir/subdir/\n'
2215.3.3 by Aaron Bentley
Get ls working on branches
189
                       'branchdir/subdir/b\n',
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
190
                       'branchdir --revision 1')
2215.3.3 by Aaron Bentley
Get ls working on branches
191
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
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'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
197
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
198
                       'a\n'
199
                       'blah.py\n'
200
                       'blah.pyo\n'
201
                       'user-ignore\n'
202
                       )
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
203
        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.
204
                       'V        a\n'
205
                       '?        blah.py\n'
206
                       'I        blah.pyo\n'
207
                       'I        user-ignore\n'
208
                       , '--verbose')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
209
        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.
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')
3382.2.2 by Jerad Cramp
Added tests for 'ls -V'.
217
        self.ls_equals('.bzrignore\n'
218
                       'a\n'
219
                       , '-V')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
220
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
221
    def test_kinds(self):
222
        self.build_tree(['subdir/'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
223
        self.ls_equals('.bzrignore\n'
224
                       'a\n',
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
225
                       '--kind=file')
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
226
        self.ls_equals('subdir/\n',
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
227
                       '--kind=directory')
228
        self.ls_equals('',
229
                       '--kind=symlink')
4325.4.6 by Vincent Ladeuil
Fixed as per John's and Markus reviews.
230
        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.
231
232
    def test_ls_path_nonrecursive(self):
4272.1.2 by Jelmer Vernooij
Fix formatting per Johns comments.
233
        self.ls_equals('%s/.bzrignore\n'
234
                       '%s/a\n'
235
                       % (self.test_dir, self.test_dir),
4272.1.1 by Jelmer Vernooij
non-recursive bzr ls now works properly when a path is specified.
236
                       self.test_dir, recursive=False)