~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_ls.py

Merge Tree.changes_from work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
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
 
 
21
from bzrlib import ignores
 
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
 
31
        ignores._set_user_ignores(['./.bazaar', 'user-ignore'])
 
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)
 
42
        self.assertEqual(value, out)
 
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'"""
 
51
        self.ls_equals('.bazaar\n.bzrignore\na\n')
 
52
        self.ls_equals('I        .bazaar/\n'
 
53
                       '?        .bzrignore\n'
 
54
                       '?        a\n',
 
55
                       '--verbose')
 
56
        self.ls_equals('.bzrignore\n'
 
57
                       'a\n',
 
58
                       '--unknown')
 
59
        self.ls_equals('.bazaar\n', '--ignored')
 
60
        self.ls_equals('', '--versioned')
 
61
        self.ls_equals('.bazaar\n'
 
62
                       '.bzrignore\n'
 
63
                       'a\n',
 
64
                       '--unknown', '--ignored', '--versioned')
 
65
        self.ls_equals('.bazaar\n', '--ignored', '--versioned')
 
66
        self.ls_equals('.bazaar\0.bzrignore\0a\0', '--null')
 
67
 
 
68
    def test_ls_added(self):
 
69
        self.wt.add(['a'])
 
70
        self.ls_equals('I        .bazaar/\n'
 
71
                       '?        .bzrignore\n'
 
72
                       'V        a\n',
 
73
                       '--verbose')
 
74
        self.wt.commit('add')
 
75
        
 
76
        self.build_tree(['subdir/'])
 
77
        self.ls_equals('I        .bazaar/\n'
 
78
                       '?        .bzrignore\n'
 
79
                       'V        a\n'
 
80
                       '?        subdir/\n'
 
81
                       , '--verbose')
 
82
        self.build_tree(['subdir/b'])
 
83
        self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
 
84
        self.ls_equals('I        .bazaar/\n'
 
85
                       'V        .bzrignore\n'
 
86
                       'V        a\n'
 
87
                       'V        subdir/\n'
 
88
                       'V        subdir/b\n'
 
89
                       , '--verbose')
 
90
 
 
91
    def test_ls_recursive(self):
 
92
        self.build_tree(['subdir/', 'subdir/b'])
 
93
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
 
94
 
 
95
        self.ls_equals('.bazaar\n'
 
96
                       '.bzrignore\n'
 
97
                       'a\n'
 
98
                       'subdir\n'
 
99
                       , '--non-recursive')
 
100
 
 
101
        self.ls_equals('I        .bazaar/\n'
 
102
                       'V        .bzrignore\n'
 
103
                       'V        a\n'
 
104
                       'V        subdir/\n'
 
105
                       , '--verbose', '--non-recursive')
 
106
 
 
107
        # Check what happens in a sub-directory
 
108
        os.chdir('subdir')
 
109
        self.ls_equals('b\n')
 
110
        self.ls_equals('b\0'
 
111
                  , '--null')
 
112
        self.ls_equals('.bazaar\n'
 
113
                       '.bzrignore\n'
 
114
                       'a\n'
 
115
                       'subdir\n'
 
116
                       'subdir/b\n'
 
117
                       , '--from-root')
 
118
        self.ls_equals('.bazaar\0'
 
119
                       '.bzrignore\0'
 
120
                       'a\0'
 
121
                       'subdir\0'
 
122
                       'subdir/b\0'
 
123
                       , '--from-root', '--null')
 
124
        self.ls_equals('.bazaar\n'
 
125
                       '.bzrignore\n'
 
126
                       'a\n'
 
127
                       'subdir\n'
 
128
                       , '--from-root', '--non-recursive')
 
129
 
 
130
    def test_ls_revision(self):
 
131
        self.wt.add(['a'])
 
132
        self.wt.commit('add')
 
133
 
 
134
        self.build_tree(['subdir/'])
 
135
 
 
136
        # Check what happens when we supply a specific revision
 
137
        self.ls_equals('a\n', '--revision', '1')
 
138
        self.ls_equals('V        a\n'
 
139
                       , '--verbose', '--revision', '1')
 
140
 
 
141
        os.chdir('subdir')
 
142
        self.ls_equals('', '--revision', '1')
 
143
 
 
144
    def test_ls_ignored(self):
 
145
        # Now try to do ignored files.
 
146
        self.wt.add(['a', '.bzrignore'])
 
147
 
 
148
        self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
 
149
        self.ls_equals('.bazaar\n'
 
150
                       '.bzrignore\n'
 
151
                       'a\n'
 
152
                       'blah.py\n'
 
153
                       'blah.pyo\n'
 
154
                       'user-ignore\n'
 
155
                       )
 
156
        self.ls_equals('I        .bazaar/\n'
 
157
                       'V        .bzrignore\n'
 
158
                       'V        a\n'
 
159
                       '?        blah.py\n'
 
160
                       'I        blah.pyo\n'
 
161
                       'I        user-ignore\n'
 
162
                       , '--verbose')
 
163
        self.ls_equals('.bazaar\n'
 
164
                       'blah.pyo\n'
 
165
                       'user-ignore\n'
 
166
                       , '--ignored')
 
167
        self.ls_equals('blah.py\n'
 
168
                       , '--unknown')
 
169
        self.ls_equals('.bzrignore\n'
 
170
                       'a\n'
 
171
                       , '--versioned')
 
172