/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

First attempt to merge .dev and resolve the conflicts (but tests are 
failing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
2
 
# -*- coding: utf-8 -*-
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
48
47
        bzrlib.user_encoding = self._orig_encoding
49
48
        super(TestNonAscii, self).tearDown()
50
49
 
 
50
    def run_bzr_decode(self, args, encoding=None, fail=False, retcode=None,
 
51
                        working_dir=None):
 
52
        """Run bzr and decode the output into a particular encoding.
 
53
 
 
54
        Returns a string containing the stdout output from bzr.
 
55
 
 
56
        :param fail: If true, the operation is expected to fail with 
 
57
            a UnicodeError.
 
58
        """
 
59
        if encoding is None:
 
60
            encoding = bzrlib.user_encoding
 
61
        try:
 
62
            out = self.run_bzr(args, output_encoding=encoding, encoding=encoding,
 
63
                retcode=retcode, working_dir=working_dir)[0]
 
64
            return out.decode(encoding)
 
65
        except UnicodeError, e:
 
66
            if not fail:
 
67
                raise
 
68
        else:
 
69
            # This command, run from the regular command line, will give a
 
70
            # traceback to the user.  That's not really good for a situation
 
71
            # that can be provoked just by the interaction of their input data
 
72
            # and locale, as some of these are.  What would be better?
 
73
            if fail:
 
74
                self.fail("Expected UnicodeError not raised")
 
75
 
51
76
    def create_base(self):
52
 
        bzr = self.run_bzr
53
 
 
54
77
        fs_enc = sys.getfilesystemencoding()
55
78
        terminal_enc = osutils.get_terminal_encoding()
56
79
        fname = self.info['filename']
72
95
                                   % (thing, terminal_enc, fs_enc))
73
96
 
74
97
        wt = self.make_branch_and_tree('.')
75
 
        open('a', 'wb').write('foo\n')
 
98
        self.build_tree_contents([('a', 'foo\n')])
76
99
        wt.add('a')
77
100
        wt.commit('adding a')
78
101
 
79
 
        open('b', 'wb').write('non-ascii \xFF\xFF\xFC\xFB\x00 in b\n')
 
102
        self.build_tree_contents(
 
103
            [('b', 'non-ascii \xFF\xFF\xFC\xFB\x00 in b\n')])
80
104
        wt.add('b')
81
105
        wt.commit(self.info['message'])
82
106
 
83
 
        open(fname, 'wb').write('unicode filename\n')
 
107
        self.build_tree_contents([(fname, 'unicode filename\n')])
84
108
        wt.add(fname)
85
109
        wt.commit(u'And a unicode file\n')
86
110
        self.wt = wt
87
111
 
88
112
    def test_status(self):
89
 
        bzr = self.run_bzr_decode
90
 
 
91
 
        open(self.info['filename'], 'ab').write('added something\n')
92
 
        txt = bzr('status')
 
113
        self.build_tree_contents(
 
114
            [(self.info['filename'], 'changed something\n')])
 
115
        txt = self.run_bzr_decode('status')
93
116
        self.assertEqual(u'modified:\n  %s\n' % (self.info['filename'],), txt)
94
117
 
95
 
        txt = bzr('status', encoding='ascii')
 
118
        txt = self.run_bzr_decode('status', encoding='ascii')
96
119
        expected = u'modified:\n  %s\n' % (
97
120
                    self.info['filename'].encode('ascii', 'replace'),)
98
121
        self.assertEqual(expected, txt)
100
123
    def test_cat(self):
101
124
        # bzr cat shouldn't change the contents
102
125
        # using run_bzr since that doesn't decode
103
 
        txt = self.run_bzr('cat', 'b')[0]
 
126
        txt = self.run_bzr('cat b')[0]
104
127
        self.assertEqual('non-ascii \xFF\xFF\xFC\xFB\x00 in b\n', txt)
105
128
 
