~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
39
    def ls_equals(self, value, *args):
40
        out, err = self.run_bzr('ls', *args)
41
        self.assertEqual('', err)
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
42
        self.assertEqualDiff(value, out)
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
43
44
    def test_ls_null_verbose(self):
45
        # Can't supply both
46
        self.run_bzr_error(['Cannot set both --verbose and --null'],
47
                           'ls', '--verbose', '--null')
48
49
    def test_ls_basic(self):
50
        """Test the abilities of 'bzr ls'"""
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
51
        self.ls_equals('.bzrignore\na\n')
52
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
53
                       '?        a\n',
54
                       '--verbose')
55
        self.ls_equals('.bzrignore\n'
56
                       'a\n',
57
                       '--unknown')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
58
        self.ls_equals('', '--ignored')
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
59
        self.ls_equals('', '--versioned')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
60
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
61
                       'a\n',
62
                       '--unknown', '--ignored', '--versioned')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
63
        self.ls_equals('', '--ignored', '--versioned')
64
        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.
65
66
    def test_ls_added(self):
67
        self.wt.add(['a'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
68
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
69
                       'V        a\n',
70
                       '--verbose')
71
        self.wt.commit('add')
72
        
73
        self.build_tree(['subdir/'])
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
74
        self.ls_equals('?        .bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
75
                       'V        a\n'
76
                       '?        subdir/\n'
77
                       , '--verbose')
78
        self.build_tree(['subdir/b'])
79
        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
80
        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.
81
                       'V        a\n'
82
                       'V        subdir/\n'
83
                       'V        subdir/b\n'
84
                       , '--verbose')
85
1551.9.27 by Aaron Bentley
Implement show-ids for all output formats
86
    def test_show_ids(self):
87
        self.build_tree(['subdir/'])
88
        self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
89
        self.ls_equals(
90
            '.bzrignore                                         \n'
91
            'a                                                  a-id\n'
92
            'subdir                                             subdir-id\n', 
93
            '--show-ids')
94
        self.ls_equals(
95
            '?        .bzrignore\n'
96
            'V        a                                         a-id\n'
97
            'V        subdir/                                   subdir-id\n', 
98
            '--show-ids', '--verbose')
99
        self.ls_equals('.bzrignore\0\0'
100
                       'a\0a-id\0'
101
                       'subdir\0subdir-id\0', '--show-ids', '--null')
102
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
103
    def test_ls_recursive(self):
104
        self.build_tree(['subdir/', 'subdir/b'])
105
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
106
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
107
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
108
                       'a\n'
109
                       'subdir\n'
110
                       , '--non-recursive')
111
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
112
        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.
113
                       'V        a\n'
114
                       'V        subdir/\n'
115
                       , '--verbose', '--non-recursive')
116
117
        # Check what happens in a sub-directory
118
        os.chdir('subdir')
119
        self.ls_equals('b\n')
120
        self.ls_equals('b\0'
121
                  , '--null')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
122
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
123
                       'a\n'
124
                       'subdir\n'
125
                       'subdir/b\n'
126
                       , '--from-root')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
127
        self.ls_equals('.bzrignore\0'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
128
                       'a\0'
129
                       'subdir\0'
130
                       'subdir/b\0'
131
                       , '--from-root', '--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'
134
                       'subdir\n'
135
                       , '--from-root', '--non-recursive')
136
2215.3.1 by Aaron Bentley
Allow ls to take a PATH
137
    def test_ls_path(self):
138
        """If a path is specified, files are listed with that prefix"""
139
        self.build_tree(['subdir/', 'subdir/b'])
140
        self.wt.add(['subdir', 'subdir/b'])
141
        self.ls_equals('subdir/b\n' ,
142
                       'subdir')
143
        os.chdir('subdir')
144
        self.ls_equals('../.bzrignore\n'
145
                       '../a\n'
146
                       '../subdir\n'
147
                       '../subdir/b\n' ,
148
                       '..')
149
        self.ls_equals('../.bzrignore\0'
150
                       '../a\0'
151
                       '../subdir\0'
152
                       '../subdir/b\0' ,
153
                       '..', '--null')
154
        self.ls_equals('?        ../.bzrignore\n'
155
                       '?        ../a\n'
156
                       'V        ../subdir/\n'
157
                       'V        ../subdir/b\n' ,
158
                       '..', '--verbose')
159
        self.run_bzr_error('cannot specify both --from-root and PATH', 'ls',
160
                           '--from-root', '..')
161
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
162
    def test_ls_revision(self):
163
        self.wt.add(['a'])
164
        self.wt.commit('add')
165
166
        self.build_tree(['subdir/'])
167
168
        # Check what happens when we supply a specific revision
169
        self.ls_equals('a\n', '--revision', '1')
170
        self.ls_equals('V        a\n'
171
                       , '--verbose', '--revision', '1')
172
173
        os.chdir('subdir')
174
        self.ls_equals('', '--revision', '1')
175
2215.3.3 by Aaron Bentley
Get ls working on branches
176
    def test_ls_branch(self):
177
        """If a branch is specified, files are listed from it"""
178
        self.build_tree(['subdir/', 'subdir/b'])
179
        self.wt.add(['subdir', 'subdir/b'])
180
        self.wt.commit('committing')
181
        branch = self.make_branch('branchdir')
182
        branch.pull(self.wt.branch)
183
        self.ls_equals('branchdir/subdir\n'
184
                       'branchdir/subdir/b\n',
185
                       'branchdir')
186
        self.ls_equals('branchdir/subdir\n'
187
                       'branchdir/subdir/b\n',
188
                       'branchdir', '--revision', '1')
189
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
190
    def test_ls_ignored(self):
191
        # Now try to do ignored files.
192
        self.wt.add(['a', '.bzrignore'])
193
194
        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
195
        self.ls_equals('.bzrignore\n'
1836.1.17 by John Arbash Meinel
move 'bzr ls' tests into their own file, and fix them up.
196
                       'a\n'
197
                       'blah.py\n'
198
                       'blah.pyo\n'
199
                       'user-ignore\n'
200
                       )
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
201
        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.
202
                       'V        a\n'
203
                       '?        blah.py\n'
204
                       'I        blah.pyo\n'
205
                       'I        user-ignore\n'
206
                       , '--verbose')
1987.1.1 by John Arbash Meinel
Update the test suite to put HOME in a different directory
207
        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.
208
                       'user-ignore\n'
209
                       , '--ignored')
210
        self.ls_equals('blah.py\n'
211
                       , '--unknown')
212
        self.ls_equals('.bzrignore\n'
213
                       'a\n'
214
                       , '--versioned')
215
1551.9.24 by Aaron Bentley
Unhide ls, add kind flag
216
    def test_kinds(self):
217
        self.build_tree(['subdir/'])
218
        self.ls_equals('.bzrignore\n' 
219
                       'a\n', 
220
                       '--kind=file')
221
        self.ls_equals('subdir\n',
222
                       '--kind=directory')
223
        self.ls_equals('',
224
                       '--kind=symlink')
225
        self.run_bzr_error('invalid kind specified', 'ls', '--kind=pile')