/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
1
# Copyright (C) 2006-2012 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
6622.1.29 by Jelmer Vernooij
Fix some more tests.
17
"""External tests of 'brz ls'"""
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
18
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import (
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
20
    ignores,
21
    tests,
22
    )
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
23
24
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
25
class TestLS(tests.TestCaseWithTransport):
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
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([
6855.4.1 by Jelmer Vernooij
Yet more bees.
35
                                 ('.bzrignore', b'*.pyo\n'),
36
                                 ('a', b'hello\n'),
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
37
                                 ])
38
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
39
    def ls_equals(self, value, args=None, recursive=True, working_dir=None):
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'
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
45
        out, err = self.run_bzr(command, working_dir=working_dir)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
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
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
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):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
55
        """Test the abilities of 'brz ls'"""
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
56
        self.ls_equals('.bzrignore\na\n')
57
        self.ls_equals('.bzrignore\na\n', './')
58
        self.ls_equals('?        .bzrignore\n'
59
                       '?        a\n',
60
                       '--verbose')
61
        self.ls_equals('.bzrignore\n'
62
                       'a\n',
63
                       '--unknown')
64
        self.ls_equals('', '--ignored')
65
        self.ls_equals('', '--versioned')
66
        self.ls_equals('', '-V')
67
        self.ls_equals('.bzrignore\n'
68
                       'a\n',
69
                       '--unknown --ignored --versioned')
70
        self.ls_equals('.bzrignore\n'
71
                       'a\n',
72
                       '--unknown --ignored -V')
73
        self.ls_equals('', '--ignored --versioned')
74
        self.ls_equals('', '--ignored -V')
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'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
79
        self.ls_equals('?        .bzrignore\n'
80
                       'V        a\n',
81
                       '--verbose')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
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/'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
85
        self.ls_equals('?        .bzrignore\n'
86
                       'V        a\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
87
                       '?        subdir/\n', '--verbose')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
88
        self.build_tree(['subdir/b'])
89
        self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
90
        self.ls_equals('V        .bzrignore\n'
91
                       'V        a\n'
92
                       'V        subdir/\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
93
                       'V        subdir/b\n', '--verbose')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
94
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
95
    def test_show_ids(self):