106
 
        txt = self.run_bzr('cat', self.info['filename'])[0]
 
129
        txt = self.run_bzr(['cat', self.info['filename']])[0]
107
130
        self.assertEqual('unicode filename\n', txt)
108
131
 
109
132
    def test_cat_revision(self):
110
 
        bzr = self.run_bzr_decode
111
 
 
112
133
        committer = self.info['committer']
113
 
        txt = bzr('cat-revision', '-r', '1')
 
134
        txt = self.run_bzr_decode('cat-revision -r 1')
114
135
        self.failUnless(committer in txt,
115
136
                        'failed to find %r in %r' % (committer, txt))
116
137
 
117
138
        msg = self.info['message']
118
 
        txt = bzr('cat-revision', '-r', '2')
 
139
        txt = self.run_bzr_decode('cat-revision -r 2')
119
140
        self.failUnless(msg in txt, 'failed to find %r in %r' % (msg, txt))
120
141
 
121
142
    def test_mkdir(self):
122
 
        bzr = self.run_bzr_decode
123
 
 
124
 
        txt = bzr('mkdir', self.info['directory'])
 
143
        txt = self.run_bzr_decode(['mkdir', self.info['directory']])
125
144
        self.assertEqual(u'added %s\n' % self.info['directory'], txt)
126
145
 
127
146
        # The text should be garbled, but the command should succeed
128
 
        txt = bzr('mkdir', self.info['directory'] + '2', encoding='ascii')
 
147
        txt = self.run_bzr_decode(['mkdir', self.info['directory'] + '2'],
 
148
                                  encoding='ascii')
129
149
        expected = u'added %s2\n' % (self.info['directory'],)
130
150
        expected = expected.encode('ascii', 'replace')
131
151
        self.assertEqual(expected, txt)
132
152
 
133
153
    def test_relpath(self):
134
 
        bzr = self.run_bzr_decode
135
 
 
136
 
        txt = bzr('relpath', self.info['filename'])
 
154
        txt = self.run_bzr_decode(['relpath', self.info['filename']])
137
155
        self.assertEqual(self.info['filename'] + '\n', txt)
138
156
 
139
 
        bzr('relpath', self.info['filename'], encoding='ascii', retcode=3)
 
157
        self.run_bzr_decode(['relpath', self.info['filename']],
 
158
                            encoding='ascii', fail=True)
140
159
 
141
160
    def test_inventory(self):
142
 
        bzr = self.run_bzr_decode
143
 
 
144
 
        txt = bzr('inventory')
 
161
        txt = self.run_bzr_decode('inventory')
145
162
        self.assertEqual(['a', 'b', self.info['filename']],
146
163
                         txt.splitlines())
147
164
 
148
165
        # inventory should fail if unable to encode
149
 
        bzr('inventory', encoding='ascii', retcode=3)
 
166
        self.run_bzr_decode('inventory', encoding='ascii', fail=True)
150
167
 
151
168
        # We don't really care about the ids themselves,
152
169
        # but the command shouldn't fail
153
 
        txt = bzr('inventory', '--show-ids')
 
170
        txt = self.run_bzr_decode('inventory --show-ids')
154
171
 
155
172
    def test_revno(self):
156
173
        # There isn't a lot to test here, since revno should always
157
174
        # be an integer
158
 
        bzr = self.run_bzr_decode
159
 
 
160
 
        self.assertEqual('3\n', bzr('revno'))
161
 
        self.assertEqual('3\n', bzr('revno', encoding='ascii'))
 
175
        self.assertEqual('3\n', self.run_bzr_decode('revno'))
 
176
        self.assertEqual('3\n', self.run_bzr_decode('revno', encoding='ascii'))
162
177
 
163
178
    def test_revision_info(self):
164
 
        bzr = self.run_bzr_decode
165
 
 
166
 
        bzr('revision-info', '-r', '1')
 
179
        self.run_bzr_decode('revision-info -r 1')
