/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
132
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
133
                       'a\n'
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
134
                       'subdir/\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
135
                       'subdir/b\n'
136
                       , '--from-root')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
137
        self.ls_equals('.bzrignore\0'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
138
                       'a\0'
3883.1.6 by Gordon P. Hemsley
Revert added slash for null-separated output of 'bzr ls'.
139
                       'subdir\0'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
140
                       'subdir/b\0'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
141
                       , '--from-root --null')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
142
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
143
                       'a\n'
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
144
                       'subdir/\n'
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
145
                       , '--from-root', recursive=False)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
146
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
147
    def test_ls_path(self):
148
        """If a path is specified, files are listed with that prefix"""
149
        self.build_tree(['subdir/', 'subdir/b'])
150
        self.wt.add(['subdir', 'subdir/b'])
151
        self.ls_equals('subdir/b\n' ,
152
                       'subdir')
153
        os.chdir('subdir')
154
        self.ls_equals('../.bzrignore\n'
155
                       '../a\n'
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
156
                       '../subdir/\n'
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
157
                       '../subdir/b\n' ,
158
                       '..')
159
        self.ls_equals('../.bzrignore\0'
160
                       '../a\0'
3883.1.6 by Gordon P. Hemsley
Revert added slash for null-separated output of 'bzr ls'.
161
                       '../subdir\0'
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
162
                       '../subdir/b\0' ,
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
163
                       '.. --null')
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
164
        self.ls_equals('?        ../.bzrignore\n'
165
                       '?        ../a\n'
166
                       'V        ../subdir/\n'
167
                       'V        ../subdir/b\n' ,
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
168
                       '.. --verbose')
169
        self.run_bzr_error('cannot specify both --from-root and PATH',
170
                           'ls --from-root ..')
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
171
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
172
    def test_ls_revision(self):
173
        self.wt.add(['a'])
174
        self.wt.commit('add')
175
176
        self.build_tree(['subdir/'])
177
178
        # Check what happens when we supply a specific revision
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
179
        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.
180
        self.ls_equals('V        a\n'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
181
                       , '--verbose --revision 1')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
182
183
        os.chdir('subdir')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
184
        self.ls_equals('', '--revision 1')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
185
2215.3.3 by Aaron Bentley
Get ls working on branches
186
    def test_ls_branch(self):
187
        """If a branch is specified, files are listed from it"""
188
        self.build_tree(['subdir/', 'subdir/b'])
189
        self.wt.add(['subdir', 'subdir/b'])
190
        self.wt.commit('committing')
191
        branch = self.make_branch('branchdir')
192
        branch.pull(self.wt.branch)
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
193
        self.ls_equals('branchdir/subdir/\n'
2215.3.3 by Aaron Bentley
Get ls working on branches
194
                       'branchdir/subdir/b\n',
195
                       'branchdir')
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
196
        self.ls_equals('branchdir/subdir/\n'
2215.3.3 by Aaron Bentley
Get ls working on branches
197
                       'branchdir/subdir/b\n',
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
198
                       'branchdir --revision 1')
2215.3.3 by Aaron Bentley
Get ls working on branches
199
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
200
    def test_ls_ignored(self):
201
        # Now try to do ignored files.
202
        self.wt.add(['a', '.bzrignore'])
203
204
        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
205
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
206
                       'a\n'
207
                       'blah.py\n'
208
                       'blah.pyo\n'
209
                       'user-ignore\n'
210
                       )
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
211
        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.
212
                       'V        a\n'
213
                       '?        blah.py\n'
214
                       'I        blah.pyo\n'
215
                       'I        user-ignore\n'
216
                       , '--verbose')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
217
        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.
218
                       'user-ignore\n'
219
                       , '--ignored')
220
        self.ls_equals('blah.py\n'
221
                       , '--unknown')
222
        self.ls_equals('.bzrignore\n'
223
                       'a\n'
224
                       , '--versioned')
3382.2.2 by Jerad Cramp
Added tests for 'ls -V'.
225
        self.ls_equals('.bzrignore\n'
226
                       'a\n'
227
                       , '-V')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
228
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
229
    def test_kinds(self):
230
        self.build_tree(['subdir/'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
231
        self.ls_equals('.bzrignore\n'
232
                       'a\n',
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
233
                       '--kind=file')
3883.1.2 by Gordon P. Hemsley
Change unittests to conform to new output.
234
        self.ls_equals('subdir/\n',
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
235
                       '--kind=directory')
236
        self.ls_equals('',
237
                       '--kind=symlink')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
238
        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.
239
240
    def test_ls_path_nonrecursive(self):
4272.1.2 by Jelmer Vernooij
Fix formatting per Johns comments.
241
        self.ls_equals('%s/.bzrignore\n'
242
                       '%s/a\n'
243
                       % (self.test_dir, self.test_dir),
4272.1.1 by Jelmer Vernooij
non-recursive bzr ls now works properly when a path is specified.
244
                       self.test_dir, recursive=False)