~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Copyright (C) 2006 by Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

"""External tests of 'bzr ls'"""

import os

from bzrlib import ignores
from bzrlib.tests import TestCaseWithTransport


class TestLS(TestCaseWithTransport):

    def setUp(self):
        super(TestLS, self).setUp()
        
        # Create a simple branch that can be used in testing
        ignores._set_user_ignores(['./.bazaar', 'user-ignore'])

        self.wt = self.make_branch_and_tree('.')
        self.build_tree_contents([
                                 ('.bzrignore', '*.pyo\n'),
                                 ('a', 'hello\n'),
                                 ])

    def ls_equals(self, value, *args):
        out, err = self.run_bzr('ls', *args)
        self.assertEqual('', err)
        self.assertEqual(value, out)

    def test_ls_null_verbose(self):
        # Can't supply both
        self.run_bzr_error(['Cannot set both --verbose and --null'],
                           'ls', '--verbose', '--null')

    def test_ls_basic(self):
        """Test the abilities of 'bzr ls'"""
        self.ls_equals('.bazaar\n.bzrignore\na\n')
        self.ls_equals('I        .bazaar/\n'
                       '?        .bzrignore\n'
                       '?        a\n',
                       '--verbose')
        self.ls_equals('.bzrignore\n'
                       'a\n',
                       '--unknown')
        self.ls_equals('.bazaar\n', '--ignored')
        self.ls_equals('', '--versioned')
        self.ls_equals('.bazaar\n'
                       '.bzrignore\n'
                       'a\n',
                       '--unknown', '--ignored', '--versioned')
        self.ls_equals('.bazaar\n', '--ignored', '--versioned')
        self.ls_equals('.bazaar\0.bzrignore\0a\0', '--null')

    def test_ls_added(self):
        self.wt.add(['a'])
        self.ls_equals('I        .bazaar/\n'
                       '?        .bzrignore\n'
                       'V        a\n',
                       '--verbose')
        self.wt.commit('add')
        
        self.build_tree(['subdir/'])
        self.ls_equals('I        .bazaar/\n'
                       '?        .bzrignore\n'
                       'V        a\n'
                       '?        subdir/\n'
                       , '--verbose')
        self.build_tree(['subdir/b'])
        self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
        self.ls_equals('I        .bazaar/\n'
                       'V        .bzrignore\n'
                       'V        a\n'
                       'V        subdir/\n'
                       'V        subdir/b\n'
                       , '--verbose')

    def test_ls_recursive(self):
        self.build_tree(['subdir/', 'subdir/b'])
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])

        self.ls_equals('.bazaar\n'
                       '.bzrignore\n'
                       'a\n'
                       'subdir\n'
                       , '--non-recursive')

        self.ls_equals('I        .bazaar/\n'
                       'V        .bzrignore\n'
                       'V        a\n'
                       'V        subdir/\n'
                       , '--verbose', '--non-recursive')

        # Check what happens in a sub-directory
        os.chdir('subdir')
        self.ls_equals('b\n')
        self.ls_equals('b\0'
                  , '--null')
        self.ls_equals('.bazaar\n'
                       '.bzrignore\n'
                       'a\n'
                       'subdir\n'
                       'subdir/b\n'
                       , '--from-root')
        self.ls_equals('.bazaar\0'
                       '.bzrignore\0'
                       'a\0'
                       'subdir\0'
                       'subdir/b\0'
                       , '--from-root', '--null')
        self.ls_equals('.bazaar\n'
                       '.bzrignore\n'
                       'a\n'
                       'subdir\n'
                       , '--from-root', '--non-recursive')

    def test_ls_revision(self):
        self.wt.add(['a'])
        self.wt.commit('add')

        self.build_tree(['subdir/'])

        # Check what happens when we supply a specific revision
        self.ls_equals('a\n', '--revision', '1')
        self.ls_equals('V        a\n'
                       , '--verbose', '--revision', '1')

        os.chdir('subdir')
        self.ls_equals('', '--revision', '1')

    def test_ls_ignored(self):
        # Now try to do ignored files.
        self.wt.add(['a', '.bzrignore'])

        self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
        self.ls_equals('.bazaar\n'
                       '.bzrignore\n'
                       'a\n'
                       'blah.py\n'
                       'blah.pyo\n'
                       'user-ignore\n'
                       )
        self.ls_equals('I        .bazaar/\n'
                       'V        .bzrignore\n'
                       'V        a\n'
                       '?        blah.py\n'
                       'I        blah.pyo\n'
                       'I        user-ignore\n'
                       , '--verbose')
        self.ls_equals('.bazaar\n'
                       'blah.pyo\n'
                       'user-ignore\n'
                       , '--ignored')
        self.ls_equals('blah.py\n'
                       , '--unknown')
        self.ls_equals('.bzrignore\n'
                       'a\n'
                       , '--versioned')