167
180
 
168
181
        # TODO: jam 20060105 If we support revisions with non-ascii characters,
169
182
        # this should be strict and fail.
170
 
        bzr('revision-info', '-r', '1', encoding='ascii')
 
183
        self.run_bzr_decode('revision-info -r 1', encoding='ascii')
171
184
 
172
185
    def test_mv(self):
173
 
        bzr = self.run_bzr_decode
174
 
 
175
186
        fname1 = self.info['filename']
176
187
        fname2 = self.info['filename'] + '2'
177
188
        dirname = self.info['directory']
178
189
 
179
190
        # fname1 already exists
180
 
        bzr('mv', 'a', fname1, retcode=3)
 
191
        self.run_bzr_decode(['mv', 'a', fname1], fail=True)
181
192
 
182
 
        txt = bzr('mv', 'a', fname2)
 
193
        txt = self.run_bzr_decode(['mv', 'a', fname2])
183
194
        self.assertEqual(u'a => %s\n' % fname2, txt)
184
195
        self.failIfExists('a')
185
196
        self.failUnlessExists(fname2)
190
201
 
191
202
        os.mkdir(dirname)
192
203
        self.wt.add(dirname)
193
 
        txt = bzr('mv', fname1, fname2, dirname)
 
204
        txt = self.run_bzr_decode(['mv', fname1, fname2, dirname])
194
205
        self.assertEqual([u'%s => %s/%s' % (fname1, dirname, fname1),
195
206
                          u'%s => %s/%s' % (fname2, dirname, fname2)]
196
207
                         , txt.splitlines())
197
208
 
198
209
        # The rename should still succeed
199
210
        newpath = u'%s/%s' % (dirname, fname2)
200
 
        txt = bzr('mv', newpath, 'a', encoding='ascii')
 
211
        txt = self.run_bzr_decode(['mv', newpath, 'a'], encoding='ascii')
201
212
        self.failUnlessExists('a')
202
213
        self.assertEqual(newpath.encode('ascii', 'replace') + ' => a\n', txt)
203
214
 
204
215
    def test_branch(self):
205
216
        # We should be able to branch into a directory that
206
217
        # has a unicode name, even if we can't display the name
207
 
        bzr = self.run_bzr_decode
208
 
        bzr('branch', u'.', self.info['directory'])
209
 
        bzr('branch', u'.', self.info['directory'] + '2', encoding='ascii')
 
218
        self.run_bzr_decode(['branch', u'.', self.info['directory']])
 
219
        self.run_bzr_decode(['branch', u'.', self.info['directory'] + '2'],
 
220
                            encoding='ascii')
210
221
 
211
222
    def test_pull(self):
212
223
        # Make sure we can pull from paths that can't be encoded
213
 
        bzr = self.run_bzr_decode
214
 
 
215
224
        dirname1 = self.info['directory']
216
225
        dirname2 = self.info['directory'] + '2'
217
226
        url1 = urlutils.local_path_to_url(dirname1)
219
228
        out_bzrdir = self.wt.bzrdir.sprout(url1)
220
229
        out_bzrdir.sprout(url2)
221
230
 
222
 
        os.chdir(dirname1)
223
 
        open('a', 'ab').write('more text\n')
 
231
        self.build_tree_contents(
 
232
            [(osutils.pathjoin(dirname1, "a"), 'different text\n')])
224
233
        self.wt.commit('mod a')
225
234
 
226
 
        pwd = osutils.getcwd()
227
 
 
228
 
        os.chdir(u'../' + dirname2)
229
 
        txt = bzr('pull')
230
 
 
231
 
        self.assertEqual(u'Using saved location: %s/\n' % (pwd,), txt)
232
 
 
233
 
        os.chdir('../' + dirname1)
234
 
        open('a', 'ab').write('and yet more\n')
 
235
        txt = self.run_bzr_decode('pull', working_dir=dirname2)
 
