/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/selftest/blackbox.py

remove more duplicate merged hunks. Bad MERGE3, BAD.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
it's normally invoked.
27
27
"""
28
28
 
29
 
from cStringIO import StringIO
30
29
import sys
31
30
import os
32
31
 
36
35
 
37
36
 
38
37
class ExternalBase(TestCaseInTempDir):
39
 
    def runbzr(self, args, retcode=0, backtick=False):
 
38
    def runbzr(self, args, retcode=0,backtick=False):
40
39
        if isinstance(args, basestring):
41
40
            args = args.split()
42
41
 
43
42
        if backtick:
44
 
            return self.run_bzr_captured(args, retcode=retcode)[0]
 
43
            return self.backtick(['python', self.BZRPATH,] + args,
 
44
                           retcode=retcode)
45
45
        else:
46
 
            return self.run_bzr_captured(args, retcode=retcode)
 
46
            return self.runcmd(['python', self.BZRPATH,] + args,
 
47
                           retcode=retcode)
47
48
 
48
49
 
49
50
class TestCommands(ExternalBase):
72
73
        f = file('.bzr/email', 'wt')
73
74
        f.write('Branch Identity <branch@identi.ty>')
74
75
        f.close()
75
 
        bzr_email = os.environ.get('BZREMAIL')
76
 
        if bzr_email is not None:
77
 
            del os.environ['BZREMAIL']
78
76
        whoami = self.runbzr("whoami",backtick=True)
79
77
        whoami_email = self.runbzr("whoami --email",backtick=True)
80
78
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
81
79
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
82
 
        # Verify that the environment variable overrides the value 
83
 
        # in the file
84
 
        os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
85
 
        whoami = self.runbzr("whoami",backtick=True)
86
 
        whoami_email = self.runbzr("whoami --email",backtick=True)
87
 
        self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
88
 
        self.assertTrue(whoami_email.startswith('other@environ.ment'))
89
 
        if bzr_email is not None:
90
 
            os.environ['BZREMAIL'] = bzr_email
91
80
 
92
81
    def test_invalid_commands(self):
93
82
        self.runbzr("pants", retcode=1)
104
93
    def test_ignore_patterns(self):
105
94
        from bzrlib.branch import Branch
106
95
        
107
 
        b = Branch.initialize('.')
 
96
        b = Branch('.', init=True)
108
97
        self.assertEquals(list(b.unknowns()), [])
109
98
 
110
99
        file('foo.tmp', 'wt').write('tmp files are ignored')
111
100
        self.assertEquals(list(b.unknowns()), [])
112
 
        assert self.capture('unknowns') == ''
 
101
        assert self.backtick('bzr unknowns') == ''
113
102
 
114
103
        file('foo.c', 'wt').write('int main() {}')
115
104
        self.assertEquals(list(b.unknowns()), ['foo.c'])
116
 
        assert self.capture('unknowns') == 'foo.c\n'
 
105
        assert self.backtick('bzr unknowns') == 'foo.c\n'
117
106
 
118
107
        self.runbzr(['add', 'foo.c'])
119
 
        assert self.capture('unknowns') == ''
 
108
        assert self.backtick('bzr unknowns') == ''
120
109
 
121
110
        # 'ignore' works when creating the .bzignore file
122
111
        file('foo.blah', 'wt').write('blah')
128
117
        # 'ignore' works when then .bzrignore file already exists
129
118
        file('garh', 'wt').write('garh')
130
119
        self.assertEquals(list(b.unknowns()), ['garh'])
131
 
        assert self.capture('unknowns') == 'garh\n'
 
120
        assert self.backtick('bzr unknowns') == 'garh\n'
132
121
        self.runbzr('ignore garh')
133
122
        self.assertEquals(list(b.unknowns()), [])
134
123
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
158
147
        os.rmdir('revertdir')
159
148
        self.runbzr('revert')
160
149
 
161
 
        file('hello', 'wt').write('xyz')
162
 
        self.runbzr('commit -m xyz hello')
163
 
        self.runbzr('revert -r 1 hello')
164
 
        self.check_file_contents('hello', 'foo')
165
 
        self.runbzr('revert hello')
166
 
        self.check_file_contents('hello', 'xyz')
167
 
 
168
150
    def test_mv_modes(self):
169
151
        """Test two modes of operation for mv"""
170
152
        from bzrlib.branch import Branch
171
 
        b = Branch.initialize('.')
 
153
        b = Branch('.', init=True)
172
154
        self.build_tree(['a', 'c', 'subdir/'])
173
155
        self.run_bzr('add', self.test_dir)
174
156
        self.run_bzr('mv', 'a', 'b')
202
184
        test.runbzr('add goodbye')
203
185
        test.runbzr('commit -m setup goodbye')
204
186
 
205
 
    def test_diff(self):
206
 
        self.example_branch()
207
 
        file('hello', 'wt').write('hello world!')
208
 
        self.runbzr('commit -m fixing hello')
209
 
        output = self.runbzr('diff -r 2..3', backtick=1)
210
 
        self.assert_('\n+hello world!' in output)
211
 
        output = self.runbzr('diff -r last:3..last:1', backtick=1)
212
 
        self.assert_('\n+baz' in output)
213
 
 
214
 
    def test_diff(self):
215
 
        self.example_branch()
216
 
        file('hello', 'wt').write('hello world!')
217
 
        self.runbzr('commit -m fixing hello')
218
 
        output = self.runbzr('diff -r 2..3', backtick=1)
219
 
        self.assert_('\n+hello world!' in output)
220
 
        output = self.runbzr('diff -r last:3..last:1', backtick=1)
221
 
        self.assert_('\n+baz' in output)
 
187
    def test_revert(self):
 
188
        self.example_branch()
 
189
        file('hello', 'wt').write('bar')
 
190
        file('goodbye', 'wt').write('qux')
 
191
        self.runbzr('revert hello')
 
192
        self.check_file_contents('hello', 'foo')
 
193
        self.check_file_contents('goodbye', 'qux')
 
194
        self.runbzr('revert')
 
195
        self.check_file_contents('goodbye', 'baz')
222
196
 
223
197
    def test_merge(self):
224
198
        from bzrlib.branch import Branch
240
214
        self.runbzr('merge ../b')
241
215
        self.check_file_contents('goodbye', 'quux')
242
216
        # Merging a branch pulls its revision into the tree
243
 
        a = Branch.open('.')
244
 
        b = Branch.open('../b')
 
217
        a = Branch('.')
 
218
        b = Branch('../b')
245
219
        a.get_revision_xml(b.last_patch())
246
220
        self.log('pending merges: %s', a.pending_merges())
247
221
        #        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
253
227
        os.chdir('a')
254
228
 
255
229
        self.example_branch()
256
 
        self.runbzr('pull', retcode=1)
257
 
        self.runbzr('missing', retcode=1)
258
 
        self.runbzr('missing .')
259
 
        self.runbzr('missing')
260
 
        self.runbzr('pull')
261
 
        self.runbzr('pull /', retcode=1)
262
 
        self.runbzr('pull')
263
 
 
264
230
        os.chdir('..')
265
231
        self.runbzr('branch a b')
266
232
        os.chdir('b')
267
 
        self.runbzr('pull')
268
233
        self.runbzr('commit -m blah --unchanged')
269
234
        os.chdir('../a')
270
 
        a = Branch.open('.')
271
 
        b = Branch.open('../b')
 
235
        a = Branch('.')
 
236
        b = Branch('../b')
272
237
        assert a.revision_history() == b.revision_history()[:-1]
273
238
        self.runbzr('pull ../b')
274
239
        assert a.revision_history() == b.revision_history()
283
248
        self.runbzr('pull ../a')
284
249
        assert a.revision_history()[-1] == b.revision_history()[-1]
285
250
        
 
251
 
286
252
    def test_add_reports(self):
287
253
        """add command prints the names of added files."""
288
 
        b = Branch.initialize('.')
 
254
        b = Branch('.', init=True)
289
255
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
 
256
 
 
257
        from cStringIO import StringIO
290
258
        out = StringIO()
 
259
 
291
260
        ret = self.apply_redirected(None, out, None,
292
261
                                    run_bzr,
293
262
                                    ['add'])
294
263
        self.assertEquals(ret, 0)
 
264
 
295
265
        # the ordering is not defined at the moment
296
266
        results = sorted(out.getvalue().rstrip('\n').split('\n'))
297
267
        self.assertEquals(['added dir',
299
269
                           'added top.txt',],
300
270
                          results)
301
271
 
302
 
    def test_unknown_command(self):
303
 
        """Handling of unknown command."""
304
 
        out, err = self.run_bzr_captured(['fluffy-badger'],
305
 
                                         retcode=1)
306
 
        self.assertEquals(out, '')
307
 
        err.index('unknown command')
308
 
        
309
 
 
310
272
 
311
273
class OldTests(ExternalBase):
312
274
    """old tests moved from ./testbzr."""
316
278
        from os.path import exists
317
279
 
318
280
        runbzr = self.runbzr
319
 
        capture = self.capture
 
281
        backtick = self.backtick
320
282
        progress = self.log
321
283
 
322
284
        progress("basic branch creation")
324
286
        chdir('branch1')
325
287
        runbzr('init')
326
288
 
327
 
        self.assertEquals(capture('root').rstrip(),
 
289
        self.assertEquals(backtick('bzr root').rstrip(),
328
290
                          os.path.join(self.test_dir, 'branch1'))
329
291
 
330
292
        progress("status of new file")
333
295
        f.write('hello world!\n')
334
296
        f.close()
335
297
 
336
 
        self.assertEquals(capture('unknowns'), 'test.txt\n')
 
298
        out = backtick("bzr unknowns")
 
299
        self.assertEquals(out, 'test.txt\n')
337
300
 
338
 
        out = capture("status")
 
301
        out = backtick("bzr status")
339
302
        assert out == 'unknown:\n  test.txt\n'
340
303
 
341
 
        out = capture("status --all")
 
304
        out = backtick("bzr status --all")
342
305
        assert out == "unknown:\n  test.txt\n"
343
306
 
344
 
        out = capture("status test.txt --all")
 
307
        out = backtick("bzr status test.txt --all")
345
308
        assert out == "unknown:\n  test.txt\n"
346
309
 
347
310
        f = file('test2.txt', 'wt')
348
311
        f.write('goodbye cruel world...\n')
349
312
        f.close()
350
313
 
351
 
        out = capture("status test.txt")
 
314
        out = backtick("bzr status test.txt")
352
315
        assert out == "unknown:\n  test.txt\n"
353
316
 
354
 
        out = capture("status")
 
317
        out = backtick("bzr status")
355
318
        assert out == ("unknown:\n"
356
319
                       "  test.txt\n"
357
320
                       "  test2.txt\n")
359
322
        os.unlink('test2.txt')
360
323
 
361
324
        progress("command aliases")
362
 
        out = capture("st --all")
 
325
        out = backtick("bzr st --all")
363
326
        assert out == ("unknown:\n"
364
327
                       "  test.txt\n")
365
328
 
366
 
        out = capture("stat")
 
329
        out = backtick("bzr stat")
367
330
        assert out == ("unknown:\n"
368
331
                       "  test.txt\n")
369
332
 
373
336
        runbzr("help commands")
374
337
        runbzr("help slartibartfast", 1)
375
338
 
376
 
        out = capture("help ci")
 
339
        out = backtick("bzr help ci")
377
340
        out.index('aliases: ')
378
341
 
379
342
        progress("can't rename unversioned file")
382
345
        progress("adding a file")
383
346
 
384
347
        runbzr("add test.txt")
385
 
        assert capture("unknowns") == ''
386
 
        assert capture("status --all") == ("added:\n"
 
348
        assert backtick("bzr unknowns") == ''
 
349
        assert backtick("bzr status --all") == ("added:\n"
387
350
                                                "  test.txt\n")
388
351
 
389
352
        progress("rename newly-added file")
391
354
        assert os.path.exists("hello.txt")
392
355
        assert not os.path.exists("test.txt")
393
356
 
394
 
        assert capture("revno") == '0\n'
 
357
        assert backtick("bzr revno") == '0\n'
395
358
 
396
359
        progress("add first revision")
397
360
        runbzr(['commit', '-m', 'add first revision'])
405
368
        runbzr("add sub1")
406
369
        runbzr("rename sub1 sub2")
407
370
        runbzr("move hello.txt sub2")
408
 
        assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
 
371
        assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
409
372
 
410
373
        assert exists("sub2")
411
374
        assert exists("sub2/hello.txt")
426
389
        runbzr(['commit', '-m', 'rename nested subdirectories'])
427
390
 
428
391
        chdir('sub1/sub2')
429
 
        self.assertEquals(capture('root')[:-1],
 
392
        self.assertEquals(backtick('bzr root')[:-1],
430
393
                          os.path.join(self.test_dir, 'branch1'))
431
394
        runbzr('move ../hello.txt .')
432
395
        assert exists('./hello.txt')
433
 
        self.assertEquals(capture('relpath hello.txt'),
434
 
                          os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
435
 
        assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
396
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
397
        assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
436
398
        runbzr(['commit', '-m', 'move to parent directory'])
437
399
        chdir('..')
438
 
        assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
400
        assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
439
401
 
440
402
        runbzr('move sub2/hello.txt .')
441
403
        assert exists('hello.txt')
450
412
 
451
413
        runbzr('commit -F msg.tmp')
452
414
 
453
 
        assert capture('revno') == '5\n'
 
415
        assert backtick('bzr revno') == '5\n'
454
416
        runbzr('export -r 5 export-5.tmp')
455
417
        runbzr('export export.tmp')
456
418
 
458
420
        runbzr('log -v')
459
421
        runbzr('log -v --forward')
460
422
        runbzr('log -m', retcode=1)
461
 
        log_out = capture('log -m commit')
 
423
        log_out = backtick('bzr log -m commit')
462
424
        assert "this is my new commit" in log_out
463
425
        assert "rename nested" not in log_out
464
426
        assert 'revision-id' not in log_out
465
 
        assert 'revision-id' in capture('log --show-ids -m commit')
 
427
        assert 'revision-id' in backtick('bzr log --show-ids -m commit')
466
428
 
467
429
 
468
430
        progress("file with spaces in name")