~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2009-03-24 15:47:32 UTC
  • mto: This revision was merged to the branch mainline in revision 4241.
  • Revision ID: aaron@aaronbentley.com-20090324154732-bwkvi4dx3o90a7dq
Add output, emit minimal inventory delta.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""External tests of 'bzr ls'"""
18
18
 
26
26
 
27
27
    def setUp(self):
28
28
        super(TestLS, self).setUp()
29
 
        
 
29
 
30
30
        # Create a simple branch that can be used in testing
31
 
        ignores._set_user_ignores(['./.bazaar', 'user-ignore'])
 
31
        ignores._set_user_ignores(['user-ignore'])
32
32
 
33
33
        self.wt = self.make_branch_and_tree('.')
34
34
        self.build_tree_contents([
36
36
                                 ('a', 'hello\n'),
37
37
                                 ])
38
38
 
39
 
    def ls_equals(self, value, *args):
40
 
        out, err = self.run_bzr('ls', *args)
 
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)
41
44
        self.assertEqual('', err)
42
 
        self.assertEqual(value, out)
 
45
        self.assertEqualDiff(value, out)
43
46
 
44
47
    def test_ls_null_verbose(self):
45
48
        # Can't supply both
46
49
        self.run_bzr_error(['Cannot set both --verbose and --null'],
47
 
                           'ls', '--verbose', '--null')
 
50
                           'ls --verbose --null')
48
51
 
49
52
    def test_ls_basic(self):
50
53
        """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
        self.ls_equals('.bzrignore\na\n')
 
55
        self.ls_equals('?        .bzrignore\n'
54
56
                       '?        a\n',
55
57
                       '--verbose')
56
58
        self.ls_equals('.bzrignore\n'
57
59
                       'a\n',
58
60
                       '--unknown')
59
 
        self.ls_equals('.bazaar\n', '--ignored')
 
61
        self.ls_equals('', '--ignored')
60
62
        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')
 
63
        self.ls_equals('', '-V')
 
64
        self.ls_equals('.bzrignore\n'
 
65
                       'a\n',
 
66
                       '--unknown --ignored --versioned')
 
67
        self.ls_equals('.bzrignore\n'
 
68
                       'a\n',
 
69
                       '--unknown --ignored -V')
 
70
        self.ls_equals('', '--ignored --versioned')
 
71
        self.ls_equals('', '--ignored -V')
 
72
        self.ls_equals('.bzrignore\0a\0', '--null')
67
73
 
68
74
    def test_ls_added(self):
69
75
        self.wt.add(['a'])