236
 
 
237
        expected = osutils.pathjoin(osutils.getcwd(), dirname1)
 
238
        self.assertEqual(u'Using saved location: %s/\n'
 
239
                'No revisions to pull.\n' % (expected,), txt)
 
240
 
 
241
        self.build_tree_contents(
 
242
            [(osutils.pathjoin(dirname1, 'a'), 'and yet more\n')])
235
243
        self.wt.commit(u'modifying a by ' + self.info['committer'])
236
244
 
237
 
        os.chdir('../' + dirname2)
238
245
        # We should be able to pull, even if our encoding is bad
239
 
        bzr('pull', '--verbose', encoding='ascii')
 
246
        self.run_bzr_decode('pull --verbose', encoding='ascii',
 
247
                            working_dir=dirname2)
240
248
 
241
249
    def test_push(self):
242
250
        # TODO: Test push to an SFTP location
243
251
        # Make sure we can pull from paths that can't be encoded
244
 
        bzr = self.run_bzr_decode
245
 
 
246
252
        # TODO: jam 20060427 For drastically improving performance, we probably
247
253
        #       could create a local repository, so it wouldn't have to copy
248
254
        #       the files around as much.
249
255
 
250
256
        dirname = self.info['directory']
251
 
        bzr('push', dirname)
 
257
        self.run_bzr_decode(['push', dirname])
252
258
 
253
 
        open('a', 'ab').write('adding more text\n')
 
259
        self.build_tree_contents([('a', 'adding more text\n')])
254
260
        self.wt.commit('added some stuff')
255
261
 
256
262
        # TODO: check the output text is properly encoded
257
 
        bzr('push')
 
263
        self.run_bzr_decode('push')
258
264
 
259
 
        f = open('a', 'ab')
260
 
        try:
261
 
            f.write('and a bit more: ')
262
 
            f.write(dirname.encode('utf-8'))
263
 
            f.write('\n')
264
 
        finally:
265
 
            f.close()
 
265
        self.build_tree_contents(
 
266
            [('a', 'and a bit more: \n%s\n' % (dirname.encode('utf-8'),))])
266
267
 
267
268
        self.wt.commit('Added some ' + dirname)
268
 
        bzr('push', '--verbose', encoding='ascii')
269
 
 
270
 
        bzr('push', '--verbose', dirname + '2')
271
 
 
272
 
        bzr('push', '--verbose', dirname + '3', encoding='ascii')
273
 
 
274
 
        bzr('push', '--verbose', '--create-prefix', dirname + '4/' + dirname + '5')
275
 
        bzr('push', '--verbose', '--create-prefix', dirname + '6/' + dirname + '7', encoding='ascii')
 
269
        self.run_bzr_decode('push --verbose', encoding='ascii')
 
270
 
 
271
        self.run_bzr_decode(['push', '--verbose', dirname + '2'])
 
272
 
 
273
        self.run_bzr_decode(['push', '--verbose', dirname + '3'],
 
274
                            encoding='ascii')
 
275
 
 
276
        self.run_bzr_decode(['push', '--verbose', '--create-prefix',
 
277
                            dirname + '4/' + dirname + '5'])
 
278
        self.run_bzr_decode(['push', '--verbose', '--create-prefix',
 
279
                            dirname + '6/' + dirname + '7'], encoding='ascii')
276
280
 
277
281
    def test_renames(self):
278
 
        bzr = self.run_bzr_decode
279
 
 
280
282
        fname = self.info['filename'] + '2'
281
 
        bzr('mv', 'a', fname)
282
 
        txt = bzr('renames')
 
283
        self.wt.rename_one('a', fname)
 
284
        txt = self.run_bzr_decode('renames')
283
285
        self.assertEqual(u'a => %s\n' % fname, txt)
284
286
 
285
 
        bzr('renames', retcode=3, encoding='ascii')
 
287
        self.run_bzr_decode('renames', fail=True, encoding='ascii')