96
        self.build_tree(['subdir/'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
97
        self.wt.add(['a', 'subdir'], [b'a-id', b'subdir-id'])
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
98
        self.ls_equals(
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
99
            '.bzrignore                                         \n'
100
            'a                                                  a-id\n'
101
            'subdir/                                            subdir-id\n',
102
            '--show-ids')
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
103
        self.ls_equals(
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
104
            '?        .bzrignore\n'
105
            'V        a                                         a-id\n'
106
            'V        subdir/                                   subdir-id\n',
107
            '--show-ids --verbose')
108
        self.ls_equals('.bzrignore\0\0'
109
                       'a\0a-id\0'
110
                       'subdir\0subdir-id\0', '--show-ids --null')
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
111
4206.2.1 by Ian Clatworthy
ls should be non-recursive by default
112
    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.
113
        self.build_tree(['subdir/', 'subdir/b'])
114
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
115
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
116
        self.ls_equals('.bzrignore\n'
117
                       'a\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
118
                       'subdir/\n', recursive=False)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
119
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
120
        self.ls_equals('V        .bzrignore\n'
121
                       'V        a\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
122
                       'V        subdir/\n', '--verbose', recursive=False)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
123
124
        # Check what happens in a sub-directory
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
125
        self.ls_equals('b\n', working_dir='subdir')
126
        self.ls_equals('b\0', '--null', working_dir='subdir')
127
        self.ls_equals('subdir/b\n', '--from-root', working_dir='subdir')
128
        self.ls_equals('subdir/b\0', '--from-root --null',
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
129
                       working_dir='subdir')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
130
        self.ls_equals('subdir/b\n', '--from-root', recursive=False,
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
131
                       working_dir='subdir')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
132
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
133
    def test_ls_path(self):
134
        """If a path is specified, files are listed with that prefix"""
135
        self.build_tree(['subdir/', 'subdir/b'])
136
        self.wt.add(['subdir', 'subdir/b'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
137
        self.ls_equals('subdir/b\n',
138
                       'subdir')
139
        self.ls_equals('../.bzrignore\n'
140
                       '../a\n'
141
                       '../subdir/\n'
142
                       '../subdir/b\n',
143
                       '..', working_dir='subdir')
144
        self.ls_equals('../.bzrignore\0'
145
                       '../a\0'
146
                       '../subdir\0'
147
                       '../subdir/b\0',
148
                       '.. --null', working_dir='subdir')
149
        self.ls_equals('?        ../.bzrignore\n'
150
                       '?        ../a\n'
151
                       'V        ../subdir/\n'
152
                       'V        ../subdir/b\n',
153
                       '.. --verbose', working_dir='subdir')
154
        self.run_bzr_error(['cannot specify both --from-root and PATH'],
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
155
                           'ls --from-root ..', working_dir='subdir')
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
156
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
157
    def test_ls_revision(self):
158
        self.wt.add(['a'])
159
        self.wt.commit('add')
160
161
        self.build_tree(['subdir/'])
162
163
        # Check what happens when we supply a specific revision
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
164
        self.ls_equals('a\n', '--revision 1')
7143.15.2 by Jelmer Vernooij
Run autopep8.
165
        self.ls_equals('V        a\n', '--verbose --revision 1')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
166
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
167
        self.ls_equals('', '--revision 1', working_dir='subdir')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
168
2215.3.3 by Aaron Bentley
Get ls working on branches
169
    def test_ls_branch(self):
170
        """If a branch is specified, files are listed from it"""
171
        self.build_tree(['subdir/', 'subdir/b'])
172
        self.wt.add(['subdir', 'subdir/b'])
173
        self.wt.commit('committing')
174
        branch = self.make_branch('branchdir')
175
        branch.pull(self.wt.branch)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
176
        self.ls_equals('branchdir/subdir/\n'
177
                       'branchdir/subdir/b\n',
178
                       'branchdir')
179
        self.ls_equals('branchdir/subdir/\n'
180
                       'branchdir/subdir/b\n',
181
                       'branchdir --revision 1')
2215.3.3 by Aaron Bentley
Get ls working on branches
182
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
183
    def test_ls_ignored(self):
184
        # Now try to do ignored files.
185
        self.wt.add(['a', '.bzrignore'])
186
187
        self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
188
        self.ls_equals('.bzrignore\n'
189
                       'a\n'
190
                       'blah.py\n'
191
                       'blah.pyo\n'
192
                       'user-ignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
193
                       )
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
194
        self.ls_equals('V        .bzrignore\n'
195
                       'V        a\n'
196
                       '?        blah.py\n'
197
                       'I        blah.pyo\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
198
                       'I        user-ignore\n', '--verbose')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
199
        self.ls_equals('blah.pyo\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
200
                       'user-ignore\n', '--ignored')
201
        self.ls_equals('blah.py\n', '--unknown')
202
        self.ls_equals('.bzrignore\n'
203
                       'a\n', '--versioned')
204
        self.ls_equals('.bzrignore\n'
205
                       'a\n', '-V')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
206
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
207
    def test_kinds(self):
208
        self.build_tree(['subdir/'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
209
        self.ls_equals('.bzrignore\n'
210
                       'a\n',
211
                       '--kind=file')
212
        self.ls_equals('subdir/\n',
213
                       '--kind=directory')
214
        self.ls_equals('',
215
                       '--kind=symlink')
216
        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.
217
218
    def test_ls_path_nonrecursive(self):
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
219
        self.ls_equals('%s/.bzrignore\n'
220
                       '%s/a\n'
4272.1.2 by Jelmer Vernooij
Fix formatting per Johns comments.
221
                       % (self.test_dir, self.test_dir),
4272.1.1 by Jelmer Vernooij
non-recursive bzr ls now works properly when a path is specified.
222
                       self.test_dir, recursive=False)
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
223
224
    def test_ls_directory(self):
225
        """Test --directory option"""
226
        self.wt = self.make_branch_and_tree('dir')
227
        self.build_tree(['dir/sub/', 'dir/sub/file'])
228
        self.wt.add(['sub', 'sub/file'])
229
        self.wt.commit('commit')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
230
        self.ls_equals('sub/\nsub/file\n', '--directory=dir')
231
        self.ls_equals('sub/file\n', '-d dir sub')