~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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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()
29
        
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
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
39
    def ls_equals(self, value, args=None):
40
        command = 'ls'
41
        if args is not None:
42
            command += ' ' + args
43
        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.
44
        self.assertEqual('', err)
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
45
        self.assertEqualDiff(value, out)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
46
47
    def test_ls_null_verbose(self):
48
        # Can't supply both
49
        self.run_bzr_error(['Cannot set both --verbose and --null'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
50
                           'ls --verbose --null')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
51
52
    def test_ls_basic(self):
53
        """Test the abilities of 'bzr ls'"""
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
54
        self.ls_equals('.bzrignore\na\n')
55
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
56
                       '?        a\n',
57
                       '--verbose')
58
        self.ls_equals('.bzrignore\n'
59
                       'a\n',
60
                       '--unknown')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
61
        self.ls_equals('', '--ignored')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
62
        self.ls_equals('', '--versioned')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
63
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
64
                       'a\n',
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
65
                       '--unknown --ignored --versioned')
66
        self.ls_equals('', '--ignored --versioned')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
67
        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.
68
69
    def test_ls_added(self):
70
        self.wt.add(['a'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
71
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
72
                       'V        a\n',
73
                       '--verbose')
74
        self.wt.commit('add')
75
        
76
        self.build_tree(['subdir/'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
77
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
78
                       'V        a\n'
79
                       '?        subdir/\n'
80
                       , '--verbose')
81
        self.build_tree(['subdir/b'])
82
        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
83
        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.
84
                       'V        a\n'
85
                       'V        subdir/\n'
86
                       'V        subdir/b\n'
87
                       , '--verbose')
88
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
89
    def test_show_ids(self):
90
        self.build_tree(['subdir/'])
91
        self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
92
        self.ls_equals(
93
            '.bzrignore                                         \n'
94
            'a                                                  a-id\n'
95
            'subdir                                             subdir-id\n', 
96
            '--show-ids')
97
        self.ls_equals(
98
            '?        .bzrignore\n'
99
            'V        a                                         a-id\n'
100
            'V        subdir/                                   subdir-id\n', 
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
101
            '--show-ids --verbose')
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
102
        self.ls_equals('.bzrignore\0\0'
103
                       'a\0a-id\0'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
104
                       'subdir\0subdir-id\0', '--show-ids --null')
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
105
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
106
    def test_ls_recursive(self):
107
        self.build_tree(['subdir/', 'subdir/b'])
108
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
109
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
110
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
111
                       'a\n'
112
                       'subdir\n'
113
                       , '--non-recursive')
114
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
115
        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.
116
                       'V        a\n'
117
                       'V        subdir/\n'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
118
                       , '--verbose --non-recursive')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
119
120
        # Check what happens in a sub-directory
121
        os.chdir('subdir')
122
        self.ls_equals('b\n')
123
        self.ls_equals('b\0'
124
                  , '--null')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
125
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
126
                       'a\n'
127
                       'subdir\n'
128
                       'subdir/b\n'
129
                       , '--from-root')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
130
        self.ls_equals('.bzrignore\0'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
131
                       'a\0'
132
                       'subdir\0'
133
                       'subdir/b\0'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
134
                       , '--from-root --null')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
135
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
136
                       'a\n'
137
                       'subdir\n'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
138
                       , '--from-root --non-recursive')
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'
149
                       '../subdir\n'
150
                       '../subdir/b\n' ,
151
                       '..')
152
        self.ls_equals('../.bzrignore\0'
153
                       '../a\0'
154
                       '../subdir\0'
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')
162
        self.run_bzr_error('cannot specify both --from-root and PATH',
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)
186
        self.ls_equals('branchdir/subdir\n'
187
                       'branchdir/subdir/b\n',
188
                       'branchdir')
189
        self.ls_equals('branchdir/subdir\n'
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')
218
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
219
    def test_kinds(self):
220
        self.build_tree(['subdir/'])
221
        self.ls_equals('.bzrignore\n' 
222
                       'a\n', 
223
                       '--kind=file')
224
        self.ls_equals('subdir\n',
225
                       '--kind=directory')
226
        self.ls_equals('',
227
                       '--kind=symlink')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
228
        self.run_bzr_error('invalid kind specified', 'ls --kind=pile')