286
288
 
287
289
    def test_remove(self):
288
 
        bzr = self.run_bzr_decode
289
 
 
290
290
        fname = self.info['filename']
291
 
        txt = bzr('remove', fname, encoding='ascii')
 
291
        txt = self.run_bzr_decode(['remove', fname], encoding='ascii')
292
292
 
293
293
    def test_remove_verbose(self):
294
 
        bzr = self.run_bzr_decode
295
 
 
296
294
        fname = self.info['filename']
297
 
        txt = bzr('remove', '--verbose', fname, encoding='ascii')
 
295
        txt = self.run_bzr_decode(['remove', '--verbose', fname],
 
296
                                  encoding='ascii')
298
297
 
299
298
    def test_file_id(self):
300
 
        bzr = self.run_bzr_decode
301
 
 
302
299
        fname = self.info['filename']
303
 
        txt = bzr('file-id', fname)
 
300
        txt = self.run_bzr_decode(['file-id', fname])
304
301
 
305
302
        # TODO: jam 20060106 We don't support non-ascii file ids yet, 
306
303
        #       so there is nothing which would fail in ascii encoding
307
304
        #       This *should* be retcode=3
308
 
        txt = bzr('file-id', fname, encoding='ascii')
 
305
        txt = self.run_bzr_decode(['file-id', fname], encoding='ascii')
309
306
 
310
307
    def test_file_path(self):
311
 
        bzr = self.run_bzr_decode
312
 
 
313
308
        # Create a directory structure
314
309
        fname = self.info['filename']
315
310
        dirname = self.info['directory']
316
 
        os.mkdir('base')
317
 
        os.mkdir('base/' + dirname)
 
311
        self.build_tree_contents([
 
312
            ('base/', ),
 
313
            (osutils.pathjoin('base', '%s/' % (dirname,)), )])
318
314
        self.wt.add('base')
319
315
        self.wt.add('base/'+dirname)
320
 
        path = '/'.join(['base', dirname, fname])
 
316
        path = osutils.pathjoin('base', dirname, fname)
321
317
        self.wt.rename_one(fname, path)
322
318
        self.wt.commit('moving things around')
323
319
 
324
 
        txt = bzr('file-path', path)
 
320
        txt = self.run_bzr_decode(['file-path', path])
325
321
 
326
322
        # TODO: jam 20060106 We don't support non-ascii file ids yet, 
327
323
        #       so there is nothing which would fail in ascii encoding
328
324
        #       This *should* be retcode=3
329
 
        txt = bzr('file-path', path, encoding='ascii')
 
325
        txt = self.run_bzr_decode(['file-path', path], encoding='ascii')
330
326
 
331
327
    def test_revision_history(self):
332
 
        bzr = self.run_bzr_decode
333
 
 
334
328
        # TODO: jam 20060106 We don't support non-ascii revision ids yet, 
335
329
        #       so there is nothing which would fail in ascii encoding
336
 
        txt = bzr('revision-history')
 
330
        txt = self.run_bzr_decode('revision-history')
337
331
 
338
332
    def test_ancestry(self):
339
 
        bzr = self.run_bzr_decode
340
 
 
341
333
        # TODO: jam 20060106 We don't support non-ascii revision ids yet, 
342
334
        #       so there is nothing which would fail in ascii encoding
343
 
        txt = bzr('ancestry')
 
335
        txt = self.run_bzr_decode('ancestry')
344
336
 
345
337
    def test_diff(self):
346
338
        # TODO: jam 20060106 diff is a difficult one to test, because it 
347
339
        #       shouldn't encode the file contents, but it needs some sort
348
340
        #       of encoding for the paths, etc which are displayed.
349
 
        open(self.info['filename'], 'ab').write('newline\n')
 
341
        self.build_tree_contents([(self.info['filename'], 'newline\n')])
350
342
        txt = self.run_bzr('diff', retcode=1)[0]