70
 
        self.ls_equals('I        .bazaar/\n'
71
 
                       '?        .bzrignore\n'
 
76
        self.ls_equals('?        .bzrignore\n'
72
77
                       'V        a\n',
73
78
                       '--verbose')
74
79
        self.wt.commit('add')
75
 
        
 
80
 
76
81
        self.build_tree(['subdir/'])
77
 
        self.ls_equals('I        .bazaar/\n'
78
 
                       '?        .bzrignore\n'
 
82
        self.ls_equals('?        .bzrignore\n'
79
83
                       'V        a\n'
80
84
                       '?        subdir/\n'
81
85
                       , '--verbose')
82
86
        self.build_tree(['subdir/b'])
83
87
        self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
84
 
        self.ls_equals('I        .bazaar/\n'
85
 
                       'V        .bzrignore\n'
 
88
        self.ls_equals('V        .bzrignore\n'
86
89
                       'V        a\n'
87
90
                       'V        subdir/\n'
88
91
                       'V        subdir/b\n'
89
92
                       , '--verbose')
90
93
 
 
94
    def test_show_ids(self):
 
95
        self.build_tree(['subdir/'])
 
96
        self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
 
97
        self.ls_equals(
 
98
            '.bzrignore                                         \n'
 
99
            'a                                                  a-id\n'
 
100
            'subdir/                                            subdir-id\n',
 
101
            '--show-ids')
 
102
        self.ls_equals(
 
103
            '?        .bzrignore\n'
 
104
            'V        a                                         a-id\n'
 
105
            'V        subdir/                                   subdir-id\n',
 
106
            '--show-ids --verbose')
 
107
        self.ls_equals('.bzrignore\0\0'
 
108
                       'a\0a-id\0'
 
109
                       'subdir\0subdir-id\0', '--show-ids --null')
 
110
 
91
111
    def test_ls_recursive(self):
92
112
        self.build_tree(['subdir/', 'subdir/b'])
93
113
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
94
114
 
95
 
        self.ls_equals('.bazaar\n'
96
 
                       '.bzrignore\n'
 
115
        self.ls_equals('.bzrignore\n'
97
116
                       'a\n'
98
 
                       'subdir\n'
 
117
                       'subdir/\n'
99
118
                       , '--non-recursive')
100
119
 
101
 
        self.ls_equals('I        .bazaar/\n'
102
 
                       'V        .bzrignore\n'
 
120
        self.ls_equals('V        .bzrignore\n'
103
121
                       'V        a\n'
104
122
                       'V        subdir/\n'
105
 
                       , '--verbose', '--non-recursive')
 
123
                       , '--verbose --non-recursive')
106
124
 
107
125
        # Check what happens in a sub-directory
108
126
        os.chdir('subdir')
109
127
        self.ls_equals('b\n')
110
128
        self.ls_equals('b\0'
111
129
                  , '--null')
112
 
        self.ls_equals('.bazaar\n'
113
 
                       '.bzrignore\n'
 
130
        self.ls_equals('.bzrignore\n'
114
131
                       'a\n'
115
 
                       'subdir\n'
 
132
                       'subdir/\n'
116
133
                       'subdir/b\n'
117
134
                       , '--from-root')
118
 
        self.ls_equals('.bazaar\0'
119
 
                       '.bzrignore\0'
 
135
        self.ls_equals('.bzrignore\0'
120
136
                       'a\0'
121
137
                       'subdir\0'
122
138
                       'subdir/b\0'
123
 
                       , '--from-root', '--null')
124
 
        self.ls_equals('.bazaar\n'
125
 
                       '.bzrignore\n'
 
139
                       , '--from-root --null')
 
140
        self.ls_equals('.bzrignore\n'
126
141
                       'a\n'
127
 
                       'subdir\n'
128
 
                       , '--from-root', '--non-recursive')
 
142
                       'subdir/\n'
 
143
                       , '--from-root --non-recursive')
 
144
 
 
145
    def test_ls_path(self):
 
146
        """If a path is specified, files are listed with that prefix"""
 
147
        self.build_tree(['subdir/', 'subdir/b'])
 
148
        self.wt.add(['subdir', 'subdir/b'])
 
149
        self.ls_equals('subdir/b\n' ,
 
150
                       'subdir')
 
151
        os.chdir('subdir')
 
152
        self.ls_equals('../.bzrignore\n'
 
153
                       '../a\n'
 
154
                       '../subdir/\n'
 
155
                       '../subdir/b\n' ,
 
156
                       '..')
 
157
        self.ls_equals('../.bzrignore\0'
 
158
                       '../a\0'
 
159
                       '../subdir\0'
 
160
                       '../subdir/b\0' ,
 
161
                       '.. --null')
 
162
        self.ls_equals('?        ../.bzrignore\n'
 
163
                       '?        ../a\n'
 
164
                       'V        ../subdir/\n'
 
165
                       'V        ../subdir/b\n' ,
 
166
                       '.. --verbose')
 
167
        self.run_bzr_error('cannot specify both --from-root and PATH',
 
168
                           'ls --from-root ..')
129
169
 
130
170
    def test_ls_revision(self):
131
171
        self.wt.add(['a'])
134
174
        self.build_tree(['subdir/'])
135
175
 
136
176
        # Check what happens when we supply a specific revision
137
 
        self.ls_equals('a\n', '--revision', '1')
 
177
        self.ls_equals('a\n', '--revision 1')
138
178
        self.ls_equals('V        a\n'
139
 
                       , '--verbose', '--revision', '1')
 
179
                       , '--verbose --revision 1')
140
180
 
141
181
        os.chdir('subdir')
142
 
        self.ls_equals('', '--revision', '1')
 
182
        self.ls_equals('', '--revision 1')
 
183
 
 
184
    def test_ls_branch(self):
 
185
        """If a branch is specified, files are listed from it"""
 
186
        self.build_tree(['subdir/', 'subdir/b'])
 
187
        self.wt.add(['subdir', 'subdir/b'])
 
188
        self.wt.commit('committing')
 
189
        branch = self.make_branch('branchdir')
 
190
        branch.pull(self.wt.branch)
 
191
        self.ls_equals('branchdir/subdir/\n'
 
192
                       'branchdir/subdir/b\n',
 
193
                       'branchdir')
 
194
        self.ls_equals('branchdir/subdir/\n'
 
195
                       'branchdir/subdir/b\n',
 
196
                       'branchdir --revision 1')
143
197
 
144
198
    def test_ls_ignored(self):
145
199
        # Now try to do ignored files.
146
200
        self.wt.add(['a', '.bzrignore'])
147
201
 
148
202
        self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
149
 
        self.ls_equals('.bazaar\n'
150
 
                       '.bzrignore\n'
 
203
        self.ls_equals('.bzrignore\n'
151
204
                       'a\n'
152
205
                       'blah.py\n'
153
206
                       'blah.pyo\n'
154
207
                       'user-ignore\n'
155
208
                       )
156
 
        self.ls_equals('I        .bazaar/\n'
157
 
                       'V        .bzrignore\n'
 
209
        self.ls_equals('V        .bzrignore\n'
158
210
                       'V        a\n'
159
211
                       '?        blah.py\n'
160
212
                       'I        blah.pyo\n'
161
213
                       'I        user-ignore\n'
162
214
                       , '--verbose')
163
 
        self.ls_equals('.bazaar\n'
164
 
                       'blah.pyo\n'
 
215
        self.ls_equals('blah.pyo\n'
165
216
                       'user-ignore\n'
166
217
                       , '--ignored')
167
218
        self.ls_equals('blah.py\n'
169
220
        self.ls_equals('.bzrignore\n'
170
221
                       'a\n'
171
222
                       , '--versioned')
 
223
        self.ls_equals('.bzrignore\n'
 
224
                       'a\n'
 
225
                       , '-V')
172
226
 
 
227
    def test_kinds(self):
 
228
        self.build_tree(['subdir/'])
 
229
        self.ls_equals('.bzrignore\n'
 
230
                       'a\n',
 
231
                       '--kind=file')
 
232
        self.ls_equals('subdir/\n',
 
233
                       '--kind=directory')
 
234
        self.ls_equals('',
 
235
                       '--kind=symlink')
 
236
        self.run_bzr_error('invalid kind specified', 'ls --kind=pile')