351
343
 
352
344
    def test_deleted(self):
353
 
        bzr = self.run_bzr_decode
354
 
 
355
345
        fname = self.info['filename']
356
346
        os.remove(fname)
357
347
        self.wt.remove(fname)
358
348
 
359
 
        txt = bzr('deleted')
 
349
        txt = self.run_bzr_decode('deleted')
360
350
        self.assertEqual(fname+'\n', txt)
361
351
 
362
 
        txt = bzr('deleted', '--show-ids')
 
352
        txt = self.run_bzr_decode('deleted --show-ids')
363
353
        self.failUnless(txt.startswith(fname))
364
354
 
365
355
        # Deleted should fail if cannot decode
366
356
        # Because it is giving the exact paths
367
357
        # which might be used by a front end
368
 
        bzr('deleted', encoding='ascii', retcode=3)
 
358
        self.run_bzr_decode('deleted', encoding='ascii', fail=True)
369
359
 
370
360
    def test_modified(self):
371
 
        bzr = self.run_bzr_decode
372
 
 
373
361
        fname = self.info['filename']
374
 
        open(fname, 'ab').write('modified\n')
375
 
 
376
 
        txt = bzr('modified')
377
 
        self.assertEqual(fname+'\n', txt)
378
 
 
379
 
        bzr('modified', encoding='ascii', retcode=3)
 
362
        self.build_tree_contents([(fname, 'modified\n')])
 
363
 
 
364
        txt = self.run_bzr_decode('modified')
 
365
        self.assertEqual('"'+fname+'"'+'\n', txt)
 
366
 
 
367
        self.run_bzr_decode('modified', encoding='ascii', fail=True)
380
368
 
381
369
    def test_added(self):
382
 
        bzr = self.run_bzr_decode
383
 
 
384
370
        fname = self.info['filename'] + '2'
385
 
        open(fname, 'wb').write('added\n')
 
371
        self.build_tree_contents([(fname, 'added\n')])
386
372
        self.wt.add(fname)
387
373
 
388
 
        txt = bzr('added')
389
 
        self.assertEqual(fname+'\n', txt)
 
374
        txt = self.run_bzr_decode('added')
 
375
        self.assertEqual('"'+fname+'"'+'\n', txt)
390
376
 
391
 
        bzr('added', encoding='ascii', retcode=3)
 
377
        self.run_bzr_decode('added', encoding='ascii', fail=True)
392
378
 
393
379
    def test_root(self):
394
 
        bzr = self.run_bzr_decode
395
 
 
396
380
        dirname = self.info['directory']
397
381
        url = urlutils.local_path_to_url(dirname)
398
 
        bzr('root')
 
382
        self.run_bzr_decode('root')
399
383
 
400
384
        self.wt.bzrdir.sprout(url)
401
385
 
402
 
        os.chdir(dirname)
403
 
 
404
 
        txt = bzr('root')
 
386
        txt = self.run_bzr_decode('root', working_dir=dirname)
405
387
        self.failUnless(txt.endswith(dirname+'\n'))
406
388
 
407
 
        txt = bzr('root', encoding='ascii', retcode=3)
 
389
        txt = self.run_bzr_decode('root', encoding='ascii', fail=True,
 
390
                                  working_dir=dirname)
408
391
 
409
392
    def test_log(self):
410
 
        bzr = self.run_bzr_decode
411
 
 
412
393
        fname = self.info['filename']
413
394
 
414
 
        txt = bzr('log')
 
395
        txt = self.run_bzr_decode('log')
415
396
        self.assertNotEqual(-1, txt.find(self.info['committer']))
416
397
        self.assertNotEqual(-1, txt.find(self.info['message']))
417
398
 
418
 
        txt = bzr('log', '--verbose')
 
399
        txt = self.run_bzr_decode('log --verbose')
419
400
        self.assertNotEqual(-1, txt.find(fname))
420
401
 
421
402
        # Make sure log doesn't fail even if we can't write out
422
 
        txt = bzr('log', '--verbose', encoding='ascii')
 
403
        txt = self.run_bzr_decode('log --verbose', encoding='ascii')
423
404
        self.assertEqual(-1, txt.find(fname))
424
405
        self.assertNotEqual(-1, txt.find(fname.encode('ascii', 'replace')))
425
406
 
426
407
    def test_touching_revisions(self):
427
 
        bzr = self.run_bzr_decode
428
 
 
429
408
        fname = self.info['filename']
430
 
        txt = bzr('touching-revisions', fname)
 
409
        txt = self.run_bzr_decode(['touching-revisions', fname])
431
410
        self.assertEqual(u'     3 added %s\n' % (fname,), txt)
432
411
 
433
412
        fname2 = self.info['filename'] + '2'
434
413
        self.wt.rename_one(fname, fname2)
435
414
        self.wt.commit(u'Renamed %s => %s' % (fname, fname2))
436
415
 
437
 
        txt = bzr('touching-revisions', fname2)
 
416
        txt = self.run_bzr_decode(['touching-revisions', fname2])
438
417
        expected_txt = (u'     3 added %s\n' 
439
418
                        u'     4 renamed %s => %s\n'
440
419
                        % (fname, fname, fname2))
441
420
        self.assertEqual(expected_txt, txt)
442
421
 
443
 
        bzr('touching-revisions', fname2, encoding='ascii', retcode=3)
 
422
        self.run_bzr_decode(['touching-revisions', fname2], encoding='ascii',
 
423
                            fail=True)
444
424
 
445
425
    def test_ls(self):
446
 
        bzr = self.run_bzr_decode
447
 
 
448
 
        txt = bzr('ls')
 
426
        txt = self.run_bzr_decode('ls')
449
427
        self.assertEqual(sorted(['a', 'b', self.info['filename']]),
450
428
                         sorted(txt.splitlines()))
451
 
        txt = bzr('ls', '--null')
 
429
        txt = self.run_bzr_decode('ls --null')
452
430
        self.assertEqual(sorted(['', 'a', 'b', self.info['filename']]),
453
431
                         sorted(txt.split('\0')))
454
432
 
455
 
        txt = bzr('ls', encoding='ascii', retcode=3)
456
 
        txt = bzr('ls', '--null', encoding='ascii', retcode=3)
 
433
        txt = self.run_bzr_decode('ls', encoding='ascii', fail=True)
 
434
        txt = self.run_bzr_decode('ls --null', encoding='ascii', fail=True)
457
435
 
458
436
    def test_unknowns(self):
459
 
        bzr = self.run_bzr_decode
460
 
 
461
437
        fname = self.info['filename'] + '2'
462
 
        open(fname, 'wb').write('unknown\n')
 
438
        self.build_tree_contents([(fname, 'unknown\n')])
463
439
 
464
440
        # TODO: jam 20060112 bzr unknowns is the only one which 
465
441
        #       quotes paths do we really want it to?
466
 
        txt = bzr('unknowns')
 
442
        #       awilkins 20080521 added and modified do it now as well
 
443
        txt = self.run_bzr_decode('unknowns')
467
444
        self.assertEqual(u'"%s"\n' % (fname,), txt)
468
445
 
469
 
        bzr('unknowns', encoding='ascii', retcode=3)
 
446
        self.run_bzr_decode('unknowns', encoding='ascii', fail=True)
470
447
 
471
448
    def test_ignore(self):
472
 
        bzr = self.run_bzr_decode
473
 
 
474
449
        fname2 = self.info['filename'] + '2.txt'
475
 
        open(fname2, 'wb').write('ignored\n')
 
450
        self.build_tree_contents([(fname2, 'ignored\n')])
476
451
 
477
452
        def check_unknowns(expected):
478
453
            self.assertEqual(expected, list(self.wt.unknowns()))
479
454
 
480
455
        check_unknowns([fname2])
481
456
 
482
 
        bzr('ignore', './' + fname2)
483
 
        # After 'ignore' you must re-open the working tree
484
 
        self.wt = self.wt.bzrdir.open_workingtree()
 
457
        self.run_bzr_decode(['ignore', './' + fname2])
485
458
        check_unknowns([])
486
459
 
487
460
        fname3 = self.info['filename'] + '3.txt'
488
 
        open(fname3, 'wb').write('unknown 3\n')
 
461
        self.build_tree_contents([(fname3, 'unknown 3\n')])
489
462
        check_unknowns([fname3])
490
463
 
491
464
        # Ignore should not care what the encoding is
492
465
        # (right now it doesn't print anything)
493
 
        bzr('ignore', fname3, encoding='ascii')
494
 
        self.wt = self.wt.bzrdir.open_workingtree()
 
466
        self.run_bzr_decode(['ignore', fname3], encoding='ascii')
495
467
        check_unknowns([])
496
468
 
497
469
        # Now try a wildcard match
498
470
        fname4 = self.info['filename'] + '4.txt'
499
 
        open(fname4, 'wb').write('unknown 4\n')
500
 
        bzr('ignore', '*.txt')
501
 
        self.wt = self.wt.bzrdir.open_workingtree()
 
471
        self.build_tree_contents([(fname4, 'unknown 4\n')])
 
472
        self.run_bzr_decode('ignore *.txt')
502
473
        check_unknowns([])
503
474
 
504
475
        # and a different wildcard that matches everything
505
476
        os.remove('.bzrignore')
506
 
        bzr('ignore', self.info['filename'] + '*')
507
 
        self.wt = self.wt.bzrdir.open_workingtree()
 
477
        self.run_bzr_decode(['ignore', self.info['filename'] + '*'])
508
478
        check_unknowns([])
509
479
 
510
480
    def test_missing(self):
511
 
        bzr = self.run_bzr_decode
512
 
 
513
481
        # create empty tree as reference for missing
514
 
        self.run_bzr('init', 'empty-tree')
 
482
        self.make_branch_and_tree('empty-tree')
515
483
 
516
484
        msg = self.info['message']
517
485
 
518
 
        txt = bzr('missing', 'empty-tree', retcode=1)
 
486
        txt = self.run_bzr_decode('missing empty-tree')
519
487
        self.assertNotEqual(-1, txt.find(self.info['committer']))
520
488
        self.assertNotEqual(-1, txt.find(msg))
521
489
 
522
490
        # Make sure missing doesn't fail even if we can't write out
523
 
        txt = bzr('missing', 'empty-tree', encoding='ascii', retcode=1)
 
491
        txt = self.run_bzr_decode('missing empty-tree', encoding='ascii')
524
492
        self.assertEqual(-1, txt.find(msg))
525
493
        self.assertNotEqual(-1, txt.find(msg.encode('ascii', 'replace')))
 
494
 
 
495
    def test_info(self):
 
496
        self.run_bzr_decode(['branch', u'.', self.info['directory']])
 
497
        self.run_bzr_decode(['info', self.info['directory']])
 
498
        self.run_bzr_decode(['info', self.info['directory']],
 
499
                            encoding='ascii')
 
500
 
 
501
    def test_ignored(self):
 
502
        fname = self.info['filename'] + '1.txt'
 
503
        self.build_tree_contents([(fname, 'ignored\n')])
 
504
        self.run_bzr(['ignore', fname])
 
505
        txt = self.run_bzr_decode(['ignored'])
 
506
        self.assertEqual(txt, '%-50s %s\n' % (fname, fname))
 
507
        txt = self.run_bzr_decode(['ignored'], encoding='ascii')
 
508
        fname = fname.encode('ascii', 'replace')
 
509
        self.assertEqual(txt, '%-50s %s\n' % (fname, fname))